How to keep url clean on calling $this->index() |
[eluser]vercoutere[/eluser]
Hi, I'm completely new to CI, but loving it already! I've stumbled across a small issue here, I'm creating a login form for my website and when the user credentials are incorrect I want the page to reload and to keep the formfields filled in as the user did. Now this all works easily by using the $this->index() function. The only issue I've got with this is that my url is not clean anymore when doing so. My login form is located at domain.com, but when I press submit and the user credentials were wrong my url changes into domain.com/index.php/main/validate_user wich is clearly not how I want my url to look after only 1 click! I've searched the forums but did not come up with any helpful results (I guess "index" is quite a common term on these forums :-) ) My code at this point is very simple and straight forward. Code: class Main extends CI_Controller { Thanks a bunch for any help!
[eluser]InsiteFX[/eluser]
Index is a controller default try using the redirect below. Code: redirect('main'); InsiteFX
[eluser]vercoutere[/eluser]
Hey, thanks for the quick reply! Using that redirect still has the /index.php/main popping up in the URL bar. Though I could use a redirect to the base_url in this case, but the real issue when using redirect is that the set_value() function for the form fields doesn't get anything from the post anymore, so the values that were filled in by the user don't get remembered. (I hope I'm making myself clear here, English isn't my first language :-))
[eluser]CodeIgniteMe[/eluser]
You can use ajax if you want to submit and receive data to webserver without redirecting the page if not necessary. I prefer you read http://jquery.com, and its powerful ajax feature.
[eluser]toopay[/eluser]
If you still want it to use "php way" rather than "ajax way", you need to configure this stuff: 1. htaccess, so you can provide uri like http://yourdomain.com/somecontroller/somefunction (without index.php). Search over the forums related with this. 2. You either set up a hook, _remap or the simple one : route!. You can set up a route like these Code: $route['signin'] = "main/validate_user"; Code: <form method="POST" action="/signin">
[eluser]vercoutere[/eluser]
[quote author="OOP-MVC addict" date="1309527900"]You can use ajax if you want to submit and receive data to webserver without redirecting the page if not necessary. I prefer you read http://jquery.com, and its powerful ajax feature.[/quote] Ajax isn't really what I was going for though it had allready crossed my mind, thanks for the reply anyway [quote author="toopay" date="1309528600"]If you still want it to use "php way" rather than "ajax way", you need to configure this stuff: 1. htaccess, so you can provide uri like http://yourdomain.com/somecontroller/somefunction (without index.php). Search over the forums related with this. 2. You either set up a hook, _remap or the simple one : route!. You can set up a route like these Code: $route['signin'] = "main/validate_user"; Code: <form method="POST" action="/signin"> I'll look into the rerouting future, thanks for the tip!
[eluser]CodeIgniteMe[/eluser]
I recommend using the form helper instead of the actual form tag. Code: <?php echo form_open('signin'); ?> Code: <form method="POST" action="/signin"> for example. If your current URI is Code: http://example.com/index.php/home/index Code: http://example.com/index.php/home/index/signin
[eluser]Amitabh Roy[/eluser]
I guess the problem is when the credentials are wrong you are stuck in a unwanted url domain.com/index.php/main/validate_user . And next if you can solve this issue by redirecting using bas_url() the form fields that were filled up were empty. To overcome this you can use flashdata to set the field values when redirected back.
[eluser]CodeIgniteMe[/eluser]
If you really want to get back to your original URIs you can set your validation at the same function. Code: <?php in your view Code: // with short_open_tags open |
Welcome Guest, Not a member yet? Register Sign In |