|
View:
New views
4 Messages
—
Rating Filter:
Alert me
|
|
|
Echo Fields of Article Ceator/Modifer in ViewHi All, This seems like a real n00b question, but here goes. I'm working on an app which has articles - in my case news - and users who create/modify the news articles. Now I found this nifty little behaviour - http://blog.loadsys.com/2008/05/02/automagically-setting-user-id-of-record-creator-and-modifier-in-cakephp-12/ - which automagically records the user id in the news record when somebody adds or edits a news item. So I've got the user id of the creator/modifier in the news article record... lovely. So, how then do I use that id in the creator/modifer to grab say the name/email/username of the user and echo it out in a view? At first I was thinking it would be a relationship, but now I'm thinking I need to do something in the news controller? If anyone could point me in the right direct that would be much appreciated. Any examples would be helpful. TIA. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@... To unsubscribe from this group, send email to cake-php-unsubscribe@... For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~----------~----~----~----~------~----~------~--~--- |
|
|
Re: Echo Fields of Article Ceator/Modifer in ViewYou would need to define a relationship in your news model to the user's model via the id set by the behaviour. This will tell cake how to pull the related models from a find call on the news model (http:// book.cakephp.org/view/66/models#associations-linking-models-to-78). You'll also want to look in the manual for more information on the new containable behaviour built into the release candidates of CakePHP 1.2 for how to narrow down what fields/models you want returned (http:// book.cakephp.org/view/474/containable) Good luck, - James On Jul 9, 12:26 am, double07 <br...@...> wrote: > Hi All, > > This seems like a real n00b question, but here goes. I'm working on an > app which has articles - in my case news - and users who create/modify > the news articles. Now I found this nifty little behaviour -http://blog.loadsys.com/2008/05/02/automagically-setting-user-id-of-r... > - which automagically records the user id in the news record when > somebody adds or edits a news item. So I've got the user id of the > creator/modifier in the news article record... lovely. > > So, how then do I use that id in the creator/modifer to grab say the > name/email/username of the user and echo it out in a view? At first I > was thinking it would be a relationship, but now I'm thinking I need > to do something in the news controller? > > If anyone could point me in the right direct that would be much > appreciated. Any examples would be helpful. > > TIA. You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@... To unsubscribe from this group, send email to cake-php-unsubscribe@... For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~----------~----~----~----~------~----~------~--~--- |
|
|
Re: Echo Fields of Article Ceator/Modifer in ViewSo the News items should "Belong To" a user. The problem I see is that you can't seem to define a "local key"? My code in the News controller should look like this yeah? var $belongsTo = array('Creator' => array( 'className' => 'User', 'foreignKey' => 'user_id', 'localKey' => 'creator_id', //can't seem to define this? ), 'Modifier' => array( 'className' => 'User', 'foreignKey' => 'user_id', 'localKey' => 'modifer_id', //can't seem to define this? ), ); How can I define the local key? On Jul 9, 10:02 pm, James K <james.m.k...@...> wrote: > You would need to define a relationship in your news model to the > user's model via the id set by the behaviour. This will tell cake how > to pull the related models from a find call on the news model (http:// > book.cakephp.org/view/66/models#associations-linking-models-to-78). > > You'll also want to look in the manual for more information on the new > containable behaviour built into the release candidates of CakePHP 1.2 > for how to narrow down what fields/models you want returned (http:// > book.cakephp.org/view/474/containable) > > Good luck, > > - James > > On Jul 9, 12:26 am, double07 <br...@...> wrote: > > > Hi All, > > > This seems like a real n00b question, but here goes. I'm working on an > > app which has articles - in my case news - and users who create/modify > > the news articles. Now I found this nifty little behaviour -http://blog.loadsys.com/2008/05/02/automagically-setting-user-id-of-r... > > - which automagically records the user id in the news record when > > somebody adds or edits a news item. So I've got the user id of the > > creator/modifier in the news article record... lovely. > > > So, how then do I use that id in the creator/modifer to grab say the > > name/email/username of the user and echo it out in a view? At first I > > was thinking it would be a relationship, but now I'm thinking I need > > to do something in the news controller? > > > If anyone could point me in the right direct that would be much > > appreciated. Any examples would be helpful. > > > TIA. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@... To unsubscribe from this group, send email to cake-php-unsubscribe@... For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~----------~----~----~----~------~----~------~--~--- |
|
|
Re: Echo Fields of Article Ceator/Modifer in ViewGot this sorted if anybody was interested, my use of foreignKey was wrong... News Model: var $belongsTo = array ('Creator' => array( 'className' => 'User', 'foreignKey' => 'creator_id', ), 'Modifier' => array( 'className' => 'User', 'foreignKey' => 'modifier_id', ), ); To echo out in the view: <?php echo $news['Creator']['firstname']." ".$news['Creator'] ['lastname'] ?> <?php echo $news['Modifier']['firstname']." ".$news['Modifier'] ['lastname'] ?> That simple! Thanks for your input James! On Jul 11, 8:13 am, double07 <br...@...> wrote: > So the News items should "Belong To" a user. The problem I see is that > you can't seem to define a "local key"? > > My code in the News controller should look like this yeah? > > var $belongsTo = array('Creator' => array( > 'className' => 'User', > 'foreignKey' => 'user_id', > 'localKey' => 'creator_id', //can't seem to define this? > ), > 'Modifier' => array( > 'className' => 'User', > 'foreignKey' => 'user_id', > 'localKey' => 'modifer_id', //can't seem to define this? > ), > > ); > > How can I define the local key? > > On Jul 9, 10:02 pm, James K <james.m.k...@...> wrote: > > > You would need to define a relationship in your news model to the > > user's model via the id set by the behaviour. This will tell cake how > > to pull the related models from a find call on the news model (http:// > > book.cakephp.org/view/66/models#associations-linking-models-to-78). > > > You'll also want to look in the manual for more information on the new > > containable behaviour built into the release candidates of CakePHP 1.2 > > for how to narrow down what fields/models you want returned (http:// > > book.cakephp.org/view/474/containable) > > > Good luck, > > > - James > > > On Jul 9, 12:26 am, double07 <br...@...> wrote: > > > > Hi All, > > > > This seems like a real n00b question, but here goes. I'm working on an > > > app which has articles - in my case news - and users who create/modify > > > the news articles. Now I found this nifty little behaviour -http://blog.loadsys.com/2008/05/02/automagically-setting-user-id-of-r... > > > - which automagically records the user id in the news record when > > > somebody adds or edits a news item. So I've got the user id of the > > > creator/modifier in the news article record... lovely. > > > > So, how then do I use that id in the creator/modifer to grab say the > > > name/email/username of the user and echo it out in a view? At first I > > > was thinking it would be a relationship, but now I'm thinking I need > > > to do something in the news controller? > > > > If anyone could point me in the right direct that would be much > > > appreciated. Any examples would be helpful. > > > > TIA. You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@... To unsubscribe from this group, send email to cake-php-unsubscribe@... For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~----------~----~----~----~------~----~------~--~--- |
| Free Forum Powered by Nabble | Forum Help |