php - cakephp 从助手中访问 View 属性/变量

标签 php cakephp view helper

是否有合理的方法来访问 View 属性“passedArgs”(或任何类似的属性)

/* view */
$this->passedArgs

从助手内部?

我很乐意自定义帮助程序的 _construct() 或自定义 app_helper...但我不想将 $this->passedArgs 传递到帮助程序中每次查看或使用。

最佳答案

蛋糕 2.x 和 3.x

您可以在_View对象中查找变量:

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

蛋糕 1.x

如果您从助手中获取当前 View 对象,您应该能够获取其 passArgs。

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

蛋糕1.2.x

如果您从助手中获取当前 View 对象,您应该能够获取其 viewVars。

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

享受, 尼克

关于php - cakephp 从助手中访问 View 属性/变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3525541/

相关文章:

php - CakePHP - TinyMceHelper 帮助器错误:方法 TinyMceHelper::__name 不存在

php - 如何使用 CakePHP 的新 Blowfish/Bcrypt 获取密码

flash - 执行时grails在 View 中显示Flash消息

php - 尝试在特定日期之后从多个 mysql 表中进行选择

php - 如何构建此 SQL 查询。合并多个表?

php - 如何让 PHPMyAdmin 显示 MySQL 警告?

php - MySQL 在选择查询中使用生成的列

php - CakePHP 管理索引

ios - 在 swift iOS 中管理用户登录 segues

java - 向 Roo 生成的项目添加新 View 很困难