Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error: Cannot be accessed directly CakePHP

Tags:

cakephp

Element file I am calling:

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

Action file I am calling:

    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'];
}

Getting error below..!!

Private Method in BrandsController

Error: BrandsController::buyer_getnames() cannot be accessed directly.

Please help

like image 494
jsduniya Avatar asked Mar 23 '23 09:03

jsduniya


1 Answers

Request action respects normal url routing rules

If you're using prefix routing then you can't access function prefix_foo() via a url of the form /controller/prefix_foo - it needs to be the corresponding prefix url: /prefix/controller/foo.

As such your request action call should be:

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

Note that if the only thing that method does is call a model method, you're better off simply doing:

$model = ClassRegistry::init('Brand');
$brand = $model->someMethod();
like image 173
AD7six Avatar answered Apr 27 '23 12:04

AD7six