I'm using cakephp and I want the login view for the controller 'users' to be displayed on the default.ctp for the layout controller. I can I do this?
我正在使用cakephp,我希望控制器'用户'的登录视图显示在布局控制器的default.ctp上。我可以这样做吗?
For example:
<div id="leftNav">
<div id="login-block" class="block">
<?php
//render users/login here
?>
<ul>
<li><a href="/users/login">Login</a></li>
<li><a href="/users/register">Register</a></li>
<li><a href="/users/logout">Logout</a></li>
</ul>
</div>
</div>
2 个解决方案
#1
2
I would make it an element - they are designed for re-usable code chunks that can be used anywhere.
我会把它作为一个元素 - 它们被设计用于可以在任何地方使用的可重用代码块。
To summarize the functionality, in your view you'd use:
要总结功能,请在视图中使用:
<?php echo $this->element('login'); ?>
and put your "login-block" div login stuff in
并把你的“登录块”div登录的东西放进去
/app/views/elements/login.ctp
#2
1
If you don't use elements for that and you already have the login view you can use it like this
如果您没有使用元素并且您已经拥有登录视图,则可以像这样使用它
<?php echo $this->requestAction('/users/login'); ?>
#1
2
I would make it an element - they are designed for re-usable code chunks that can be used anywhere.
我会把它作为一个元素 - 它们被设计用于可以在任何地方使用的可重用代码块。
To summarize the functionality, in your view you'd use:
要总结功能,请在视图中使用:
<?php echo $this->element('login'); ?>
and put your "login-block" div login stuff in
并把你的“登录块”div登录的东西放进去
/app/views/elements/login.ctp
#2
1
If you don't use elements for that and you already have the login view you can use it like this
如果您没有使用元素并且您已经拥有登录视图,则可以像这样使用它
<?php echo $this->requestAction('/users/login'); ?>