CakePHP Basics Tutorial – Part 5

Overview

Today I’ll show you how you can use cakePHP layout files and elements.  This way you can easily create different layouts for your pages and with elements you can write efficient code instead of copy/pasting the same code over and over again.

In this tutorial I’ll be covering

  1. Explain layouts
  2. Create 2 different layouts, one for regular users and one for the admin
  3. Explain elements
  4. Create an element and pass data to it

This part is the follow-up on what we have seen in CakePHP Basics Tutorial – Part 4.

This part is the follow-up on what we have seen in part 4 of my CakePHP basics serie!

Let me know if you enjoyed it!
Happy coding!

Share this post

27 Responses

  1. Hi!

    I followed all your tuts and I’m now doing a tut from the CakePHP Cookbook.
    But in the cookbook they always include components and helpers at top of the controller which you haven’t done once in your tuts.
    But it still works. Why is that? Is it optional to include them?

    Eg: http://book.cakephp.org/2.0/en/tutorials-and-examples/blog/part-two.html#adding-posts
    public $helpers = array(‘Html’, ‘Form’, ‘Session’);
    public $components = array(‘Session’);

    Kind regards,
    WouterDS

  2. Oh and for the next video could you show you would retrieve data from multiple tables on a specific page? Eg: On the homepage I want to show the total products, total users and the last 3 added users and last 3 added products.

    1. By using the $uses array you can add multiple models to one controller. So if you add $uses = array(‘Products’, ‘Users’);, cakePHP will make these models available in your controller!

  3. I think you are doing a great job with your tutorials and I am finding them helpful and interesting. I was hoping you could do a tutorial on building a complete application such a shopping cart. I am having problems trying to understand passedArgs function and named parameters and was hoping you could help me out by explaining how it works, that is how to reference them within controllers and models

  4. Great work..
    We are waiting for your next tutorial.
    I am still little bit confusing in naming conventions.

  5. Hi!,
    l have followed you tutorials and it was great. l want to ask, can we always put one content per page i.e fetch(‘content’);?>

  6. Frederik,
    Thanks for creating the tutorials – very helpful and the best I have found! I have a question about your phpstorm setup. Have you done anything to phpstorm for enabling autocomplete? I am not getting some of the same autocomplete options and was wondering if you would mind giving a hint for setting phpstorm up for cakephp development….thanks in advance!

  7. Hi ! I have been following all your tutorials. Its really good. Can you tell me how to use single core for multiple apps ?

  8. Hi. I really have to thank you. You made things clearer to me. Keep making tutorials, they’ve got a talent for that.

  9. Hi Frederik,
    Thanks a lot for your tuts, you re really helping me out to get some good fundaments on cakephp.
    Just wondrering though, is there any way to implement a templating language eg. Liquid in cakephp ???
    Thanks again,
    keep on.

  10. Hey,
    Great series and i have just cleared my basics in CakePHP.So now will implement it in a small application and in case of any problem i will post it here.
    Moreover,awesome work really.
    Looking forward for new topics.
    I have a ques:
    After login when i click back button it again opens login form ,how can i get it fixed ??

  11. fantastic tutorial – the best I’ve seen so far. Would I be asking too much if I wanted to download this video? Would truly appreciate the favour…

  12. Wow i hate CakePHP so much. all these magic function are so annoying and to code in CakePHP is simply confusing and too much of OOP.

Leave a Reply

Your email address will not be published. Required fields are marked *

Related Posts