cakephp accessing view attributes/variables from within a helper

后端 未结 3 1388
旧巷少年郎
旧巷少年郎 2021-01-01 22:54

is there a reasonable way to access the view attribute \"passedArgs\" (or any similar)

/* view */
$this->passedArgs

from within a Helper

3条回答
  •  甜味超标
    2021-01-01 23:19

    Cake 2.x and 3.x

    You can look up your variables in the _View object:

    $this->_View->viewVars['foo'];
    

    Cake 1.x

    If you grab the current view object from within the helper you should be able to get to its passedArgs.

    class SomeHelper extends AppHelper {
      function __construct($settings = array()){
        $this->passedArgs = ClassRegistry::getObject('view')->passedArgs;
      }
    }
    

    Cake 1.2.x

    If you grab the current view object from within the helper you should be able to get to its viewVars.

    class SomeHelper extends AppHelper {
      function __construct($settings = array()){
        $this->viewVars = ClassRegistry::getObject('view')->viewVars;
      }
    }
    

    Enjoy, Nick

提交回复
热议问题