model view controller - Return class name and access it from $this afterwards in php -


hello building application , want similar codeigniter.

i have controller class:

class controller{      function __construct(){         $this->view = new view();         $this->load = new loader();     } } 

my loader class:

class loader{      function __construct(){         echo 'loader class instanciated';     }      public function model($model){         $file = 'models/' . $model . '.php';         if (file_exists($file)) {             require $file;             $this->model = new $model();             return $this->model;         }     } } 

and controller class:

class extends controller{      function __construct(){         parent::__construct();     }      public function index(){         $this->view->render('index/index');     }      public function other(){         $model = $this->load->model('help_model');         $model->meth();     } } 

so far works. have like:

$this->load->model('help_model'); $this->help_model->meth(); 

how possible? gives me error of undefined variable help::$help_model() when try use this.

you're defining $model not help_model. in loader class below. haven't used php in while hope helps.

$this->{$model} = new $model(); 

then in do

$this->load->model('help_model');  $this->load->help_model->meth(); 

Comments

Popular posts from this blog

sequelize.js - Sequelize group by with association includes id -

android - Robolectric "INTERNET permission is required" -

java - Android raising EPERM (Operation not permitted) when attempting to send UDP packet after network connection -