Re: Auth Component and user information.
On Jun 7, 2:33 pm, saidbakr wrote: > I also noticed another thing: > > The output of $this->Auth->user() ,without key parameter, is an array > which is listing User model only without regarding the associated > model. Look at the API: http://api.cakephp.org/class/auth-component#method-AuthComponentuser Parameters: $keystring field to retrive. Leave null to get entire User record optionalNULL if ($key == null) { $model =& $this->getModel(); return array($model->alias => $this->Session->read($this- >sessionKey)); } else { And, of course, $this->sessionKey cannot be some arbitrary string that the component doesn't know about. It can't read your mind so it defaults to what it knows. Namely, 'Auth.User'. Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
Re: Auth Component and user information.
On Jun 7, 2:19 pm, saidbakr wrote: > Well, but what about the data in the associated Model Rules? How could > I get it? The AuthComponent does not require anything in the User::login() method. However, if you wish to run some code upon login, you implement it there. public function login() { if ($user = $this->Auth->user()) { /* fetch and store your associated data */ $this->Session->write( 'Auth.User.whatever', $this->User->find(...) ); $this->redirect($this->Auth->loginRedirect); } } Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
Re: Auth Component and user information.
I think the point is that as part of your log in process you scrape information from your associated model and add it to the User array. You could also do an update if the associated model data was changed, I guess. Jeremy Burns jeremybu...@me.com On 7 Jun 2010, at 19:33, saidbakr wrote: > I also noticed another thing: > > The output of $this->Auth->user() ,without key parameter, is an array > which is listing User model only without regarding the associated > model. > > > Array ( [User] => Array ( [id] => 1 [username] => admin [name] => Said > Bakr [join_date] => 2010-06-14 19:35:00 [email] => said@gmail.com > [rule_id] => 1 ) ) > > On Jun 7, 8:27 pm, cricket wrote: >> On Jun 7, 11:39 am, saidbakr wrote: >> >> >> >>> Hi, >> >>> I use User model to handle user's basic data such as Name, username, >>> password and so on. >> >>> The User model is associated with Rule model by belongsTo association, >>> while Rule model is associated to User model by hasMany association. >> >>> The later model "Rule" is meant by something like users groups so it >>> handles name, description, value and of-course id, for example, two >>> records from rules table: >> >>> id -> 1 >>> name -> Administrators >>> description -> The super users group! >>> value -> ABC >> >>> id -> 2 >>> name -> Editors >>> decription -> reviewers and articles writers. >>> value -> BC >> >>> In AuthComponent documentation >>> :http://book.cakephp.org/view/247/AuthComponent-Methods#user-387 >> >>> when they talked about "user" method of the component, they regards >>> that it is possible to retrieve the current user data from the session >>> in the view like: >> >>> # $session->read('Auth.User.first_name') //returns particular field >>> value >> >>> This example shows that the access of User model property first_name. >> >>> My Question Is, >> >>> How could I able to access the associated model property "Rule" such >>> as Rule.name ? >> >>> Best Regards! >> >> You should implement a login() method in your UsersController. In >> there, do something like: >> >> $this->Session->write('Auth.User.foo', 'bar'); >> >> When you need to read the info: >> >> echo $this->Auth->user('foo'); >> >> Basically, Auth::user() simply reads whatever data has been written to >> the Session's 'Auth.User' key (note the uppercase U). You can also >> write entire arrays: >> >> $this->Session->write('Auth.User.extra', array('foo' => 'bar')); > > Check out the new CakePHP Questions site http://cakeqs.org and help others > with their CakePHP related questions. > > You received this message because you are subscribed to the Google Groups > "CakePHP" group. > To post to this group, send email to cake-php@googlegroups.com > To unsubscribe from this group, send email to > cake-php+unsubscr...@googlegroups.com For more options, visit this group at > http://groups.google.com/group/cake-php?hl=en Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
Re: Auth Component and user information.
I also noticed another thing: The output of $this->Auth->user() ,without key parameter, is an array which is listing User model only without regarding the associated model. Array ( [User] => Array ( [id] => 1 [username] => admin [name] => Said Bakr [join_date] => 2010-06-14 19:35:00 [email] => said@gmail.com [rule_id] => 1 ) ) On Jun 7, 8:27 pm, cricket wrote: > On Jun 7, 11:39 am, saidbakr wrote: > > > > > Hi, > > > I use User model to handle user's basic data such as Name, username, > > password and so on. > > > The User model is associated with Rule model by belongsTo association, > > while Rule model is associated to User model by hasMany association. > > > The later model "Rule" is meant by something like users groups so it > > handles name, description, value and of-course id, for example, two > > records from rules table: > > > id -> 1 > > name -> Administrators > > description -> The super users group! > > value -> ABC > > > id -> 2 > > name -> Editors > > decription -> reviewers and articles writers. > > value -> BC > > > In AuthComponent documentation > > :http://book.cakephp.org/view/247/AuthComponent-Methods#user-387 > > > when they talked about "user" method of the component, they regards > > that it is possible to retrieve the current user data from the session > > in the view like: > > > # $session->read('Auth.User.first_name') //returns particular field > > value > > > This example shows that the access of User model property first_name. > > > My Question Is, > > > How could I able to access the associated model property "Rule" such > > as Rule.name ? > > > Best Regards! > > You should implement a login() method in your UsersController. In > there, do something like: > > $this->Session->write('Auth.User.foo', 'bar'); > > When you need to read the info: > > echo $this->Auth->user('foo'); > > Basically, Auth::user() simply reads whatever data has been written to > the Session's 'Auth.User' key (note the uppercase U). You can also > write entire arrays: > > $this->Session->write('Auth.User.extra', array('foo' => 'bar')); Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
Re: Auth Component and user information.
Well, but what about the data in the associated Model Rules? How could I get it? On Jun 7, 8:27 pm, cricket wrote: > On Jun 7, 11:39 am, saidbakr wrote: > > > > > Hi, > > > I use User model to handle user's basic data such as Name, username, > > password and so on. > > > The User model is associated with Rule model by belongsTo association, > > while Rule model is associated to User model by hasMany association. > > > The later model "Rule" is meant by something like users groups so it > > handles name, description, value and of-course id, for example, two > > records from rules table: > > > id -> 1 > > name -> Administrators > > description -> The super users group! > > value -> ABC > > > id -> 2 > > name -> Editors > > decription -> reviewers and articles writers. > > value -> BC > > > In AuthComponent documentation > > :http://book.cakephp.org/view/247/AuthComponent-Methods#user-387 > > > when they talked about "user" method of the component, they regards > > that it is possible to retrieve the current user data from the session > > in the view like: > > > # $session->read('Auth.User.first_name') //returns particular field > > value > > > This example shows that the access of User model property first_name. > > > My Question Is, > > > How could I able to access the associated model property "Rule" such > > as Rule.name ? > > > Best Regards! > > You should implement a login() method in your UsersController. In > there, do something like: > > $this->Session->write('Auth.User.foo', 'bar'); > > When you need to read the info: > > echo $this->Auth->user('foo'); > > Basically, Auth::user() simply reads whatever data has been written to > the Session's 'Auth.User' key (note the uppercase U). You can also > write entire arrays: > > $this->Session->write('Auth.User.extra', array('foo' => 'bar')); Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
Re: Auth Component and user information.
On Jun 7, 11:39 am, saidbakr wrote: > Hi, > > I use User model to handle user's basic data such as Name, username, > password and so on. > > The User model is associated with Rule model by belongsTo association, > while Rule model is associated to User model by hasMany association. > > The later model "Rule" is meant by something like users groups so it > handles name, description, value and of-course id, for example, two > records from rules table: > > id -> 1 > name -> Administrators > description -> The super users group! > value -> ABC > > id -> 2 > name -> Editors > decription -> reviewers and articles writers. > value -> BC > > In AuthComponent documentation > :http://book.cakephp.org/view/247/AuthComponent-Methods#user-387 > > when they talked about "user" method of the component, they regards > that it is possible to retrieve the current user data from the session > in the view like: > > # $session->read('Auth.User.first_name') //returns particular field > value > > This example shows that the access of User model property first_name. > > My Question Is, > > How could I able to access the associated model property "Rule" such > as Rule.name ? > > Best Regards! You should implement a login() method in your UsersController. In there, do something like: $this->Session->write('Auth.User.foo', 'bar'); When you need to read the info: echo $this->Auth->user('foo'); Basically, Auth::user() simply reads whatever data has been written to the Session's 'Auth.User' key (note the uppercase U). You can also write entire arrays: $this->Session->write('Auth.User.extra', array('foo' => 'bar')); Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
Auth Component and user information.
Hi, I use User model to handle user's basic data such as Name, username, password and so on. The User model is associated with Rule model by belongsTo association, while Rule model is associated to User model by hasMany association. The later model "Rule" is meant by something like users groups so it handles name, description, value and of-course id, for example, two records from rules table: id -> 1 name -> Administrators description -> The super users group! value -> ABC id -> 2 name -> Editors decription -> reviewers and articles writers. value -> BC In AuthComponent documentation : http://book.cakephp.org/view/247/AuthComponent-Methods#user-387 when they talked about "user" method of the component, they regards that it is possible to retrieve the current user data from the session in the view like: # $session->read('Auth.User.first_name') //returns particular field value This example shows that the access of User model property first_name. My Question Is, How could I able to access the associated model property "Rule" such as Rule.name ? Best Regards! Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en