Skip to content

Instantly share code, notes, and snippets.

Avatar
🕶️
Building cool web stuff

Mark Scherer dereuromark

🕶️
Building cool web stuff
View GitHub Profile
@dereuromark
dereuromark / PaginatorComponent.php
Created Aug 17, 2017
App Paginator extension for out of bounds redirect instead of 404 exception
View PaginatorComponent.php
<?php
namespace App\Controller\Component;
use Cake\Controller\Component\PaginatorComponent as CorePaginatorComponent;
use Cake\Datasource\QueryInterface;
use Cake\Network\Exception\NotFoundException;
class PaginatorComponent extends CorePaginatorComponent
{
View gist:5bfc5c33dfd9b59b8388
/**
* @param Event $event
* @param Query $query
* @return void
*/
public function beforeFind(Event $event, Query $query) {
$this->encodeBitmaskConditions($query);
$field = $this->_config['field'];
if (!($mappedField = $this->_config['mappedField'])) {
View gist:5dc3b85a43a969ccde01
array(
(int) 0 => array(
'ParentCategory' => array(
'id' => '1',
'name' => 'Lorem ipsum dolor sit amet',
'parent_id' => '1'
)
)
)
View gist:2541d9139ca4598cf000
Overwrite completly:
public function setup(Model $Model, $config = array()) {
$this->settings[$Model->alias] = $config + $this->_defaultConfig;
}
Merge:
public function setup(Model $Model, $config = array()) {
@dereuromark
dereuromark / gist:6080212
Created Jul 25, 2013
Try to get associated callbacks working for certain behaviors via AppModel hack
View gist:6080212
public function afterFind($results, $primary = false) {
if (!$primary && $this->attached('Translate')) {
$results = $Model->Behaviors->Translate->afterFind($this, $results, $primary);
}
...
}