「Cauth」という名前のプラグインに Cakephp ACL ユーザー認証を実装しようとしています。以前に実装したものと同じものがうまく機能していました。今回の違いは、プラグインの下にあります。ここで、コントローラーでは、 $this->User->Group->find('list'); 動かない。次の致命的なエラーが発生しました。
Fatal Error
Error: Call to a member function find() on a non-object
File: my_dir_path\app\Plugin\Cauth\Controller\UsersController.php
Line: 60
Notice: If you want to customize this error message, create app\View\Errors\fatal_error.ctp
私のコードは次のとおりです。
グループ モデル:
var $useTable = 'groups';
public $hasMany = array (
'User' => array (
'className' => 'Cauth.User',
'foreignKey' => 'group_id',
'dependent' => false,
'conditions' => '',
'fields' => '',
'order' => '',
'limit' => '',
'offset' => '',
'exclusive' => '',
'finderQuery' => '',
'counterQuery' => ''
)
);
ユーザーモデル:
var $useTable = 'users';
public $belongsTo = array (
'Group' => array (
'className' => 'Cauth.Group',
'foreignKey' => 'group_id',
'conditions' => '',
'fields' => '',
'order' => ''
)
);
ユーザー コントローラーのアクションを追加すると、グループ選択ボックスが機能しません。
ユーザーコントローラー追加アクション:
App::uses('CauthAppController', 'Cauth.Controller');
class UsersController extends CauthAppController {
public function add() {
if ($this->request->is('post')) {
$this->User->create();
if ($this->User->save($this->request->data)) {
$this->Session->setFlash(__('The user has been saved'));
$this->redirect(array ('action' => 'index'));
} else {
$this->Session->setFlash(__('The user could not be saved. Please, try again.'));
}
}
$groups = $this->User->Group->find('list');
$this->set(compact('groups'));
}
誰でもこの問題を解決するのを手伝ってくれますか?
特記事項:以下のケースに取り組んでいます。
ケース 1:
コントローラーからモデルをバインドすると、正常に動作します。
$this->User->bindModel(
array ('belongsTo' => array ('Group'))
);
すなわち
public function add() {
$this->User->bindModel(
array ('belongsTo' => array ('Group'))
);
if ($this->request->is('post')) {
$this->User->create();
if ($this->User->save($this->request->data)) {
$this->Session->setFlash(__('The user has been saved'));
$this->redirect(array ('action' => 'index'));
} else {
$this->Session->setFlash(__('The user could not be saved. Please, try again.'));
}
}
$groups = $this->User->Group->find('list');
$this->set(compact('groups'));
}
ケース 2:
すべてのアクション名を許可する場合。管理者にはすべての権限がありますが、管理者用の beforeFilter も記述する必要があります。
public function beforeFilter() {
parent::beforeFilter();
$this->Auth->allow('index', 'add');
}
それを実行可能にするもう1つのケースを見つけました。
ケース 3:
私のAppControllerのコードは -
class AppController extends Controller {
public $helpers = array ('Form', 'Time', 'Html', 'Session', 'Js', 'DebugKit.Toolbar');
public $counter = 0;
public $components = array (
'DebugKit.Toolbar',
'RequestHandler',
'Acl',
'Auth' => array (
'authorize' => array (
'Actions' => array ('actionPath' => 'controllers')
)
),
'Session'
);
public function beforeFilter() {
//Configure AuthComponent
$this->Auth->loginAction = array ('plugin' => 'cauth', 'controller' => 'users', 'action' => 'login');
$this->Auth->logoutRedirect = array ('plugin' => 'cauth', 'controller' => 'users', 'action' => 'login');
$this->Auth->loginRedirect = array ('plugin' => '', 'controller' => 'pages', 'action' => 'display');
}
}
この場合、機能していませんでした。しかし、私がそれを作ったとき -
class AppController extends Controller {
public $helpers = array ('Form', 'Time', 'Html', 'Session', 'Js', 'DebugKit.Toolbar');
public $counter = 0;
public $components = array (
'DebugKit.Toolbar',
'RequestHandler',
'Acl',
'Auth' => array (
'authenticate' => array('Form')
),
'Session'
);
public function beforeFilter() {
//Configure AuthComponent
$this->Auth->loginAction = array ('plugin' => 'cauth', 'controller' => 'users', 'action' => 'login');
$this->Auth->logoutRedirect = array ('plugin' => 'cauth', 'controller' => 'users', 'action' => 'login');
$this->Auth->loginRedirect = array ('plugin' => '', 'controller' => 'pages', 'action' => 'display');
}
}
その後、協会は再び活動を開始します。このコンポーネント宣言の何が問題なのか、まだ理解できません。
public $components = array (
'DebugKit.Toolbar',
'RequestHandler',
'Acl',
'Auth' => array (
'authorize' => array (
'Actions' => array ('actionPath' => 'controllers')
)
),
'Session'
);
このように宣言しないと、ACL が機能しません。つまり、すべてのグループが同じ権限を取得します。
私を助けてください。私はこれに非常に長い間取り組んでいます。