Note that there are some explanatory texts on larger screens.

plurals
  1. POIs there an easy way to get AuthComponent user data from a view in CakePHP?
    primarykey
    data
    text
    <p>According to the cakebook <a href="http://book.cakephp.org/view/172/Authentication" rel="nofollow noreferrer">section on the Auth component</a>, I can implement simple authentication by using the following Users controller:</p> <pre><code>class UsersController extends AppController { var $name = 'Users'; var $components = array('Auth'); // Not necessary if declared in your app controller /** * The AuthComponent provides the needed functionality * for login, so you can leave this function blank. */ function login() { } function logout() { $this-&gt;redirect($this-&gt;Auth-&gt;logout()); } } </code></pre> <p>I would like to be able to something like the following into my view:</p> <pre><code>&lt;?php $username = $auth-&gt;user('username'); echo "Welcome " . $username; ?&gt; </code></pre> <p>Is there a simple way to do this, or do I need to overwrite the login function and store the username to the session?</p> <p><strong>Update</strong></p> <p><a href="https://stackoverflow.com/questions/929186/is-there-an-easy-way-to-get-authcomponent-user-data-from-a-view-in-cakephp/930226#930226">Alexander's answer</a> is exactly what I wanted. However, I will add the following in case someone else gets confused like I did.</p> <p>It took me a while to understand that if you change the model that Auth uses (for example, you might have a 'persons' table instead of 'users'), then you need to use something like:</p> <pre><code>$persondata = $session-&gt;read('Auth.Person'); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload