错误:无法直接访问CakePHP
我正在调用的元素文件:错误:无法直接访问CakePHP,cakephp,Cakephp,我正在调用的元素文件: $brand = $this->requestAction('brands/buyer_getnames/'); public function buyer_getnames(){ $newid=$this->Auth->User('brand_id'); $name=$this->Brand->find('first',array('condition
$brand = $this->requestAction('brands/buyer_getnames/');
public function buyer_getnames(){
$newid=$this->Auth->User('brand_id');
$name=$this->Brand->find('first',array('conditions'=>array('Brand.id'=>$newid),'recursive'=>-1));
return $name['Brand']['name'];
}
我正在调用的操作文件:
$brand = $this->requestAction('brands/buyer_getnames/');
public function buyer_getnames(){
$newid=$this->Auth->User('brand_id');
$name=$this->Brand->find('first',array('conditions'=>array('Brand.id'=>$newid),'recursive'=>-1));
return $name['Brand']['name'];
}
获取下面的错误
Private Method in BrandsController
Error: BrandsController::buyer_getnames() cannot be accessed directly.
请提供帮助如果使用requestAction方法请求您的操作,则您可以允许未经授权的访问操作 例如:
public function beforeFilter() {
parent::beforeFilter();
if ($this->request->is('requested') && $this->request->params['action'] == 'index') {
$this->Auth->allow(array('index'));
}
}
这也可能有效(尚未测试):
如果我能为您提供更多帮助,请告诉我。请求操作尊重正常的url路由规则
如果正在使用,则无法通过/controller/prefix\u foo
格式的url访问函数prefix\u foo()
——它需要是相应的前缀url:/prefix/controller/foo
因此,您的请求操作调用应为:
$brand = $this->requestAction('/prefix/brands/getnames/');
请注意,如果该方法所做的唯一一件事是调用模型方法,则最好只执行以下操作:
$model = ClassRegistry::init('Brand');
$brand = $model->someMethod();
我不认为后者会起作用——因为在实际运行索引操作代码之前,必须回答身份验证问题!有时我会遇到这种问题,这就是为什么思考对我有效。请提供更多的背景。你叫$this->requestAction?买家是路由前缀吗?@AD7six是前缀