CodeIgniter routing issue, advice how to do it -


I'm not a CI programmer, just trying to figure it out. Perhaps this is a wrong approach, please advise.

My Controllers (not in subdirectory):

  Extend class user CI_Controller {function __construct () {parent :: __ construct (); } Public Function Index ($ msg = NULL) {$ this- & gt; Load-> Assistant (array ('form')); $ Data ['msg'] = $ msg; $ This- & gt; Load-> View ('Users / Login', $ data); } Public function process_logout () {$ this- & gt; Session-> Sess_destroy (); Redirect (base_url ()); }}   

and one way to login:

  $ route ['user / login'] = 'user / index';   

The problem occurs when I want to logout, it shows me 404 because I do not have this in my way:

  $ route [ 'User / process_logout'] = 'user / process_logout';   

And in my opinion, I & lt; A href = "users / process_logout" & gt; Logout & lt; / A & gt;

When I add, it works, and it is stupid to add a path to everything, please do advise, please advise, please.

Thank you

Do not know why you have the login facility in the index () function While trying to implement, since you said that you are learning CI, I am saying something about the _remap () function.

Before that you can try the following routing:

  $ route ['user /: any'] = 'user / $ 1'; $ Route ['user / login'] = 'user / index';   

If you want to take the value immediately after the controller section, then you need to use the _remap () function and this function can solve your routing problem, I mean You do not have to set up routing. Applying your code controller 'User' by using the _remap () function.

  Class users extend the CI_Controller {Private $ classes = array ('login', 'logout'). ; Function __ composition () {origin: __ creation (); } Public Function _remap ($ method) {$ section = $ this- & gt; Uri-> Segment (2); If (in_array ($ section, $ this- & gt; section)) call_user_func_array (array ($ this, '_'. Section), array ()); Else show_404 (); // Showing 404 error} Private function _ login () {$ msg = $ this- & gt; Uri-> Segment (3); $ This- & gt; Load-> Assistant (array ('form')); $ Data ['msg'] = $ msg; $ This- & gt; Load-> View ('Users / Login', $ data); } Public function _logout () {$ this- & gt; Session-> Sess_destroy (); Redirect (base_url ()); }}    

Comments

Popular posts from this blog

excel vba - How to delete Solver(SOLVER.XLAM) code -

c# - Add Image in a stackpanel based on textbox input -

java - Reaching JTextField in a DocumentListener -