Welcome Guest, Not a member yet? Register   Sign In
How can I pass a variable with anchor()
#1

[eluser]Hasan Iqbal[/eluser]
Hi guys!

I'm a newbie in codeigniter.
I'm trying to pass an information through anchor() function.

Here, I want to attach a variable 'id' that relates to that description and pass it to a controller named 'test'. In that controller I want to retrieve the variable from the URI and do something.
But where can i attach it?

echo anchor('test',$value->description,'');
#2

[eluser]John_Betong_002[/eluser]
Try this:

Code:
echo anchor(‘test/index/id’,$value->description,’‘);

  // Test controller
  // to retrieve the id value
  function index()
  {
    http://ellislab.com/codeigniter/user-guide/libraries/uri.html
    echo $this->uri->segment(2);
    die;
  }
 
 
#3

[eluser]Naga Gotama Adhiwijaya[/eluser]
use this in your view
Code:
echo anchor("test/some_method/".$value->id, $value->description);



and you can get your variable in your "test" controller with this way:
Code:
function some_method($id)
  {
    echo $id;
  }
#4

[eluser]Hasan Iqbal[/eluser]
thnx.. guys.. it's done.. Smile




Theme © iAndrew 2016 - Forum software by © MyBB