cakePHP 中的 Kohana 风格模板
过去几个月我一直在使用这两个框架。他们都有自己的高潮和低谷。不想发起一个话题来争论哪个更好。
有没有办法实现 Kohana 样式模板,您可以在 cakePHP 中的另一个视图中显示一个视图。
I have been using both frameworks for last few months. They both have their highs and lows. Do not wish to start a thread to argue which is better.
Is there any way to implement Kohana style template where you can display one view in other in cakePHP.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
它们被称为元素。请记住,视图特定于控制器内的功能。例如,假设您有一个用户登录名。在用户控制器中,您将看到:
然后在视图目录中,您将有views/users/login.ctp。
但假设您希望在所有视图中包含一系列链接。手动将它们全部剪切并粘贴到每个视图中是不明智的。这是因为当链接发生变化时,您必须更新每个视图。因此,最好的方法是使用一个元素:
然后在视图中,您可以简单地添加:
现在,同样的道理,如果您只是想渲染另一个视图,您可以使用 render 函数调用它:
所以如果您想要从另一个视图渲染用户登录视图,只需添加:
这将调用
views/users/login.ctp
。快乐编码!
They are referred to as elements. Keep in mind a view is specific to a function within a controller. For example, let's say you have a User login. In the Users controller you will see:
Then in the views directory you will have views/users/login.ctp.
But let's say there is a series of links you want to include in all views. It's not wise to manually cut and paste all of them into each view. This is because when there is a change in the links, you have to update every view. So the best way to do it is with an element:
Then in the view, you can simply add:
Now, on the same token, if you simply want to render another view, you can call it with the render function:
So if you want to render the users login view from another view, just add:
This will call
views/users/login.ctp
.Happy Coding!