加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

错误:无法直接访问CakePHP

发布时间:2020-12-13 17:45:15 所属栏目:PHP教程 来源:网络整理
导读:我正在调用的元素文件: $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'=
我正在调用的元素文件:

$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.

请帮忙

解决方法

请求操作遵循正常的URL路由规则

如果您使用的是prefix routing,则无法通过/ controller / prefix_foo格式的url访问函数prefix_foo() – 它必须是相应的前缀url:/ prefix / controller / foo.

因此,您的请求操作调用应该是:

$brand = $this->requestAction('/prefix/brands/getnames/');

请注意,如果该方法所做的唯一事情是调用模型方法,那么最好只做:

$model = ClassRegistry::init('Brand');
$brand = $model->someMethod();

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读