0

I get the following error:

  • Fatal error: Call to undefined function getAll() in ...application\controllers\restserver.php on line 18
  • A PHP Error was encountered
  • Severity: Error
  • Message: Call to undefined function get()
  • Filename: controllers/restserver.php
  • Line Number: 24
  • Backtrace:

And I have the following Controller: restserver.php

defined('BASEPATH') OR exit('No direct script access allowed');
require APPPATH . '/libraries/REST_Controller.php';

class Restserver extends REST_Controller {

    public function __construct() {
        parent::__construct();

        $this->load->database();
        $this->load->helper('url');
    }

    public function appproviders_get() {
        $this->load->model('appproviders_model');
        $this->response($this->appproviders_model>getAll());
   }

    public function appprovider_get() {
        $data = array('returned: '. $this->get('id'));
        $this->load->model('appproviders_model');
        $this->response($this->appproviders_model>get($data));
   }
}

And the following model: appproviders_model.php

class appproviders_model extends CI_Model {

function __construct(){

    parent::__construct();//Call the model constructor
}

function get($id = 0)
{
    $this -> db -> select('appprovider.*');
    $this -> db -> from('appprovider');
    $this -> db -> join('appusers','appprovider.userID = appusers.id','left');
    $this -> db -> where('appprovider.id', $id);

    $query = $this -> db -> get();

    if($query->num_rows()>0){
        $row = $query->row();
        return $row;
    } else {
        return NULL;
    }
}

function getAll()
{
    $this -> db -> select('appprovider.*, appusers.name as name');
    $this -> db -> from('appprovider');
    $this -> db -> join('appusers','appprovider.userID = appusers.id','left');
    $this -> db -> where('appprovider.status', 1);

    $query = $this -> db -> get();

    if($query->num_rows()>0){
        $row = $query->row();
        return $row;
    } else {
        return NULL;
    }
    }
}

And I'm using the following RESTful server implementation for CodeIgniter:

https://github.com/chriskacerguis/codeigniter-restserver

Any idea why when I call from the browser:

.../restserver/appprovider?id=1;format=json

or

.../restserver/appproviders?format=json

I get the errors detailed at the beginning of the post? It is indeed detecting the model but not its functions.

Must be something so simple, but I cannot find the error and I'm going totally crazy ...

2
  • You're missing a dash in your syntax: appproviders_model>get($data) should be appproviders_model->get($data), and the same for the getAll line. Commented Mar 1, 2018 at 13:42
  • Yeap, thank you very much. Commented Mar 1, 2018 at 13:57

1 Answer 1

2

Try this,

You should replace

$this->response($this->appproviders_model>getAll());

to

$this->response($this->appproviders_model->getAll());

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.