我们如何在cakephp中扩展一个模型数据以检查条件到另一个控制器?
例如:
class UsersController extends AppController
{
public function beforeFilter()
{
$this->loadModel('Apages');
$usr=$this->Apages->find('all');
$this->loadModel('Pagepermissions');
$pre=$this->Pagepermissions->find('all',array('conditions'=>array('user_id'=>'1')));
if($pre->request->data['Pagepermissions']['_add']==1)
{
$this->redirect(array('controller'=>'users','action'=>'add'));
}
else
{
throw new NotFoundException(__("Don't have access this Page"));
}
}
}
在此代码中
$pre->request->data['Pagepermissions']['_add']
显示错误。
请建议我怎么做
先谢谢
答案 0 :(得分:0)
$ pre是数组,执行类似
的操作$pre=$this->Pagepermissions->find('all',array('conditions'=>array('user_id'=>'1')));
if(!empty($pre)){
foreach($pre as $v){
if($v['Pagepermissions']['_add']==1){
$this->redirect(array('controller'=>'users','action'=>'add'));
return;
}else{
throw new NotFoundException(__("Don't have access this Page"));
}
}
}else{
throw new NotFoundException(__("user not find"));
}