Welcome Guest, Not a member yet? Register   Sign In
how to get string before the second slash as a parameter??
#1

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:

http://married.org/institution1/class/method/

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!
Reply
#2

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); 
Reply
#3

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

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

Because...

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:

http://hamresan.ir/intstitution1/search/add/

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

But I don't want this Sad

please help me..
Reply
#5

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
Reply
#6

(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';

and

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

can you help me?
Reply
#7

(This post was last modified: 04-19-2018, 11:39 AM by imalegend.)

$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!:

http://localhost/hamresan/login/index/?c...nstitution

the get center=myinstitution
Reply




Theme © iAndrew 2016 - Forum software by © MyBB