• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Is there a way to route an entire controller?

#1
Is there a way to route an entire controller, so I can route a controller to be / (root directory)?

Let's say my controller looks like this.



Code:
<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Main extends MY_Controller {

    public function debate($nodeviewid){

    }

    public function question($nodeviewid){

   }
}


By doing this (setting a route for my controller), all actions in my specific controller I set the controller's route in, (such as "debate") inherit this route so action debate has the /debate url and action question has the /question url.

It would be more convenient to map or route an entire controller and all actions in that controller by default become a subroute of it, than setting each route for each of my controller actions individually.
Reply

#2
Rewrite in .htaccess:

RewriteRule ^debate$ /main/debate [L]

Or just use CI routing.
Reply

#3
(08-01-2017, 10:46 AM)skunkbad Wrote: Rewrite in .htaccess:

RewriteRule ^debate$ /main/debate [L]

Or just use CI routing.

Yes but I want to route the entire controller, not each method individually. How do I do that?
Reply

#4
(08-07-2017, 01:29 PM)desbest Wrote:
(08-01-2017, 10:46 AM)skunkbad Wrote: Rewrite in .htaccess:

RewriteRule ^debate$ /main/debate [L]

Or just use CI routing.

Yes but I want to route the entire controller, not each method individually. How do I do that?

It's not possible. You may be able to come up with a RewriteRule or CI routing that uses a regular expression, but there is no magic way to do what you want to do. A CI route like this might work:

PHP Code:
$route['(debate|question)'] = 'main/$1'
Reply

#5
A Kludge I use is to route any unfound URIs to a search routine.

A search of an exact match for a table url_title() matching the URL or a nearest match or the table unique record number calls the relevant matching table record.

If the above fails the standard 404 is called.
download and make your system directory strict
Reply

#6
I am going to request this feature in the next version of Codeigniter.
Reply

#7
(08-08-2017, 12:34 AM)desbest Wrote: I am going to request this feature in the next version of Codeigniter.

What do you think about Routes in a Controller Comments
Reply

#8
(08-10-2017, 08:47 AM)jonathanq Wrote:
(08-08-2017, 12:34 AM)desbest Wrote: I am going to request this feature in the next version of Codeigniter.

What do you think about Routes in a Controller Comments

I don't think that is helpful.
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


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