route_to not working with controller::method - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28) +--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forumdisplay.php?fid=30) +--- Thread: route_to not working with controller::method (/showthread.php?tid=75683) |
route_to not working with controller::method - eafarooqi - 03-05-2020 hi why route_to method doesn't work with the controller::method when setAutoRoute is set to true and there is no route defined in the Routes.php <?php echo route_to('App\Controllers\Home::TestFunction')?> <?php echo route_to('Home::TestFunction')?> Doesn't work. Is this not supported? do i have to define the Route in Routes.php to use route_to function. It would be a nice feature to have another function if not route_to which auto detect the Controller and functions without any route in Routes.php. This works <?php echo site_url('home/TestFunction'); ?> RE: route_to not working with controller::method - InsiteFX - 03-05-2020 You need to setup the route correct: Example: PHP Code: $routes->get('admin', 'Admin::index', ['as' => 'admin']); See the as => admin then you can add. PHP Code: route_to('admin'); In your html view file. route_to needs a defined route in the Routes.php file to work. RE: route_to not working with controller::method - eafarooqi - 03-05-2020 yes i know. but i want to use the AutoRoute feature with route_to or may be with another function, without defining any routes in Routes.php file, because there are too many routes in the application. like: <?php echo route_to('App\Controllers\Home::TestFunction')?> May be i will extend or create a helper function to do it. RE: route_to not working with controller::method - InsiteFX - 03-05-2020 From what I read in the User's Guide I believe you need to set your route in the html file like this. PHP Code: <?= base_url('Controller/Method'); ?> Then the auto routing will try to match it against the controller and method. |