Welcome Guest, Not a member yet? Register   Sign In
route_to not working with controller::method
#1

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'); ?>
Reply
#2

(This post was last modified: 03-05-2020, 07:22 AM by InsiteFX.)

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.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#3

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.
Reply
#4

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.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply




Theme © iAndrew 2016 - Forum software by © MyBB