【问题标题】:Another way to get the instance of the View object in a controller在控制器中获取 View 对象实例的另一种方法
【发布时间】:2011-11-16 20:34:41
【问题描述】:

我最近从 CakePHP 的 1.3 转到 2.0。迁移进行得很顺利,除了之前我使用 ClassRegistry::getObject() 方法检索正在使用的 View 对象的当前实例的地方。然后我打电话给$view->renderLayout($content, $layout);。此代码用于执行 ajax 重定向,几乎是来自 here 的代码。

但是现在,随着 CakePHP 2.0 能够从 ClassRegistry has been disabled 获取 View 对象的实例,这段代码不再有效。

所以我想知道是否有另一种方法可以通过不同的方式获得相同的效果。我真的不想用javascript方式(手动设置location.hash)。

谢谢,

【问题讨论】:

    标签: cakephp cakephp-2.0


    【解决方案1】:

    只需阅读源代码。

    /**
     * Instance of the View created during rendering. Won't be set until after Controller::render() is called.
     *
     * @var View
     */
        public $View;
    

    ClassRegistry 从未真正被认为可用于模型以外的其他事物。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-06-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多