Akelos Framework v1 forum archive. This forum is no longer maintained. To report bugs please visit https://github.com/akelos/akelos/issues
    • CommentAuthorraiho
     
    I have the code:

    class HomeController extends ApplicationController
    {
    var $models = 'User, Addressbook, Contact';

    ...................
    }

    class ContactController extends HomeController
    {
    function menu()
    {
    //print_r($this);
    $this->layout = 'contact';
    if( !empty($this->params['id']) ){
    $param = $this->params['id'];
    $options = array('conditions' => array("addressbook_id = $param"));
    $this->contacts = $this->Contact->find('all',$options); // <--------
    //Fatal error: Call to a member function find()
    //on a non-object in /var/www/rubrica3/app/
    //controllers/contact_controller.php on line 24
    }
    }
    }

    So take a look.

    if I call the page 'www.mysite.com/contact/menu/9' appears this error:
    Fatal error: Call to a member function find() on a non-object in /var/www/rubrica3/app/controllers/contact_controller.php on line 24
    because $this->Contact is strangely not istanced,
    else if I call the page 'www.mysite.com/contact/menu/' $this->Contact exists...

    is it a bug or I made some mistake?
    • CommentAuthorsuthern
     

    Your options may work, but would be better written like this

    $options = array('conditions' => array('addressbook_id = ?', $param));
    

    That 'cleans' the $param variable, protecting against SQL injection attack I think. As to why $this->Contact is not automatically loaded, I'm not sure.

    • CommentAuthorjan.bartos
     
    Model names should be in lowercase, i.e.

    var $models = 'user, addressbook, contact';