佛缘 发表于 2012-6-15 17:42:23

把数据库操作写到控制器可以,但是写到model里面就报错,请

本帖最后由 佛缘 于 2012-6-18 14:47 编辑

这段是model,在构造函数中链接数据库,里面有一个插入的方法
<?php
if (! defined ( 'BASEPATH' ))
exit ( 'No direct script access allowed' );
class Newstype_m extends CI_Model {
function __construct() {
$this->load->database ( 'mynews' );
}
function newstype_insert($arr) {
$this->db->insert ( 'NewsType', $arr );
}
}

这段是控制器代码,在构造函数中加载model,就因为记载这个model,就报错,我是安装官方文档的例子做的。


<?php
if (! defined ( 'BASEPATH' ))
exit ( 'No direct script access allowed' );
class Newstype extends CI_Controller {

public function __construct() {
parent::__construct ();
$this->load->model ( "newstype_m" );
}

public function index() {
$this->load->view ( "newstype/index" );
}

public function create() {
$this->load->view ( "newstype/create" );
}

public function post() {
}
}


错误提示如下:

曜日晨阳 发表于 2012-6-16 02:37:38

$this->load->database ( 'mynews' );

确认你的config/database.php里已经配置了相应的数据库连接。

佛缘 发表于 2012-6-18 14:47:38

问题已经解决,谢谢
页: [1]
查看完整版本: 把数据库操作写到控制器可以,但是写到model里面就报错,请