用户
 找回密码
 入住 CI 中国社区
搜索
查看: 2083|回复: 2
收起左侧

关于CI的model写的模型不能被调用的问题

[复制链接]
发表于 2013-1-29 10:12:44 | 显示全部楼层 |阅读模式
2CI币
我在model中写了一个文件名为company.php如下:
<?php
class Company extends CI_Model
{
function __construct()
{
parent::__construct();
$this->load->database();
}
function company_insert($arr){
$this->db->insert(company', $arr);
}
}
?>




在controllers下写的文件如下 :
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Company extends CI_Controller {

function insert()
{
$na=array("c_name"=>"tom01","c_Describe"=>"qingna01","temp1"=>"");

$this->load->model('company');
$this->company->company_insert($na);
}}
?>

总是不能通过;


而单独在controllers文件夹下写文件company.php:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Company extends CI_Controller {

function insert()
{

$this->load->database();
$na=array("c_name"=>"tom01","c_Describe"=>"qingna01","temp1"=>"");
$this->db->insert(company', $na);
}
能通过!


请教高手,指点一下!在下感激不尽!!!!

发表于 2013-1-29 13:40:26 | 显示全部楼层
你这代码都是手写上来的吧    没有直接去你的项目里发过来,。。。$this->db->insert(company', $na); 这里少一个  '   。应该是$this->db->insert('company', $na);
基本上没有什么大问题,注意文件名大小写
回复

使用道具 举报

发表于 2013-1-29 13:41:44 | 显示全部楼层
sdink 发表于 2013-1-29 13:40
你这代码都是手写上来的吧    没有直接去你的项目里发过来,。。。$this->db->insert(company', $na); 这 ...

要你的controllers里应该加入

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

请给分吧。。。。。
回复

使用道具 举报

本版积分规则