【发布时间】:2019-06-27 20:33:41
【问题描述】:
我想将我的变量 $lastid 传递给同一类中的另一个函数。我该怎么做??..我尝试了一些东西,但它不起作用?
class ProductmModel extends CI_Model
{
var $PRODUCTNAME='';
var $DESCRIPTION='';
var $CATEGORY='';
var $SUBCAT='';
var $IMAGE='';
public function addproductm()
{
$this->load->database();
$data = array(
"p_name" => $this->PRODUCTNAME,
"p_des" => $this->DESCRIPTION,
"cat" => $this->CATEGORY,
"subcat" => $this->SUBCAT
);
$this->db->insert('product_multi', $data);
$lastid = $this->db->insert_id();
}
这是下一个函数
public function addimage()
{
$last= $this->addproductm();
$this->load->database();
$data = array(
"pid" => $lastid,
"images" => $this->IMAGE
);
$this->db->insert('image', $data);
}
}
【问题讨论】:
-
尝试将 id 传递给函数。
public function addimage($product_id)并在你想传递 id 的地方调用这个函数,这里在addproductm()函数为$this->addimage($lastid) -
为什么不在全局范围内扩展
$lastid的声明? php.net/manual/en/language.variables.scope.php
标签: php function codeigniter class mysqli