2013-10-29 4 views
-1

codeigniter의 카트 시스템에 이미지를 표시하고 싶습니다. 하지만 그렇게하지 못했습니다. 나는 codeigniter에서 새롭다. 그래서 너 한테 도움이 필요해. 여기 CodeIgniter에서 장바구니 시스템에 이미지를 표시하는 방법은 무엇입니까?

내 컨트롤러 :::입니다

class Cart extends CI_Controller { 

public function add_to_cart($product_id) { // adds a product to cart 
    $this->load->model('cart_model'); 
    $result = $this->cart_model->selectProductByProductId($product_id); 

    $insert = array(
     'id' => $product_id, 
     'qty' => 1, 
     'price' => $result->product_price, 
     'name' => $result->product_name, 
    'image' => $result->product_image 
    ); 
    //$this->load->library('Cart'); 
    $this->cart->insert($insert); 
    redirect("cart/show_cart"); 
} 

보기 :::

<?php echo $items['image'] ?> 

이 .. 카트보기 페이지에서 작동하지 않습니다 어쩌면 내가 카트 라이브러리 몇 가지 변화가 필요하지만, 내가 할 내가 편집하거나 업데이트하는 위치를 모릅니다. 제발 도와주세요.

답변

1

class Cart extends CI_Controller { 

public function add_to_cart($product_id) { // adds a product to cart 
    $this->load->model('cart_model'); 
    $result = $this->cart_model->selectProductByProductId($product_id); 

    $insert = array(
     'id' => $product_id, 
     'qty' => 1, 
     'price' => $result->product_price, 
     'name' => $result->product_name, 
    'image' => $result->product_image 
    ); 
    //$this->load->library('Cart'); 
    $this->cart->insert($insert); 
    $data['image'] = $result->product_image; 
    $this->load->view("cart/show_cart",$data); 
} 

을 시도하고 당신의보기 페이지에 VIEW_NAME 단지

echo $image; //gives the path of the image 

참고 :

당신이 세션에서 가게를 코드에서 이미지 경로를 재 사용하려면

+0

작동 중입니다 –

+0

이 이미지를 사용자의 전자 메일로 보내는 방법을 알려 주겠습니까? –

+0

제발 받아 들여 보내주세요. 이 이미지를 사용자의 이메일로 보내시겠습니까? –

0

리디렉션 방법을 사용하는 대신 장바구니/show_cart를 (를) 사용자가 볼 수있게되기를 바랍니다. $ this-> load-> view ('view_name', $ items)를 사용하십시오; 여기 show_cart 당신이보기에

체크 대한 추가 정보를 원하시면이 링크를 표시하고자하는 데이터를 전달 ... http://ellislab.com/codeigniter/user-guide/general/views.html

+0

정말 고마워요. –

0
$insert = array(
    'id' => $product_id, 
    'qty' => 1, 
    'price' => $result->product_price, 
    'name' => $result->product_name, 
'img' => $result->product_image 
); 

$ this-> cart-> 삽입 ($ 삽입);

+1

함께 작은 * 해설 * 코드가 무엇을하는지 설명하십시오. – Jack

관련 문제