Welcome Guest, Not a member yet? Register   Sign In
Problem with RESTFul and CI_Controller

Hi all,

I have a quite strange problem here and after spending quite a lot of time - I am still no closer to solution Sad Any help is appreciated.

Oke, to give you clear view / idea, this is the concept:

Server 1: CI application with RESTFul client;
Server 2: CI application with RestFul server.

On server 1 I have one controller which initiates RESTFul and calls 'api' on the server 2. So far, no problems.

On server 2, API receives the params (_post) and calls the model to do some DB queries. Problem occurs here. Model is loaded, but when I try to execute it - it fails.

Here is the code:
Server 1
class Login extends CPIN_Controller
    function check_login()
        $this->load->library('Cpin2_rest_client', array('server' => REST_SERVER));
        $params = array(
            'page_id'        =>    1,
            'website_id'    =>    8, # 8 = MAM
            'lang_id'        =>    $this->session->userdata('lang_id')
        $test['text'] = $this->cpin2_rest_client->post('custom_text',$params,'json');
        # This code works fine and calls API script on server 2.
        # More code here bellow, which is not relevant

Server 2 (API):
# Load the REST Api
require BASEPATH.'/libraries/Cpin2_rest.php';

class Mam_api extends Cpin2_rest
    function custom_text_post()
        # Load appropriate model
        //echo '<pre>';print_r($this); echo '</pre>'; exit;
        # Call the model and get data; passing vars: page_id, website_id and lang_id
        $result = $this->mam->get_page_text($this->input->post('page_id'),$this->input->post('website_id'),$this->input->post('lang_id'));
            # Could not find text in DB
        $this->response('request failed',500);
            # We got data, send it back
        # Return the response

Problem is, on this line:
$result = $this->mam->get_page_text($this->input->post('page_id'),$this->input->post('website_id'),$this->input->post('lang_id'));

It says:
Quote:Severity: Notice
Message: Undefined property: Mam_api::$mam
Filename: api/mam_api.php
Line Number: 53

If I do:
echo '<pre>';print_r($this); echo '</pre>'; exit;

I get:
Mam_api Object
( ... * a lot of params (array values) here )
But import one is at the end, which says:
[mam] => Mam Object
(it is empty).

So - what the hell am I doing wrong here Sad


Small update;

If I put:

$mam = new Mam();

and then call:

$result = $mam->get_page_text($this->input->post('page_id'),$this->input->post('website_id'),$this->input->post('lang_id'));

Then it is working. But, imho - this should not be necessary Sad

Any help is appreciated.

Theme © iAndrew 2016 - Forum software by © MyBB