Welcome Guest, Not a member yet? Register   Sign In
Modular Extension - passing data from view to controller via form
#1

[eluser]ice_prince7[/eluser]
[EDIT - sorry for double posting. it should be here : http://ellislab.com/forums/viewthread/73177/P690/ ]

Hi all,

sorry to bother you with this might-be-something-obvious problem

Im trying out Modular extension by wiredesignz.

I got stumble when i want to pass data via form_open.

it seems that it doesnt go to my immediate controller, but rather to index.php/product/add_to_cart.

This is my hierachy
Quote:application/
modules/
product/
controllers/product.php
views/product_list.php

This is my controller
Code:
<?php

class Product extends Controller {

    function __construct()
    {
        parent::Controller();
    }
    
    function product_list()
    {  
        #get products
        $get_product = $this->db->get('product');
        $data['product'] = 'empty';
        if($get_product->num_rows()>0){
        
            $data['product']=$get_product->result();  
            
        }
        
        $this->load->view('product_list',$data);
    }
    
    function add_to_cart(){
        echo 'asdsadas';
        print_r($this->input->post('product'));
        
        
    }
}

/* End of file product.php */
/* Location: ./application/modules/product/controllers/product.php */

This is my view :
Code:
<div id="cart">
    <h1>Product List</h1>
    <div id="content">
        &lt;?php if($product=='empty'){
            
            ?&gt;<div>There is no product yet</div>&lt;?php
            
            
        }else{
            
            ?&gt;
            <table>
                <tr>
                    <td>Item</td>
                    <td>Quantity</td>
                    <td>Price</td>
                    <td>&nbsp;</td>
                
                </tr>
            
            &lt;?php
            
            foreach($product as $item){
                $len =20;
                ?&gt;
                      
                <tr>
                    <td>&lt;?php if(strlen($item->productName)>=$len){echo substr($item->productName,0,$len).'...';}else{echo $item->productName;}; ?&gt;</td>
                    <td>&lt;?php echo $item->quantity; ?&gt;</td>
                    <td>Price</td>
                    <td>
                        &lt;?php echo form_open('product/add_to_cart');?&gt;// here is where im passing my data
                        &lt;input type="submit" name="product[&lt;?php echo $item-&gt;productId; ?&gt;]" value="Add to Cart" />
                        &lt;?php echo form_close();?&gt;
                    </td>
                
                </tr>
                &lt;?php
            }
        ?&gt;</table>&lt;?php    
        }?&gt;
    </div>
</div>

Any ideas on how do i get the data from view to controllers/product/add_to_cart ?
sorry for posting any noob question.

thankx


Messages In This Thread
Modular Extension - passing data from view to controller via form - by El Forum - 03-09-2010, 10:18 PM



Theme © iAndrew 2016 - Forum software by © MyBB