【问题标题】:Zend - access layout property from controllerZend - 从控制器访问布局属性
【发布时间】:2009-11-24 06:37:27
【问题描述】:

啊,原谅我的 Zend 新手,我正在尝试访问此表单,存储在:

layouts/scripts/layout.phtml:

$this->layout()->userForm = $this->action('index', 'user');   

class IndexController extends Zend_Controller_Action
{
    public function init ()
    {    /* Initialize action controller here */
    }
    public function indexAction ()
    {
    // here
    }
}

indexAction,除了在布局中,我基本上还需要表单出现在首页。

我尝试使用 $this->_helper->layout()->userForm 访问它,但我怀疑控制器中的代码在布局之前运行,因为它没有给我想要的东西。

【问题讨论】:

    标签: php zend-framework


    【解决方案1】:

    我真的不明白你的问题。

    • 为什么您的表单总是存储在布局文件夹中?
    • “除了出现在布局中之外,还出现在主页上”是什么意思?似乎您对“布局”的定义与 Zend 的定义不同。据我了解,布局包含您的所有内容和句段,因此这句话没有意义。
    • 为什么不直接启动表单并将其传递给视图?

    像这样:

    $userForm = new UserForm();   
    $this->view->userForm = $userForm;
    

    【讨论】:

      【解决方案2】:

      我认为

      $this->_helper->layout->userForm
      

      应该这样做。

      我不知道你为什么不重复使用之后

       $this->action('index', 'user');
      

      在您看来,恕我直言,这似乎更简单。

      【讨论】:

      • 是的,我试过了,但它似乎没有吐出任何东西,这就是为什么我怀疑控制器代码在可能设置布局属性之前运行?
      • 是的布局可能会最后运行,无论如何你不应该把代码放在布局中只是我的感觉。
      猜你喜欢
      • 2011-04-14
      • 1970-01-01
      • 1970-01-01
      • 2020-01-27
      • 1970-01-01
      • 2011-07-11
      • 1970-01-01
      • 2012-02-17
      • 1970-01-01
      相关资源
      最近更新 更多