Welcome Guest, Not a member yet? Register   Sign In
still don't understand routing perfectly
#1

[eluser]SPeed_FANat1c[/eluser]
Hi,

so I want to make freindly urls for pages that are created dynamiclaly by admin.

Such as www.domain.com/about, www.domain.com/contacts and so on.

What can I do is make it something like this:

Code:
$route['default_controller'] = "home";
$route['scaffolding_trigger'] = "";

$route['admin'] = "admin";
$route['admin_/naujienos'] = "admin_/naujienos";
$route['atsiliepimai'] = "atsiliepimai";

$route['(:any)'] = "home/info/5";

so the (:any) remaps to home/info/5 5 is for example, it will actually be some word like "contact" or "about".

But the problem is that I have to write reroutings before (:any) for EVERY controler and function.

How can I do this so I would not need to write every controller and function.

For example
$route['admin_/naujienos'] = "admin_/naujienos";

opens controler naujienos index page. (admin_ is a folder name). But - it does not open

admin_/naujienos/redaguoti

I have to make the other line in $routes.php

$route['admin_/naujienos/redaguoti'] = "admin_/naujienos/redaguoti";

for it to work.

I want it make work for anything that is in folder "admin_". How to do that not writing string for ecery controller and its function? Something like

$route['admin_'] = "anything in the admin_ folder?"
#2

[eluser]davzie[/eluser]
I was about to ask the same question. I wanted CodeIgniter to figure out if no controllers are found then to default to a specific rule.

So if I did

domain.com/admin

That would goto my admin controller, if I went
domain.com/page_name

It would see there isn't a controller called page_name and thus reroute me to the page controller.
#3

[eluser]John_Betong[/eluser]
Try double quotes with a $1:

Code:
// $route['(:any)'] = "home/info/5";
   $route["(:any)"] = "home/info/5/$1";
#4

[eluser]WanWizard[/eluser]
Note that :any matches a single segment, not "anything in the URI". If you really need a "match anything" rule, use "(.*)" instead. Remember, you can use any valid regex to match a route.
#5

[eluser]davzie[/eluser]
I see! So is it possible to do something like

domain.com/page_name

if page_name is not equal to 'admin' or 'auth' then goto page/index/$1

That's what I'm getting at here.

Otherwise I want to cry :'(
#6

[eluser]CroNiX[/eluser]
Quote:if page_name is not equal to ‘admin’ or ‘auth’ then goto page/index/$1
For what you are asking, you could:
$route['((?!admin|auth).*)'] = "page/index/$1";
#7

[eluser]SPeed_FANat1c[/eluser]
Thank you guys for good information, I was thinking a lot a counld not myself find a way to make the code cleaner. At my first project the routing looked like this:
Code:
$route['default_controller'] = "welcome";
$route['scaffolding_trigger'] = "";

$route['login']= "login";
$route['login/(:any)'] = "login/$1";
$route['welcome'] = "welcome";
$route['welcome/show_cities/:any'] = "welcome/show_cities";
$route['welcome/(:any)'] = "welcome/$1";
//$route['welcome/index/:any'] = "welcome/index/$1";
//$route['welcome/:any'] = "welcome/index/$1";
$route['admin'] = "admin";
$route['admin/(:any)'] = "admin/$1";
$route['admin_/reklama/(:any)'] = "admin_/reklama/$1";
$route['admin_/(:any)'] = "admin_/$1";
$route['vartotojas'] = "vartotojas";
$route['vartotojas/(:any)'] = "vartotojas/$1";
$route['registracija'] = "registracija";
$route['registracija/(:any)'] = "registracija/$1";

$route['details/(:any)'] = "details/$1";
$route['pagalba/(:any)'] = "pagalba/$1";
$route['cities/(:any)'] = "cities/$1";
$route['ratings/(:any)'] = "ratings/$1";
$route['info/(:any)'] = "info/index/$1";

$route['test/(:any)'] = "test/$1";


//jei nenueina ne vienu is siu keliu, tada reikia miesta, pvz. plotai.eu/vilnius - bus rodomi vilniaus objektai
$route['(:any)/(:num)'] = "welcome/index/$1/$2";
$route['(:any)'] = "welcome/index/$1";

so I hated it, because you can easily forget something, make mistake.

Now this

[quote author="CroNiX" date="1297989910"]
Quote:if page_name is not equal to ‘admin’ or ‘auth’ then goto page/index/$1
For what you are asking, you could:
$route['((?!admin|auth).*)'] = "page/index/$1";[/quote]

helped a lot, at least it looks it helped, for now. I will finish with all controllers and see. So basically I guess I will need only one line of code to make user firendly urls now.

Edit: there should be some tutorial about rerouting, for beginners it would be very usefull, in documentation there is too little examples. Or maybe there is somewhere a tutorial, I just didn't find good one.

Edit2: so I completed and everything works perfectly now Smile My routing is so simple now

Code:
$route['default_controller'] = "home";
$route['scaffolding_trigger'] = "";

$route['darbuotojai'] = "home/darbuotojai";
$route['((?!admin|admin_|atsiliepimai|grupes|home|test).*)'] = "home/info/$1";

Thanks again, this was very usefull information Smile
#8

[eluser]SPeed_FANat1c[/eluser]
Today I found a litle problem with this solution
Code:
$route['default_controller'] = "home";
$route['scaffolding_trigger'] = "";

$route['darbuotojai'] = "home/darbuotojai";
$route['((?!admin|admin_|atsiliepimai|grupes|home|test).*)'] = "home/info/$1";

the adress cannot be like this: www.domain.com/home1

it is because there is word "home" in regular expression. So it means that those words means the beggining of the word, not the exact word. It is not very likely that information page will begin with the same word as contrller or folder, but it is still possible, who knows what the admin can do. So the question is - how to make it match the exact word, not the beginning of the word?

Edit: what a stupid I am Big Grin it maches beginning + anything because there is .* at the end. So don't even know. On thing I can think if is put controller is such folder which name 100 % admin will not use for information pages. But it should exist better solution.

Eidt: another solution maybe would be ok - if admin creates the information pagel liek "home1" then it should add some character befor this word, so the "home" would not be matched. But probably it is litte to now chace that he will ever use these words I guess. I just want to make it perfect, but of course knowledge would be more valuable thing, for other projects.




Theme © iAndrew 2016 - Forum software by © MyBB