Skip to content

Instantly share code, notes, and snippets.

View angelxmoreno's full-sized avatar

Angel S. Moreno angelxmoreno

View GitHub Profile
@angelxmoreno
angelxmoreno / ExceptionRendererFixed.php
Created November 23, 2012 20:07
Workaround for CakePHP bug #3389 ExceptionRenderer uses the wrong viewClass
<?php
/**
* Exception Renderer Fixed
* Angel S. Moreno (angelxmoreno@gmail.com)
*
* As per ticket #3389 (http://cakephp.lighthouseapp.com/projects/42648/tickets/3389-exceptionrenderer-uses-the-wrong-viewclass)
* the ExceptionRenderer fails to use the proper view class when an exception is thrown in the AppController's beforeFilter.
* This new ExceptionRenderer extends the original and updates the view class based on RequestHandlerComponent::params['ext'] and
* Router::extensions(). It assumes that when RequestHandlerComponent::params['ext'] is set and the extention is in the array of
* Router::extensions(), that the viewClass to use is prefixed by the extension being used. That being said, when the extenion is
@angelxmoreno
angelxmoreno / EnvSwitcher.php
Last active December 17, 2015 12:29
Environment Switching class for CakePHP
<?php
/**
* For the latest version please visit https://github.com/angelxmoreno/CakePHP-Environment-Switcher
*
* Environment Switching class for CakePHP
*
* The class should be included in your webroot/index file right after the APP_DIR
* is defined, since this class uses the ROOT and APP_DIR constants.
*
* PHP 5
@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(