我正在调用的元素文件:
$brand = $this->requestAction('brands/buyer_getnames/');
Run Code Online (Sandbox Code Playgroud)
我正在调用的动作文件:
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'];
}
Run Code Online (Sandbox Code Playgroud)
得到以下错误.. !!
Private Method in BrandsController
Error: BrandsController::buyer_getnames() cannot be accessed directly.
Run Code Online (Sandbox Code Playgroud)
请帮忙
如果您正在使用前缀路由,则无法function prefix_foo()通过表单的URL 访问/controller/prefix_foo- 它需要是相应的前缀url : /prefix/controller/foo.
因此,您的请求操作调用应该是:
$brand = $this->requestAction('/prefix/brands/getnames/');
Run Code Online (Sandbox Code Playgroud)
请注意,如果该方法所做的唯一事情是调用模型方法,那么最好只做:
$model = ClassRegistry::init('Brand');
$brand = $model->someMethod();
Run Code Online (Sandbox Code Playgroud)