TIP: Use Markdown or, <pre> for multi line code blocks / <code> for inline code.
These forums are read-only and for archival purposes only!
Please join our new forums at discourse.kohanaframework.org
kohana model base class has no constructor
  • I'm trying to generate results from a 'Model_Player' class and there is no parent constructor for the model base class. So there is no database connection established and I get the error:

    Undefined property: Model_Player::$db

  • Can you provide some more source code? Where are you calling this from?

  • class Controller_Player extends Controller {
    
        private $player_model;
        private $playerother_model;
        private $playerdata_model;
    
        private $list_view;
        private $create_view;
        private $update_view;
    
        public function before() {
    
            parent::before();
            $this->player_model = new Model_Player;
            //this->playerother_model = new Playerother_Model;
            //$this->playerdata_model = new Playerdata_Model;
    
            $this->list_view = new View('list');
            //$this->update_view = new View('update');
            //$this->create_view = new View('create');
    
        }
    
    public function action_index()
    {
            $this->show_player_list();  
    }
    
        public function show_player_list() {
    
            $player_list = $this->player_model->get_list();
            $this->list_view->set('players', $player_list);
            $this->list_view->render(TRUE);
    
        }
    
    } // End Player
    
    class Model_Player extends Model
    {
    private $player_table;
    private $playerother_table;
    private $db;
    
    public function __construct()
    {
        $this->player_table = 'player';
        $this->playerother_table = 'playerother';
    }
    
    
    public function get_list()
    {
        $this->db->select("fname"); 
        $this->db->from($this->player_table); 
        //$this->db->join($this->playerother_table,'playerother.pid','player.id');
        $query = $this->db->get();
        return $query->result_array();
    }
    } //Model_Player
    
  • @jpking872 basic kohana pack supports: model - "interface" for model classes, model_database - easy model for db, orm - object-relational mapping models. translate and read http://kohanaframework.su/database

  • It seems like there are a lot of small changes like that with release 3.3.1 that are not updated in the documentation. For example, it is now Model_Player not Player_Model. Now I'm getting this error when I extend ORM:

    Declaration of Model_Player::create() should be compatible with   
    Kohana_ORM::create(Validation $validation = NULL)
    
  • Scratch the above comment, I figured it out.

  • @jpking872 " For example, it is now Model_Player not Player_Model." it was always in 3.x, class name must be a certain format for autoloading: calling new Model_Player or Model::factory('Player') load 'classes/Model/Player.php'.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion