Vote count:
0
I've looked at CakePHP save without form and tried to adapt that information, but it didn't work for me. I've trying to create a new record.
Situation: I'd like to periodically run a cron job to snapshot some information about my site to another table, in particular, the current number of users. I've created a Model, Analytics and I have a controller with a function named snapshot. I don't want to create a view I just want to grab a count of records and add it to the Analytics table with the current date.
This is the core of that routine:
$num_users = $this->User->find('count');
$nw = date("Y-m-d");
$this->Analytic->create();
if ($this->Analytic->save(array('Analytic' => array (
'num_users' => $num_users,
'snapshot' => $nw))) ) {
$this->Session->setFlash(__('The analytic has been saved.'));
return $this->redirect(array('action' => 'index'));
} else {
throw new NotFoundException(__('Cannot save analytics [$num_users]'));
}
I'm getting an error that the object $this->Analytic doesn't exist.
I'm guessing that ordinarily this object gets created from a form submission of a View. Can I create this object on the fly with a view?
thanks!
asked 54 secs ago
In CakePHP how do I save a record without using a Form or View?
Aucun commentaire:
Enregistrer un commentaire