【问题标题】:Code Igniter Undefined property Controllerclass::$functionname [duplicate]Codeigniter 未定义属性 Controller Class::$function name [重复]
【发布时间】:2018-04-17 07:11:14
【问题描述】:

当我收到此错误时,我正在 PHP 上练习 CI 框架

消息:未定义的属性:Test_controller::$testFunction

我的 Test_controller.php 看起来像这样

class Test_controller extends CI_Controller {

public function test(){
    $this->load->model('Test_model');
    $test = $this->Test_model->testFunction;

    echo "Message : " . $test;
}

而我的 Test_model.php 看起来像这样

class Test_model extends CI_Model{

public function testFunction(){
    return "This is a test function on model";
}

我找不到哪里出错了。

感谢您的回答。

【问题讨论】:

  • testFunction是方法,请加括号。

标签: php codeigniter model controller


【解决方案1】:

Test_controller

在函数testFunction中添加()

class Test_controller extends CI_Controller {

public function test(){
    $this->load->model('Test_model');
    $test = $this->Test_model->testFunction();

    echo "Message : " . $test;
}

【讨论】:

  • 是的,这只是为了测试,我目前正在学习。这解决了问题......这很尴尬。
  • @jeesoon - 一般而言,您不应该从控制器回显。可以进行测试,但理想情况下,您可以将该数据传递给视图并让它处理格式。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2013-11-08
  • 1970-01-01
  • 1970-01-01
  • 2013-03-20
  • 2011-03-27
  • 1970-01-01
  • 2016-11-23
相关资源
最近更新 更多