Codeigniter模型功能不起作用

时间:2014-09-11 15:53:52

标签: codeigniter

我开始使用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 */

?>

1 个答案:

答案 0 :(得分:0)

检查{}test功能 User课程。将它移到课堂内,然后$this->User->test()就可以了。

<?php
    class User extends CI_Model {

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

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

没有什么&#34;可怕的&#34;关于文件。