PyroCMS and CodeIgniter Routing Issue - codeigniter

I'm having a problem with PyroCMS and CodeIgniter URI Routing.
I have a page (majors_list) has a child page (major) , which it has a child page too called (course).
$route['majors_list/major/(:any)'] = 'pages/view/majors_list/major';
$route['majors_list/major/(:any)/course/(:any)'] = 'pages/view/majors_list/major/course';
The first routing, is to view the major page which contains all the courses.
The second routing, conflicts with the first routing, and it is used to view the course information.
When I comment the first routing, the second routing works, but the first stops, and vice versa.
A real example:
majors_list/major/Dentistry/course/dental_material

You need to swap them around. To me it looks like any route that matches the second one will also match the first one, so it never reaches the second one, therefore swapping them will solve the issue.
Alternatively, you could use the regex syntax for routing and place a dollar sign at the end of the regex for the first route to exclude routes that continue after that point.

Related

Redirects to same action from different urls in laravel 5.2

I am using Laravel 5.2.
I am passing parameters via two urls. But it always goes to the first route only.
code in my routes.php is as follows:
Route::get('{department}', 'settings#load_department_settings')->middleware('auth');
Route::get('{id}', 'settings#load_staff')->middleware('auth');
Anchor tags in view is as follows:
<td>{{$staff->name}}</td>
<td>{{$staff->deptname}}</td>
The issue is it always uses 'settings#load_department_settings'. How could i use 'settings#load_staff' when clicking on staff name?
It is always going to use the {department} route because that is matching anything on the root / slash. You need tto dive at least one of them unique prefixes. For example:
Route::get('department/{department}', 'settings#load_department_settings')->middleware('auth');
Route::get('staff/{id}', 'settings#load_staff')->middleware('auth');
Then
<td>{{$staff->name}}</td>
<td>{{$staff->deptname}}</td>

CodeIgniter router for joomla sef urls?

I wish to create a front-end for joomla using CodeIgniter. I prefer to make my own front-end that reads joomla database and I had my own "framework" to accomplish this, this is because I feel that joomla front-end is too heavy for high traffic websites, because it needs to accommodate for so many user needs, at the end you would really only use a small percentage of what joomla has to offer, yet a lot of unneeded core modules load and when you have a website with 300k visits per day, every bit of resource counts. And I like joomla because of its back-end and database structure.
Anyway, I'm looking to standardize a framework for joomla front-end using CodeIgniter instead of my own messy php code, the main issue for me is the ci router. In joomla I set sef url like these:
websitex.com/
websitex.com/category.html
websitex.com/category/subcat/123-alias.html
I'm looking for a router override that would allow me to process those urls. Basically, if any of the params has a number, then its for sure an article. If it doesn't, and its not index.php then its for sure a category or subcategory (if it exists).
And if I write this:
websitex.com/123 [OR]
websitex.com/category/123-alias.html
It would display the article with id 123. At least that's how it works in joomla and its what I'm trying to achieve here.
If anyone could point me in the right direction that would be great. Thanks in advance.
ADDED:
OK #ImranQamer comment left me thinking. What if I try to do it with conventional CI router? So I tried, and came up with this:
$route['default_controller'] = "controller/index";
$route['index'] = "controller/index";
$route[':num'] = "controller/article";
$route['(:any)/:num'] = "controller/article";
$route['(:any)'] = "controller/section";
I think it may work. I've run some tests and so far so good.
First and second line, if nothing is specified OR index.suffix (index.html) is the URI, then it goes to my controller index method.
Third line, if URI is a number (eg: /123.html) then it routes to controller/article.
Fourth line needs more testing, but apparently it will grab any URI that ends with a number (or number + suffix) and route it to controller/article. Still needs another rule to let article's title alias to be put in the URI (eg: /category/123-hello.html)
And last line, will treat the URI as one of the categories/section of the joomla site. In this controller though, I'm going to need to check if submitted URI corresponds to an existing section, in which case it gets displayed, otherwise, redirected to 404.
I'm gonna test this out for a while, but looks good so far.

Codeigniter routes don't work correctly

I have two string in routing config.
$route['education/course/(:any)'] = "education/course/$1";
$route['education/course/(:any)/(:num)'] = "education/lection/$1/$2";
But when I went to /education/course/my_course/1, the first rule worked, but the second didn't.
Please help! I'm newbie in CI.
Routes run in the order they are defined. Your second one will never be applied because the (:any) wildcard is capturing, well, anything.
I believe you should be able to switch the order so the most specific is first, followed by the least specific:
$route['education/course/(:any)/(:num)'] = "education/lection/$1/$2";
$route['education/course/(:any)'] = "education/course/$1";
Since both two routes are similar in the first three segments
education / course / (:any)
And since Route.php runs procedural (line by line),
Requesting a page like /education/course/my_course/1 matches the first route pattern (below)
$route['education/course/(:any)'] = "education/course/$1";
And also, requesting a page like /education/course/my_course/1/23 will still matches the first route pattrn, because Route.php only cares if your requested URL link matched the specified route pattern or not, otherwise go check the next route.
So, switching the order of the routes will fix the problem.

How can I shorten routes in Codeigniter for certain requests?

I have a page that has this category URL website.com/category/view/honda-red-car and I just want it to say http://website.com/honda-red-car no html or php and get rid of the category view in the URL.. this website has been done using the CodeIgniter framework..
also this product view URL website.com/product/details/13/honda-accord-red-car
and I want it to be website.com/honda-accord-red-car PLEASE HELP!!!
I cannot find correct instructions on what I am doing wrong??
In Routes.php you need to create one like so
$route['mycar'] = "controller_name/function_name";
So for your example it would be:
$route['honda-red-car] = "category/view/honda-red-car";
Take a look into the URI Routing part of the user guide.
If you have concrete set of urls that you want to route then by adding rules to the application/config/routes.php you should be able to achieve what you want.
If you want some general solution (any uri segment can be a product/details page) then you might need to add every other url explicitly to the routes.php config file and set up a catch-all rule to route everything else to the right controller/method. Remember to handle 404 urls too!
Examples:
Lets say the /honda-red-car is something special and you want only this one to be redirected internally you write:
$routes['honda-red-car'] = 'product/details/13/honda-accord-red-car';
If you want to generalize everything that starts with the honda- string you do:
$routes['(honda-.*)'] = 'product/details_by_slug/$1'; // imaginary endpoint
These rules are used inside a preg_replace() call passing in the key as the pattern, and the value as the replace string, so the () are for capture groups, $1 for placing the capture part.
Be careful with the patterns, if they are too general they might catch every request coming in, so:
$routes['(.*)'] = 'product/details_by_slug/$1';
While it would certainly work for any car name like suzuki-swift-car too it would catch the ordinary root url, or the product/details/42 request too.
These rules are evaulated top to bottom, so start with specific rules at the top and leave general rules at the end of the file.

Route all actions of a controller except one in codeigniter

I am doing a project in CodeIgniter and I want to route all the urls of a particular controller to a specific action except one. For e.g.,
I want the url
myurl/mycontroller/myaction
to be handled by the action myaction but any other urls like
myurl/mycontroller/myaction1
myurl/mycontroller/myaction2
myurl/mycontroller/myaction3
to be handled by action abc of a particular controller. I had searched across the internet and what I get is how to handle all urls by a certain controller except some. The way to do it is
$route['^(?!admin|user|setup|pages).*'] = "user/view/$0";
Here all urls will be handled by user/view except those whose 2'nd part of the url is admin, user, setup or pages.
I think routes are applied in order, so how about adding a route for the "myaction" first before the other ones?
$route['myurl/mycontroller/myaction'] = "myurl/mycontroller/myaction";
$route['myurl/mycontroller/abc'] = "myurl/mycontroller/$1";
I believe this is the correct syntax
$route['myurl/mycontroler/myaction(:any)'] = "myurl/controller_a/action";
You can verify it here
EDIT
I read your comment and I made an adjustment. Give it a go and see if it fits.
EDIT 2
Well since you just want the exact word myaction unharmed then either use (:any) or (\d+) after the word so the rerouteing happens when a number is attached to the myaction word. I haven't actually tested it yet.

Resources