php - how to get name of dynamically generated method in codeigniter -


i have achieved url follows

myapp.com/profile/username1

myapp.com/profile/username2

myapp.com/profile/username3

my routes.php file contains following line of code

$route['profile/(:any)'] = 'profile/user_profile/$profile_method'; 

my profile controller contains code

    public function user_profile($profile_method)     {         echo $profile_method;     } 

all problem want return username process further, method returns parameter name instead of username. please tell me doing wrong ?

just tip have no / after username myapp.com/profile/username/1

try

$route['profile/(:any)'] = 'profile/user_profile/$1'; $route['profile/(:any)/(:num)'] = 'profile/user_profile/$1/$2'; 

instead of

$route['profile/(:any)'] = 'profile/user_profile/$profile_method'; 

http://www.codeigniter.com/user_guide/general/routing.html#examples

then

public function user_profile($profile_method = '', $id = '') {     echo $profile_method . ' <br/> ' . $id; } 

make sure have named controllers , other files correct first letter of class , file name upper case profile.php

you may need have htaccess in main directory remove index.php url also.

https://github.com/wolfgang1983/htaccess_for_codeigniter


from magnus eriksson comment

ci using regular expressions replace dynamic url variable, means $1 = first match, $2 = second match etc. $-part isn't ordinary php-variable, can't name want.



Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -