MainsController::view()

$log = ClassRegistry::init('Log');
$log->create();
$this->data['Log']['main_id'] = 23;
$this->data['Log']['referrer'] = ...
$log->save($this->data['Log']);

But if you define in Main model hasMany Logs,
you can write like this:
$this->Main->Log->create();
$this->data['Log']['main_id'] = 23;
$this->data['Log']['referrer'] = ...
$this->Main->Log->($this->data['Log']);
....

On Aug 20, 7:04 pm, "James P. Howard, II" <[email protected]> wrote:
> I am a week into CakePHP and have a built a simple application that is
> doing some neat things.  But now I am stuck.  I'd like to have it log to
> the database every time my primary model is viewed (or edited).  So I
> have a logs table and it looks like this:
>
> mysql> describe logs;
> +----------+---------------------+------+-----+-------------------+----------------+
> | Field    | Type                | Null | Key | Default           |Extra
>
> +----------+---------------------+------+-----+-------------------+----------------+
> | id       | bigint(20) unsigned | NO   | PRI |          |auto_increment
> | main_id  | bigint(20)          | NO   |     |                   |
>
> | time     | timestamp           | YES  |     | CURRENT_TIMESTAMP |
>
> | referrer | varchar(1024)       | NO   |     |                   |
>
> +----------+---------------------+------+-----+-------------------+----------------+
> 4 rows in set (0.00 sec)
>
> Then I have a simple model for Log that belongs to Main.  Inside
> MainsController, I have a method called view() that displays the Main
> entry.  What is the "correct" way to also have view() create and write
> the log?
>
> Thank you, James
>
> --
> James P. Howard, II, MPA
> [email protected]
>
>  signature.asc
> < 1KViewDownload
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to [email protected]
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to