|
model层:
class News_model extends CI_Model
{
public function __construct(){
parent::__construct();
$this->load->database();
}
public function take_news()
{
$query=$this->db->get('news');
return $query->row_array();
}
}
控制器:
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 __construct()
{
$this->load->model('News_model');
}
public function index()
{
$data['a'] = '变量测试输出';
$data['b'] = '案例拉倒辣的了卡的林科大辽阔的';
$data=$this->news_model->take_news();
var_dump($data);
$this->load->view('welcome_message.html',$data);
}
}
视图输出:
A PHP Error was encounteredSeverity: Notice
Message: Undefined property: Welcome:load
Filename: controllers/welcome.php
Line Number: 23
Fatal error: Call to a member function database() on a non-object in D:\wamp\www\htdocs\CodeIgniter\application\controllers\welcome.php on line 23
|
|