cakephp - Undefined variable in view -


i having issue setting variables in controller , showing @ view.

my codes follow: in view (pages/anything.ctp):

<?php echo $anything; ?> 

in controller (pagescontroller.php):

public function anything() {         $a = "asdasdas";         $this->set('anything', $a); } 

i new cake, , i've done quite number of search in google , stack. still no luck.

i'd grateful if help, or if asked question before please provide link best.

first read following article controller actions in cakephp cookbook

when use controller methods requestaction(), want return data isn’t string. if have controller methods used normal web requests + requestaction, should check request type before returning:

class recipescontroller extends appcontroller {     public function popular() {         $popular = $this->recipe->popular();         if (!empty($this->request->params['requested'])) {             return $popular;         }         $this->set('popular', $popular);     } } 

the above controller action example of how method can used requestaction() , normal requests. returning array data non-requestaction request cause errors , should avoided. see section on requestaction() more tips on using requestaction()


Comments

Popular posts from this blog

apache - PHP Soap issue while content length is larger -

asynchronous - Python asyncio task got bad yield -

javascript - Complete OpenIDConnect auth when requesting via Ajax -