Create a new model instance and return its new ID

2008-07-25 Thread GrandiJoos

Hi,

I want to create a new model instance from a controller (linked to an
other model).
The data in the model can be populated by the method itself (user id)
etc.
Furthermore, the id of the just created model should be returned to
use as a foreign key in the current model.
How do I do this?

Sample code:
http://bin.cakephp.org/view/997858437

Please help this newbie :p

GrandiJoos

PS sorry if the information is sparse
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Create a new model instance and return its new ID

2008-07-25 Thread Smelly_Eddie

GJ:

When users register on one site onf mine, i automatically add them to
a table of news articles. I think this is a similar idea top what you
(very) sparsley described.
this is calledc from users/register ,and calls a function in a
behavior, that User actsas. You could also place directly int he model
me thinks.

//get id of newly registered user
$lastId = $this-User-getLastInsertId();
//subscribe new user to internal news 
for all
project
$this-User-addToNews($lastId);

//behavior
function addtonews($userID){
$model-query('INSERT INTO `join_table` (`project_id`, `user_id`)
VALUES (\'1\', \''.$userID.'\')');



i think that should get yo going.

the api and manual have great expalnations of various methods
available to cake.

On Jul 25, 9:52 am, GrandiJoos [EMAIL PROTECTED] wrote:
 Hi,

 I want to create a new model instance from a controller (linked to an
 other model).
 The data in the model can be populated by the method itself (user id)
 etc.
 Furthermore, the id of the just created model should be returned to
 use as a foreign key in the current model.
 How do I do this?

 Sample code:http://bin.cakephp.org/view/997858437

 Please help this newbie :p

 GrandiJoos

 PS sorry if the information is sparse
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---