【问题标题】:Codeigniter: Call to undefined function (model)Codeigniter:调用未定义的函数(模型)
【发布时间】:2018-03-01 13:40:26
【问题描述】:

我收到以下错误:

  • 致命错误:调用未定义的函数 getAll() ...application\controllers\restserver.php 第 18 行
  • 遇到 PHP 错误
  • 严重性:错误
  • 消息:调用未定义的函数 get()
  • 文件名:controllers/restserver.php
  • 行号:24
  • 回溯:

我有以下控制器: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));
   }
}

以及以下模型: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;
    }
    }
}

我正在为 CodeIgniter 使用以下 RESTful 服务器实现:

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

知道为什么当我从浏览器调用时:

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

.../restserver/appproviders?format=json

我得到了帖子开头的详细错误信息? 它确实在检测模型而不是它的功能。

一定是这么简单,但我找不到错误,我快疯了......

【问题讨论】:

  • 语法中缺少破折号:appproviders_model>get($data) 应该是 appproviders_model->get($data),getAll 行也是如此。
  • 好的,非常感谢。

标签: php function codeigniter model undefined


【解决方案1】:

试试这个,

你应该替换

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-04-06
    • 2012-02-16
    • 2018-05-05
    • 2017-03-01
    • 1970-01-01
    • 1970-01-01
    • 2023-01-02
    • 2021-09-17
    相关资源
    最近更新 更多