Php 存在,但不存在';t声明类代码点火器
我试图加载这个名为“m_cart”的模型,但它在我的控制器上不起作用。我在这里遇到一个错误“M_cart.php存在,但没有声明类M_cart”Php 存在,但不存在';t声明类代码点火器,php,function,codeigniter,class,Php,Function,Codeigniter,Class,我试图加载这个名为“m_cart”的模型,但它在我的控制器上不起作用。我在这里遇到一个错误“M_cart.php存在,但没有声明类M_cart” Controller Part.php 您的模型必须声明为扩展CI\U模型的类 Class M_cart extends CI_Model { function get_all_produk() { $hasil=$this->db->get('produk'); return $hasil
您的模型必须声明为扩展CI\U模型的类
Class M_cart extends CI_Model
{
function get_all_produk()
{
$hasil=$this->db->get('produk');
return $hasil->result();
}
function some_other_model()
{
// some other thing
}
}
如果您要声明class Cart
(不要忘记扩展CI\u Controller
),则控制器名称应为Cart.php
而不是Part.php
)
m_cart
中的m应在文件名m_cart.php
和声明中大写,并应扩展CI_模型
,例如类m_cart扩展CI_模型
如果两者都无法工作,请确认您正在编辑与测试相同的副本
<?php
class Cart_model extends CI_Model{
function get_all_produk(){
$hasil=$this->db->get('produk');
return $hasil->result();
}
Class M_cart extends CI_Model
{
function get_all_produk()
{
$hasil=$this->db->get('produk');
return $hasil->result();
}
function some_other_model()
{
// some other thing
}
}