Reputation: 885
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.
Upvotes: 0
Views: 186
Reputation: 11574
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:
function login() {
// code
}
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:
views/elements/links.ctp
Then in the view, you can simply add:
<?php echo $this->element('links'); ?>
Now, on the same token, if you simply want to render another view, you can call it with the render function:
<?php echo $this->render('/controller_name/method'); ?>
So if you want to render the users login view from another view, just add:
<?php echo $this->render('/users/login'); ?>
This will call views/users/login.ctp
.
Happy Coding!
Upvotes: 1