CodeIgniter Forums
URI Routing Help - 23.07.19 - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forum-5.html)
+--- Forum: Model-View-Controller (https://forum.codeigniter.com/forum-10.html)
+--- Thread: URI Routing Help - 23.07.19 (/thread-74106.html)



URI Routing Help - 23.07.19 - Porto - 07-23-2019

Hi Guys greetings!

$route['mf'] = 'voting/mf';

/***Route Formteste Works***/
$route['formteste'] = 'formteste/index';

/***Route Voting Dashboard Works***/
$route['admin_voting'] = 'admin_voting/index';

/***Route default_controller Works***/
$route['default_controller'] = 'voting/index';

/***Route Works***/
$route['(:any)'] = 'voting/index/$1';

// $route['default_controller'] = 'welcome';
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;

Above are the routes.

In four cases the routes are working very normal with the name of the controller - slash - index = controller/index.

Here i need to write the controller name and the method name.
$route['mf'] = 'voting/mf';              voting  = controller method = mf
In this case in special it doesn't work when i try to use voting/index. Why?

Does someone has some idea what is going on or what is missing please?

Before someone to send me to read the documentation, i've already read it, but i didn't find a clear help, that's why i'm here.

https://www.codeigniter.com/user_guide/general/routing.html?highlight=route#uri-routing


Thank you very much in advance


RE: URI Routing Help - 23.07.19 - Digital_Wolf - 07-23-2019

I'm not exactly sure what you want to do, but maybe it will help:

Example 1:
$route['{segment-1} / {segment-2} / {segment-3}']
will be converted to:
https://example.com/segment-1/segment-2/segment-3/

Example 2:
$route['auth/welcome/( : segment)'] = "authentication/index/$1";
The value "segment" can be passed to the method "index" of the class "authentication".
* Example: https://example.com/auth/welcome/Jack
  displays: Welcome, Jack !

Example 3:
$route['photos/( : segment)/( :any)'] = "photos/catalogs_$1/id_$2";
The value "#segment" can be passed to the "#catalogs_&1" method of the "#photo" class, after which this value becomes the " #catalogs_***" method, and the value from "#:any" is passed to the ready method "#catalogs_****".
* Example: https://example.com/photos/cats/1
  Displays photos whose ID=1, from catalogue under the name cats...

P.S. If somewhere is wrong please correct me, I may be confused with CI4.


RE: URI Routing Help - 23.07.19 - Porto - 07-23-2019

(07-23-2019, 03:03 AM)Digital_Wolf Wrote: I'm not exactly sure what you want to do, but maybe it will help:

Example 1:
$route['{segment-1} / {segment-2} / {segment-3}']
will be converted to:
https://example.com/segment-1/segment-2/segment-3/

Example 2:
$route['auth/welcome/( : segment)'] = "authentication/index/$1";
The value "segment" can be passed to the method "index" of the class "authentication".
* Example: https://example.com/auth/welcome/Jack
  displays: Welcome, Jack !

Example 3:
$route['photos/( : segment)/( :any)'] = "photos/catalogs_$1/id_$2";
The value "#segment" can be passed to the "#catalogs_&1" method of the "#photo" class, after which this value becomes the " #catalogs_***" method, and the value from "#:any" is passed to the ready method "#catalogs_****".
* Example: https://example.com/photos/cats/1
  Displays photos whose ID=1, from catalogue under the name cats...

P.S. If somewhere is wrong please correct me, I may be confused with CI4.

Sorry Guys,

i wrote a mistake.

$route['mf'] = 'mf/index';

This line above does not work! here we have the method (mf) and the index page of the method where should appear the "Form Page".

When i try to access this page, http://localhost/poll/mf  i see 404 Page Not Found


RE: URI Routing Help - 23.07.19 - Wouter60 - 07-23-2019

PHP Code:
$route['mf'] = 'mf/index'

This route makes no sense. It says: if the url is http://yourwebsite/mf, then point to the index method inside the mf controller.
This is default behaviour if the url has only one segment (controller), so you don't need an extra route for that.
Just make sure the mf controller has an index method.


RE: URI Routing Help - 23.07.19 - Digital_Wolf - 07-23-2019

(07-23-2019, 05:44 AM)Porto Wrote:
(07-23-2019, 03:03 AM)Digital_Wolf Wrote: I'm not exactly sure what you want to do, but maybe it will help:

Example 1:
$route['{segment-1} / {segment-2} / {segment-3}']
will be converted to:
https://example.com/segment-1/segment-2/segment-3/

Example 2:
$route['auth/welcome/( : segment)'] = "authentication/index/$1";
The value "segment" can be passed to the method "index" of the class "authentication".
* Example: https://example.com/auth/welcome/Jack
  displays: Welcome, Jack !

Example 3:
$route['photos/( : segment)/( :any)'] = "photos/catalogs_$1/id_$2";
The value "#segment" can be passed to the "#catalogs_&1" method of the "#photo" class, after which this value becomes the " #catalogs_***" method, and the value from "#:any" is passed to the ready method "#catalogs_****".
* Example: https://example.com/photos/cats/1
  Displays photos whose ID=1, from catalogue under the name cats...

P.S. If somewhere is wrong please correct me, I may be confused with CI4.

Sorry Guys,

i wrote a mistake.

$route['mf'] = 'mf/index';

This line above does not work! here we have the method (mf) and the index page of the method where should appear the "Form Page".

When i try to access this page, http://localhost/poll/mf  i see 404 Page Not Found

You say that you want to go to the url with segments "poll/mf", and then write in routs the following
$route["mf"] = "mf/index";
this is not the right way...

So you can type in the address bar of your browser https:://example.com/poll/mf
you need to change the route to the following:
$route["poll/mf"] = "mf";
and then you will have a controller with the class "mf" and its method "index()"


RE: URI Routing Help - 23.07.19 - InsiteFX - 07-23-2019

The index method in a controller is always called as a default.

So you only need the controller name when calling an index method.


RE: URI Routing Help - 23.07.19 - Done! - Porto - 07-24-2019

(07-23-2019, 09:04 AM)Digital_Wolf Wrote:
(07-23-2019, 05:44 AM)Porto Wrote:
(07-23-2019, 03:03 AM)Digital_Wolf Wrote: I'm not exactly sure what you want to do, but maybe it will help:

Example 1:
$route['{segment-1} / {segment-2} / {segment-3}']
will be converted to:
https://example.com/segment-1/segment-2/segment-3/

Example 2:
$route['auth/welcome/( : segment)'] = "authentication/index/$1";
The value "segment" can be passed to the method "index" of the class "authentication".
* Example: https://example.com/auth/welcome/Jack
  displays: Welcome, Jack !

Example 3:
$route['photos/( : segment)/( :any)'] = "photos/catalogs_$1/id_$2";
The value "#segment" can be passed to the "#catalogs_&1" method of the "#photo" class, after which this value becomes the " #catalogs_***" method, and the value from "#:any" is passed to the ready method "#catalogs_****".
* Example: https://example.com/photos/cats/1
  Displays photos whose ID=1, from catalogue under the name cats...

P.S. If somewhere is wrong please correct me, I may be confused with CI4.

Sorry Guys,

i wrote a mistake.

$route['mf'] = 'mf/index';

This line above does not work! here we have the method (mf) and the index page of the method where should appear the "Form Page".

When i try to access this page, http://localhost/poll/mf  i see 404 Page Not Found

You say that you want to go to the url with segments "poll/mf", and then write in routs the following
$route["mf"] = "mf/index";
this is not the right way...

So you can type in the address bar of your browser https:://example.com/poll/mf
you need to change the route to the following:
$route["poll/mf"] = "mf";
and then you will have a controller with the class "mf" and its method "index()"

Thank you so much Digital. i got you point!