Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/265.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 从一种方法到另一种方法获取变量-Codeigniter_Php_Codeigniter - Fatal编程技术网

Php 从一种方法到另一种方法获取变量-Codeigniter

Php 从一种方法到另一种方法获取变量-Codeigniter,php,codeigniter,Php,Codeigniter,我的Codeigniter模型中有两种方法/函数 public function main_product($p_id) { $this->db->select('p.*'); $this->db->from('products_main as p'); $this->db->where('p.product_id',$p_id); $this->db->where('p.status','Active');

我的Codeigniter模型中有两种方法/函数

public function main_product($p_id) {


    $this->db->select('p.*');
    $this->db->from('products_main as p');
    $this->db->where('p.product_id',$p_id);
    $this->db->where('p.status','Active');
    $query = $this->db->get();

    if ($query->num_rows() > 0):
        return $query->result();
        foreach($query->result() as $row):

            $product_tag = $row->product_tag;
            $product_id = $row->product_id;
            $name_family = $row->name_family;

        $this->main_images($product_id, $product_tag, $name_family);
        endforeach;         
    else:
        $this->session->set_flashdata( 'message', 'The main product query was unsuccessful.' );
    endif;      
}


public function main_images($product_id, $product_tag, $name_family) {
    //run query
    $this->db->select('im.*'); 
    $this->db->from('images_main as im');
    $this->db->where('im.pro_img_id',$p_id);
    /*$this->db->where('im.img_tag',$product_tag);
    $this->db->where('im.img_family',$name_family);*/
    $this->db->order_by('img_order', 'desc');
    $query = $this->db->get();

    if ($query->num_rows() > 0):
        return $query->result();
    else:
        $this->session->set_flashdata( 'message', 'The new image query was unsuccessful.' );
    endif;      

}

我正在尝试从成功的主产品函数中获取一些数据,并将其传递到主图像函数中。我想我可以像在模型中一样通过变量传递它,但没有成功。环顾四周后,我发现了一些类似的例子,但也没有成功

主图像
功能中,
$this->db->where('im.pro\u img\u id',$p\u id)应该变成
$this->db->where('im.pro\img\u id',$product\u id)作为
$p_id


此外,我建议您在模型中保留所有数据库交互。控制器应仅将数据从模型传递到视图,或从用户传递到模型

我做了更改,但出现了以下错误“消息:Shop_model::main_images()缺少参数1,在第26行的/application/controllers/mainpro.php中调用,并定义了“参数2和参数3的情况相同”。另外,这是在一个模型中,很抱歉输入错误。错误被抛出到Mainpro控制器中。检查该文件。$this->shop_model->main_images()这一行,它所说的那一行,没有参数,但我认为,因为我在模型中传递参数(根据上面的代码),所以控制器中不需要它?每次调用
main_images
方法时,都需要提供参数,不管你叫它在哪里。