简体   繁体   中英

Codeigniter: Call to undefined function (model)

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 ...

Try this,

You should replace

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

to

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM