• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
how to get string before the second slash as a parameter??

I'm working on a project ...

I want to have my institutions and get the string before second slash as a institution username

for example:

in this path:


I want to get the institution1 as a parameter to detect this institution and show this it's page and informations.

so I want to write my controller between second slash and third slash

and between third slash and fourth slash I want to write my method and parameter comes after them...

what do I do??

I guess should user the htaccess, but don't know how to do!

Look at the URI library: https://www.codeigniter.com/user_guide/l...s/uri.html

This should do what you want:

PHP Code:
$segment $this->uri->segment(1); 

Look at the URI class. It has what you need, specifically the segment method.

Thank you my friends , But I think this way not work!


I know how to get url and it's segments by this class(URI)!

But I don't know how to change url analysing in codeigniter. In another words I want to codeiginter get first parameter as a $_GET parameter and second parameter as a controller and third parameter as a method and next parameter as another parameters.

Like this example:

http://hamresan.ir/intstitution1/search/add/ ... (and others as parameters)
"institution1" as a parameter like center (center=institution1)
"search" as a controller
and "add" as a method

But by default setting of codeigniter I have to get like this, but I don't want:


"institution1" as a controller
"search" as a method
and "add" as a parameter

But I don't want this Sad

please help me..

You could use a routing rule, eg something like $route['(:any)/(:any)/(:any)'] = '$2/$1/$3';
See https://www.codeigniter.com/user_guide/g...uting.html

(04-19-2018, 01:42 AM)ciadmin Wrote: You could use a routing rule, eg something like $route['(:any)/(:any)/(:any)'] = '$2/$1/$3';
See https://www.codeigniter.com/user_guide/g...uting.html

hi my friend

I tried to do what you say , but I couldn't to do that...

and I user this code in route.php :

$route['([a-zA-Z]+)'] = '?center=$1';


$route['([a-zA-Z]+)'] = 'index.php/?center=$1';

can you help me?

$route['(:any)'] = 'login/index/?center=$1';

it's works but don't get the center as a $_GET parameter

altough absolute address work and get the center as a $_GET parameter!:


the get center=myinstitution

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.