Welcome Guest, Not a member yet? Register   Sign In
How to pass arrays to a controller?
#1

[eluser]Shiju S S[/eluser]
I tried to pass the array data to contoller loadprddetails;

This code is from a view file.

Code:
<div>
&lt;?php
for($i=1;$i<=10;$i++)
{
$data = array(
          'prdid'  => 'India',
          'exeid'    => 'United Arab Emirates',
          
    );
?&gt;



<div>
<p>
<a href="&lt;?Php echo base_url() ?&gt;frontpage/loadprddetails/&lt;?Php echo $data ?&gt;"><img src="&lt;?Php echo base_url() ?&gt;images/logo.jpg" align="left" /></a>
</p>
&lt;?Php echo "quickbharat.com"; ?&gt; <br />

&lt;?Php echo "category"; ?&gt;
  
</div>
  &lt;?Php } ?&gt;

The route is
Code:
$route['frontpage/loadprddetails/(:any)'] = "frontpage/loadprddetails/$1";

The controller is
Code:
public function loadprddetails($prd)
{
  
  $data['message'] = "Product id is".$prd['prdid']."Userid is ".$prd['exeid'];
  $this->load->view('frontarea/header', $data);
  $this->load->view('frontarea/success_messages', $data);
  $this->load->view('frontarea/footer', $data);
}

As you know the output is just A
The first letter of Array

Que1:
Is it possible to pass an array to the controller. If so please help me

Que2:
How can I pass multiple values back to the controller
#2

[eluser]Aken[/eluser]
If you're expecting PHP code to go through a URL, you really should be learning more about PHP in general before you use CodeIgniter.
#3

[eluser]Shiju S S[/eluser]
Thanks I got it done with this information.

You cannot pass an array through a url in it's raw form. You have to
serialize it, encode it, then on the receiving page you unencode it, and
finally unserialize it.

Example:
Code:
&lt;?
$test = array(1,2,3,4);
$serialized = rawurlencode(serialize($test));
echo "<a testvar=".$test.">Test</a>";
?&gt;
then in recieve_array.php:
Code:
&lt;?
$testvar = unserialize(rawurldecode($_GET['testvar']));
echo "<pre>";
print_r($testvar);
echo "</pre>";
?&gt;

- Patrick.




Theme © iAndrew 2016 - Forum software by © MyBB