var $components = array('DebugKit.Toolbar', 'Session');
function beforeFilter()
{
// ricava la variabile di sessione
$id = $this->Session->read('editable_season_id');
// se non esiste o è un valore non valido
if((is_null($id)) || (!is_numeric($id)))
{
// importa modello Season
App::import('Model', 'Season');
// cerca l'id della stagione più recente
$id = $this->Season->getLastSeasonId();
....
gave me:
Undefined property: PagesController::$Season [CORE\cake\libs\controller
\app_controller.php, line 50]
Fatal error: Call to a member function getLastSeasonId() on a non-
object in C:\wamp\www\cakephp\cake\libs\controller\app_controller.php
on line 50
Line 50 is: $id = $this->Season->getLastSeasonId();
Why?
On 24 Mar, 22:23, cricket <zijn.digi...@gmail.com> wrote:
> On Thu, Mar 24, 2011 at 4:11 PM, Mariano C. <mariano.calan...@gmail.com> wrote:
> > I have this code, I need (for every page) to read a session, if
> > doesn't exist read from a model and then write the session, something
> > like:
>
> > ======================
> > function beforeFilter()
> > {
> > // read session variable
> > $id = $this->Session->read('editable_season_id');
>
> > // id doesn't exist
> > if((is_null($id)) || (!is_numeric($id)))
> > {
> > // find it
> > $id = $this->MyModel->getLastSeasonId();
> > $this->Session->write("editable_season_id", $id);
> > }
> > }
> > ======================
>
> > If I put it inside appController I can't use $this->MyModel,
> > but if I put it inside appModel I can't use $this->Session.
> > So.... where I should insert that code???
>
> There's no beforeFilter() in AppModel. That's for client requests. So,
> AppController. To get the model, use App::import('model', 'MyModel').
--
Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions.
To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php
No comments:
Post a Comment