Skip to content

Instantly share code, notes, and snippets.

@konnoyosuke
konnoyosuke / gist:bccc8e6f12826f8345572e96757e3e49
Last active June 22, 2017 04:28
AutoComponentとCustom Finder
<?php
// AppController function initialize()
$this->Auth->config('authenticate', [
'Form' => [
'userModel' => 'Employees',
'finder' => ['auth' => [$this->request->getData()]],
'fields' => [
'username' => 'code',
'password' => 'encrypted_password',
],
<?php
class AppModel extends Model {
public $actsAs = array(
'Search.Searchable',
);
}
<?php
class User extends AppModel {
public $filterArgs = array(
array('name' => 'name', 'type' => 'like', 'field' => 'User.name'),
array('name' => 'state', 'type' => 'value', 'field'=>'User.state'),
);
public $options = array(
'default' => array(
<div class="users index">
<h2><?php echo __('Users'); ?></h2>
<?php echo $this->Form->create(null, array('inputDefaults' => array('label' => false, 'div' => 'controls'))); ?>
<?php echo $this->Form->input('name', array('placeholder' => 'name')); ?>
<?php echo $this->Chosen->select('state', $states, array('data-placeholder' => 'Pick states...', 'multiple' => true)); ?>
<?php echo $this->Form->submit('Search'); ?>
<?php echo $this->Form->end(); ?>
<?php
App::uses('AppController', 'Controller');
class UsersController extends AppController {
public $components = array('Search.Prg');
public $presetVars = array(
array('model' => 'User', 'field' => 'name', 'type' => 'value'),
array('model' => 'User', 'field' => 'state', 'type' => 'value'),
<?php
class User extends AppModel {
public $filterArgs = array(
array('name' => 'name', 'type' => 'like', 'field' => 'User.name'),
array('name' => 'state', 'type' => 'value', 'field'=>'User.state'),
);
}
<?php
class AppModel extends Model {
public $actsAs = array(
'Search.Searchable',
'Collectionable.Options',
);
public $defaultOption = true;
}
<?php
class UsersController extends AppController {
public $components = array('Search.Prg');
public $presetVars = array(
array('model' => 'User', 'field' => 'name', 'type' => 'value'),
array('model' => 'User', 'field' => 'state', 'type' => 'value'),
array('model' => 'User', 'field' => 'tel', 'type' => 'value'),
);
function beforeFilter() {
       if(isset($this->Ktai) && $this->Ktai->is_ktai()){
$this->layout = 'ktai_default';
$this->viewPath = 'ktai' . DS . $this->viewPath;
$this->Ktai->_options = array_merge($this->Ktai->_options, array(
'input_encoding' => 'UTF-8',
<?php
// in app/Lib/Error/AppExceptionRenderer.php
App::uses('ExceptionRenderer', 'Error');
class AppExceptionRenderer extends ExceptionRenderer {
protected function _getController($exception) {
$controller = parent::_getController($exception);
$controller->layout = 'error';
return $controller;
}