REST Controller Issue - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5) +--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24) +--- Thread: REST Controller Issue (/showthread.php?tid=604) |
REST Controller Issue - DanielUS - 12-24-2014 Im having some trouble trying to configure the RestServer library for CodeIgniter (https://github.com/chriskacerguis/codeigniter-restserver/blob/master/application/libraries/REST_Controller.php). //EDIT I'm using Code Igniter Version 2.1.3 Whenever I try to access a model from a Controller, it returns an error saying: A PHP Error was encountered Severity: Notice Message: Undefined property: Dan::$dM My controller looks like this <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); // This can be removed if you use __autoload() in config.php OR use Modular Extensions require APPPATH.'/libraries/REST_Controller.php'; class Dan extends REST_Controller { function __construct(){ parent::__construct(); $this->load->model('dan_model','dM',TRUE); } public function ptest_get() { //$this->load->model('dan_model','dM'); //var_dump($this->dM); $test = $this->dM->testSum(); //$test = 1; $this->response($test, 200); // 200 being the HTTP response code } } ?> I have configured everything that the documentation states, I have loaded the database module in the autoload.php, I have tried loading the model in the construct and in the function but it always returns the error. The only solution I have found (which is not efficiente) is in the autoload.php file configure to load all the models since the beginning (thing that we don't want because of performance). /* | ------------------------------------------------------------------- | Auto-load Models | ------------------------------------------------------------------- | Prototype: | | $autoload['model'] = array('model1', 'model2'); | */ $autoload['model'] = array('finder_model'); Could anyone point me if I'm missing some configuration or what I'm doing wrong? RE: REST Controller Issue - dbui - 12-30-2014 How about using $this->dan_model->testSum(), I think the complaint was that CI didnt understand the 'alias' name of model RE: REST Controller Issue - jlp - 12-31-2014 Hmm - I tried essentially the same thing you describe, but not using a REST controller, and had no problem. What line # is the error reported at, and what does that correspond to in your controller? |