Welcome Guest, Not a member yet? Register   Sign In
rest api to database - Call to a member function where() on a non-object
#1

[eluser]newtonianb[/eluser]
I'm trying to implement a rest api using http://net.tutsplus.com/tutorials/php/wo...igniter-2/

Everything works fine until I try to use my models in my application where I start getting
"Call to a member function where() on a non-object"

In my regular application I have a controller that loads a library and that library then loads a model which performs a database operation.

Here I'm trying to go from my restapi which extends REST_CONTROLLER which extends CONTROLLER to run a library function.
======controller_myclass.php
class myClassextends REST_Controller
{
function __construct()
{
parent::__construct();
$this->load->library('lib_myclass');

// if i try $this->load->library('database'); I get Unable to load the requested class: database
}
======lib_myclass.php
public function __construct()
{
$this->ci =& get_instance();
$this->ci->load->model('model_myclass.php');

======model_myclass.php
function needToCallThisFunction($inUsername) {
return $this->db->where('username', $inUsername)
->from(myusers)
->count_all_results() > 0;
}

So I tried to change the function as below but still got the same problem
======model_myclass.php
function needToCallThisFunction($inUsername) {
$ci = &get;_instance();
return $ci->db->where('username', $inUsername)
->from(myusers)
->count_all_results() > 0;
}


What am i missing? What in my regular application allows me to use $this-> without having to specify a ci instance?


Messages In This Thread
rest api to database - Call to a member function where() on a non-object - by El Forum - 11-30-2010, 11:15 PM



Theme © iAndrew 2016 - Forum software by © MyBB