Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Codeigniter模型功能不工作_Codeigniter - Fatal编程技术网

Codeigniter模型功能不工作

Codeigniter模型功能不工作,codeigniter,Codeigniter,我从codeigniter开始,但是文档编写得很糟糕,实际上不能与新版本一起使用。我的问题是我不能在模型中调用函数 这是我的模型:User.php <?php class User extends CI_Model { function __construct() { parent::__construct(); } } function test($x) { re

我从codeigniter开始,但是文档编写得很糟糕,实际上不能与新版本一起使用。我的问题是我不能在模型中调用函数

这是我的模型:User.php

 <?php

    class User extends CI_Model {

        function __construct()
        {
            parent::__construct();
        }
    }
    function test($x)
    {
        return $x;
    }

    ?>

还有我的控制器:welcome.php

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Welcome extends CI_Controller {

    /**
     * Index Page for this controller.
     *
     * Maps to the following URL
     *      http://example.com/index.php/welcome
     *  - or -  
     *      http://example.com/index.php/welcome/index
     *  - or -
     * Since this controller is set as the default controller in 
     * config/routes.php, it's displayed at http://example.com/
     *
     * So any other public methods not prefixed with an underscore will
     * map to /index.php/welcome/<method_name>
     * @see http://codeigniter.com/user_guide/general/urls.html
     */
    public function index()
    {
        $this->load->model('User');
        echo $this->User->test('darn');
        $this->load->view('welcome_message');
    }
}

/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */

?>

检查您的
{}
s,您的
测试
函数不在您的
用户
类中。将其移动到类中,然后
$this->User->test()
将起作用

<?php
    class User extends CI_Model {

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

        function test($x)
        {
            return $x;
        }
    }
?>


文档没有什么“可怕”的地方。

您的文件应该命名为
user.php
(小写)。它怎么会“不工作”?您看到错误消息了吗?文档很好,如果您遵循它,一切都会正常工作。我将名称更改为user.php,并得到错误php致命错误:在/var/www/html/application/controllers/welcome.php第28行调用未定义的方法user::test(),很高兴我能提供帮助:-)