更改 Bootstrap 中的布局
我是 zend 新手,在更改引导程序中的布局时遇到问题。我想在用户登录时更改我的布局。
我在引导程序中更改布局的函数如下:
protected function _initAuthState()
{
$layout = new Zend_Layout;
$layout->setLayoutPath('/layouts/scripts');
if (Zend_Auth::getInstance()->hasIdentity()):
// Logged in.
$layout->setLayout(layout2);
else:
// Not Logged in.
$layout->setLayout(‘layout’);
endif;
}
此代码不起作用,布局始终相同......救命!
I am new with zend and I have a problem changing my layout in the bootstrap. I want to change my layout when the user is logged in.
My function to change the layout in the bootstrap is like this:
protected function _initAuthState()
{
$layout = new Zend_Layout;
$layout->setLayoutPath('/layouts/scripts');
if (Zend_Auth::getInstance()->hasIdentity()):
// Logged in.
$layout->setLayout(layout2);
else:
// Not Logged in.
$layout->setLayout(‘layout’);
endif;
}
This code doesn't work, the layout is always the same ... help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您正在修改新布局实例,而不是系统正在使用的实例。
我假设您在
application.ini
中指定布局参数。所以你需要:然后对此布局实例执行检查/修改。
顺便说一句,更改布局通常是使用前端控制器插件来完成的。仍然足够早地运行来完成这项工作,但通常更可配置和可重用。请参阅此处和这里举两个例子。
You are modifying a new layout instance, not the instance that is being used by the system.
I assume you are specifying your layout params in
application.ini
. So you need:Then perform your check/modification on this layout instance.
BTW, changing layout is often done using a front-controller plugin. Still runs early enough to do the job, but is often more configurable and re-usable. See here and here for two examples.
我找到了答案!!
这是我的最终结果,并且正在工作!
Bootstrap.php:
应用程序/插件/Layout.php:
I found the answer!!
this is my final result, and is working!!
Bootstrap.php:
application/plugins/Layout.php: