Php 调用未定义的函数inval()
我在CodeIgniter中的_模型中有一个错误。我到处都找过了,但什么都没找到我的模型:Php 调用未定义的函数inval(),php,codeigniter,codeigniter-2,Php,Codeigniter,Codeigniter 2,我在CodeIgniter中的_模型中有一个错误。我到处都找过了,但什么都没找到我的模型: <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); class MY_Model extends CI_Model { protected $_table_name = ''; protected $_primary_key = 'id'; protected
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class MY_Model extends CI_Model
{
protected $_table_name = '';
protected $_primary_key = 'id';
protected $_primary_filter = 'intval';
protected $_order_by = '';
protected $_rules = array();
protected $_timestamps = FALSE;
function __construct(){
parent::__construct();
$this->load->database();
}
public function get($id = NULL, $single = FALSE)
{
if ($id != NULL)
{
$filter = $this->_primary_filter;
$id = $filter($id);
$this->db->where($this->_primary_key,$id);
$method = 'row';
}
elseif($single == TRUE)
{
$method = 'row';
}
else
{
$method = 'result';
}
if(!count($this->db->ar_orderby))
{
$this->db->order_by($this->_order_by);
}
return $this->db->get($this->_table_name)->$method();
}
public function get_by($where, $single = FALSE)
{
$this->db->where($where);
return $this->get(NULL, $single);
}
public function save($data, $id = NULL)
{
//Set timestamp
if($this->_timestamps == TRUE)
{
$now = date('Y-m-d H:i:s');
$id || $data['created'] = $now;
$data['modified'] = $now;
}
//INSERT
if ($id ===NULL)
{
!isset($data[$this->_primary_key]) || $data[$this->_primary_key] = NULL;
$this->db->set($data);
$this->db->insert($this->_table_name);
$id = $this->db->insert_id();
}
//UPDATE
else
{
$filter = $this->_primary_filter;
$this->db->set($data);
$this->db->where($this->_primary_key,$id);
$this->db->update($this->_table_name);
}
return $id;
}
public function delete($id)
{
$filter = $this->_primary_filter;
$id = $filter($id);
$this->db->where($this->_primary_key,$id);
$this->db->limit(1);
$this->db->delete($this->_table_name);
}
}
?>
当我写:cms/page/delete…时,错误是:
Fatal error: Call to undefined function inval() in C:\xampp\htdocs\application\core\MY_Model.php on line 75
请帮助我我想您的问题出在
delete()
函数中
$filter = $this->_primary_filter;
$id = $filter($id);
确保收到正确的id
和类型
(int,bool)更改您的:
$filter = $this->_primary_filter;
$id = $filter($id);
致:
你能告诉我你的保存功能正常吗?更改
$id=$filter($id)代码>到$id=intval($id)
insidefunction delete()
并重试。检查$filter=$this->\u primary\u filter$id=$filter($id);您的id是否正确?protected$\u primary\u filter='intval'代码>但错误消息包含无效
(不带t)。代码片段中最后一次使用此函数thingy是在第72行,而不是eror消息中所述的第75行。你确定你发布的代码就是正在执行的代码吗?你所说的“正确的id和类型(int,bool)”是什么意思?请把答案贴在这里。你可以在评论中发表你的假设。
$filter = $this->_primary_filter;
$id = $filter($id);
$id = intval($id);