1

I have a link to a modal

echo anchor('welcome/test/?$userid', 'Full View', 'class="ajax"');

and when my modal opens i retrieve it

$id= $_GET;

reason being is that when you click the "full View" link the modal opens and display different content fetched from my database depending on the id. Codeigniter will not let me pass $userid since $ is a forbidden character. Is there anyway to get round this obstacle without enabling $ in

$config['permitted_uri_chars'] = 'a-z 0-9~%.:_\-';

adding $ in the config would open up my application to sql injections right?

So basicly what I wish to achieve is to pass the ID from my view my modal window (that allso is a view)

darrrrUC
  • 311
  • 2
  • 15

2 Answers2

2

Add the route to the routes.php config file

    $route['welcome/test/(:num)'] = "{your_controller}/{your_function}/$1";

And this will allow you to have the link just as

welcome/test/$user_id 

and it will call your function with $user_id as the argument. Make sure to specify the parameter in the function signature.

Note: don't put '$' in the URL, replace $user_id with the actual id number. I really recommend reading the CI documentation on routing, you really need to have a good understanding of it to use CI properly. http://ellislab.com/codeigniter/user-guide/general/routing.html

xd6_
  • 483
  • 4
  • 9
  • Hi thanks, but if I create a new item it will have a new id, I cannot hardcode them all, or did I missundertand you when you said : Note: don't put '$' in the URL, replace $user_id with the actual id number – darrrrUC Apr 15 '14 at 13:49
  • You're trying to call 'welcome/test/?user$id', so I assume there is supposed to be a value in $userid when you try to make that link. In order to pass the actual value (the user id) you should be using double quotes, which will replace $userid with it's actual value. "welcome/test/$userid" . This will pass whatever the id actually is to the welcome controller's test function, which should look like function test($userid){...} – xd6_ Apr 15 '14 at 13:52
  • You sir, are a hero! Thanks alot! – darrrrUC Apr 15 '14 at 14:00
0

Try this:

echo anchor('test/anchor/?userid='. $user_id, 'Full View', 'class="ajax"');
Mykola
  • 123
  • 1
  • 7