Saturday, December 21, 2013

Re: CakePHP Newbie Questions

No doubt you've seen http://book.cakephp.org/2.0/en/core-libraries/components/authentication.html

With this, you set up the Auth component to tell it how you're doing your Auth, and what the loginAction should be.  Once a user request comes in for a page that requires authentication, and if they're not Authentication, the component will redirect the user to the login action, get them logged in, and then redirect them to the original page they were trying to get to.  Of course, you're free to directly display your login action as well.

As mentioned before, Controllers don't need a Model, but will use convention to determine a model to use, if one is not supplied.  If you want a controller with no Models, use public $uses = false or public $uses = array(), as described here : http://book.cakephp.org/2.0/en/controllers.html#Controller::$uses

When you set up the Auth component, you'll also set up a model that is used for that authentication.  Usually it's a User model, with a username and password.  To access any fields in the auth model for the current authentication session, from the controller, use $this->Auth->user();  i.e. $this->Auth->user('username') will give you the user name of the currently logged in user. As seen here: http://book.cakephp.org/2.0/en/core-libraries/components/authentication.html#accessing-the-logged-in-user

I hope that answers your questions.

Regards
Reuben Helms

On Wednesday, 18 December 2013 03:21:50 UTC+10, Nick Harper wrote:
Hi,

I have recently started to learn CakePHP after just being used to coding from scratch.

I have installed a couple of plugins but the issue I have is linking them together, for example if I have a login script then how on earth do I just show the login page for example?

Does every Controller need to have a mysql assigned to it?

I have been through the blog tutorial but so far it just feels really restrictive compared to just coding from scratch but what really appeals is the plugins / helpers but I am just struggling with basic things like echoing the username they are logged in with when logged in etc.


--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP
 
---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscribe@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/groups/opt_out.

No comments: