Skip to content

Instantly share code, notes, and snippets.

View angelxmoreno's full-sized avatar

Angel S. Moreno angelxmoreno

View GitHub Profile
@angelxmoreno
angelxmoreno / CakeModelConstruct
Created April 29, 2014 22:39
Advance use of CakePHP Virtual Fields
/**
* Constructor. Binds the model's database table to the object.
*
* @param integer|string|array $id Set this ID for this model on startup, can also be an array of options, see above.
* @param string $table Name of database table to use.
* @param string $ds DataSource connection name.
*/
public function __construct($id = false, $table = null, $ds = null) {
parent::__construct($id, $table, $ds);
//verify that all children have a $role
@angelxmoreno
angelxmoreno / ArticlesController.php
Created May 13, 2014 21:43
Testing if Controller::set($data) works in 3.0
<?php
//Controller
namespace App\Controller;
use App\Controller\AppController;
class ArticlesController extends AppController {
public function beforeRender(\Cake\Event\Event $event) {
parent::beforeRender($event);
was the ability to edit the wrapping div in the FormHelper::input() dropped in favor of the groupContainer template or has it not been implemented
was the ability to edit the wrapping div in the FormHelper::input() dropped in favor of the groupContainer template or has it not been implemented
<?php
//if i dont have the id but i have the email
$email = 'johndoe@example.com';
$new_pass = 'cakephp2014'
$user_id = $this->field('id', array('email' => $email));
$this->User->save(array('id' => $user_id, 'password' => Security::hash($new_pass);
<?php
App::uses('ConnectionManager', 'Model');
$db = ConnectionManager::getDataSource('amazon');
$books = $db->find('Books', array(
'title' => 'Harry Potter'
));
debug($books);
debug($genres_movies);
########## DEBUG ##########
array(
'Movie' => array(
'id' => '1726'
),
'Genre' => array(
'Genre' => array(
(int) 0 => (int) 28,
(int) 1 => (int) 12,
<?php
// in the User Model
App::uses('AppModel', 'Model');
App::uses('SimplePasswordHasher', 'Controller/Component/Auth');
class User extends AppModel {
public function beforeSave($options = array()) {
if (isset($this->data[$this->alias]['password'])) {
$passwordHasher = new SimplePasswordHasher();
$this->data[$this->alias]['password'] = $passwordHasher->hash(
<?php
class Keyword extends MoviesAppModel {
public function __construct($id = false, $table = null, $ds = null) {
parent::__construct($id, $table, $ds);
$this->virtualFields['movies_count'] = sprintf(
'select count(*) from `keywords_movies` where `keywords_movies`.`keyword_id` = `%s`.`id', $this->alias
);
}
?>
// routes.php
<?php
Router::parseExtensions('json', 'xml');
Router::connect('/', array('controller' => 'pages', 'action' => 'display', 'home'));
Router::connect('/pages/*', array('controller' => 'pages', 'action' => 'display'));
CakePlugin::routes();
require CAKE . 'Config' . DS . 'routes.php';
?>
// AppController