Creating dynamic functions based on values from database |
[eluser]Unknown[/eluser]
Hi I was wondering is it possible to generate dynamic functions within controller named after values obtained from URL (which is originally from a database)? For example: Code: http://www.something.com/index.php/value1/value2/ obviously the 'value1' segment is a function on its own and I was wondering if it is possible to generate the 'value2' dynamically at all? Many thanks.
[eluser]Pascal Kriete[/eluser]
I'm not sure I understand this correctly. You want segment 2 to be dynamic? Or you want segment 2 to define a new function? The latter isn't possible in php. Option 1: Routing (docs) Code: $route = array( Code: class Value1 extends Controller { Let me know if that answered your question at all . And welcome to CodeIgniter.
[eluser]Unknown[/eluser]
Many thanks inparo for your reply. So its impossible to define new functions, that answered my question.
[eluser]marcoss[/eluser]
[quote author="modena" date="1223264074"]Many thanks inparo for your reply. So its impossible to define new functions, that answered my question. [/quote] You can still use the _remap function to do something like this http://site.com/username. Code: <?php
[eluser]Aken[/eluser]
You can use regular expressions in your Routes config file to basically create any URL you want, and have them access whichever controller or function you want. You can then check their validity inside the appropriate function.
[eluser]xwero[/eluser]
In php5 you can create functions with __call but i don't see how it would be useful in your case as you already call a function.
|
Welcome Guest, Not a member yet? Register Sign In |