Welcome Guest, Not a member yet? Register   Sign In
issue accessing CI with curl?
#1

[eluser]gedev2006[/eluser]
Hi

I have an issue im just not understanding.

Im using curl in an external script to access a CI controller. Lets say for example

Code:
$_curl = curl_init ( "http://test.com/index.php/test/example" );
$_result = curl_exec( $_curl );

So, this works fine, lets say the controller looks like this:

Code:
class Test extends Controller {

    public function example(){

        $this->load->model ( 'testing' );

        $_data = $this->testing->test();


        echo $_data;

    }

}

All good so far. So lets look at the model:

Code:
class Testing extends Model {

    public function test() {

       $_result = $this->db->query ( "QUERY STRING HERE");

    }

}

ok so i stopped the code there. because im getting the following error:

[quote]Fatal error: Using $this when not in object context[/code]

but...if i create the model like this:

Code:
$Model =& new Model();
$Model->db->query ( "QUERY STRING HERE");

it works fine!

so whats with the error?
#2

[eluser]imn.codeartist[/eluser]
You have error in your model because you have extend the Model class but

you haven't declared your constructor for your Testing Model class

It's suppose to be like this

Code:
class Testing extends Model {

    function Testing()
    {
         parent::Model();
    }
    public function test() {

       $_result = $this->db->query ( "QUERY STRING HERE");

    }

}

This should works
#3

[eluser]Colin Williams[/eluser]
dixcoder, there is no requirement to provide a constructor, only that if you do, you must remember to call the parent class's constructor.

gedev2006, you might need to check your install. Make sure no core files got modified
#4

[eluser]gedev2006[/eluser]
Hi

Exactly, no need for a constructor...though actually i have had issues in the past if a constructor isnt there.

The install wasnt modifierd! Just unzipped
#5

[eluser]gedev2006[/eluser]
ok so adding a constructor makes no difference. also tried a re-install. with no change
#6

[eluser]gedev2006[/eluser]
it only appears to be doing this when accessing via curl. if i access the controller directly there is no problem.

Im unsure as to why this is happening?
#7

[eluser]gedev2006[/eluser]
from what i can tell, it appears as though codeigniter for some reason when i access through curl is calling the model statically...but then in the code this cant be possible...Angry
#8

[eluser]gedev2006[/eluser]
Ha

I figured it out. It was me being an idiot.

I was using call_user_func_array in the controller but calling the name of the class without $this-> in front of it. So it was called satically lol




Theme © iAndrew 2016 - Forum software by © MyBB