CakePHP Basics Tutorial – Part 3


In this tutorial I will show you how to create a login form which validates the user with the database and do some basic security to redirect people who try to access a protected page. I’ll go over Flash messages to show the user some information which will last for one request.

In this tutorial I’ll be covering

  1. Create a login form via FormHelper
  2. Retrieve data from the database via automagic functions (ooooooh magic!)
  3. Use sessions to check if a user is logged in
  4. Use Flash messages to inform the user
  5. Check out the AppController and callback functions

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

Let me know if you enjoyed it!
Happy coding!

Share this post

9 Responses

  1. It’s a good post and tutorial!

    I like to add that when you develop the login action on UsersController you should encrypt your password before compare to db field because if not, this comparsion will be always false (plain text vs encrypted text, remember that in add action we encrypt the pass before save on DB).



  2. Error: Call to a member function write() on a non-object
    File: C:xampphtdocscakephp1appControllerUsersController.php
    Line: 31

    could you pls help me solve this….

  3. sir i am getting the error while executing the code
    array(‘controller’=>’home’,action =>’hii’));

    the error is Call to a member function link() on a non-object

  4. In Tutorial 2 we have hashed the passwords before saving. How do we do the authentication with these hashed saved passwords? Do we do that using a beforeFind option in the model?

  5. Nice work man… keep going…

    I had a little trouble, I don’t know why…. maybe because I had installed the “DebutKit.Toolbar” or what…
    I did’t note the exactly error but it was related with the Session.

    So I made the bellow changes on AppController.php and now works fine. So if anyone has the some trouble with “Session”…. try this…..

    public $components = array(
    ‘DebugKit.Toolbar’ => array(
    ‘panels’ => array(‘history’, ‘session’)),
    ‘Session’ => array (‘Session’, ‘Cookie’));

    Apythanos from Hellas

Leave a Reply

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

Related Posts