![]() |
Login - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: Login (/showthread.php?tid=53115) Pages:
1
2
|
Login - El Forum - 07-11-2012 [eluser]Felipe Deitos[/eluser] Hi everyone! First of all, i am from Brazil and my english is actually bad... and i am not using the translator cuz i think it is worst than me hehe I am a developer for some years, and i was reading about all frameworks, and i decided começar a usar o CI, it seems better, simple, seems to have a great community! So i was reading the user guide and a lot of other stuffs, it will take a time until i get used to all features... I have watched some tutorials too(like this http://net.tutsplus.com/articles/news/codeigniter-from-scratch-day-6-login/) A great tutorial teaches how create a "template", login form, sign up... So here we go, my question is... i want this same login but i want to show the fields to login in every page of my website in the header... (like this forum, show the fields to login, and after login u can see your informations "Hello, Felipe")... Someone can help me, show me a good tutorial, or give me the right way to do it? Thanks for your attention!! Hope that i can help someone in a next future. Login - El Forum - 07-11-2012 [eluser]CroNiX[/eluser] What I do is create a Template library that gets autoloaded. I won't write the whole thing out, but you can simply do things like: Code: class Template { Then in your controllers, all you have to do is pass the template the main view you are using for the content and it will add the header, menu and footer every time. you can also create various methods to display different types of pages. This keeps your controllers clean and DRY. If you have a login system, for instance, where it displays the users info and some links if they are logged in and shows the login form if they aren't, the library can do all of that stuff for you so you don't have to pollute your controllers, and then there is only one place to update it if it needs updating. Controller: Code: //...blah, do some work, manipulate some data... This is obviously a very simple example, which can be infinitely more complex and do a whole lot more. Login - El Forum - 07-11-2012 [eluser]Felipe Deitos[/eluser] Ok i got it, its working perfectly (really really thanks for the help) Getting that, brings me another question.. I already got the login form working in the header... So the user type his username and password and press enter... What is the action i should call in form_open('????Class/function????'); Thanks again for the attention! sorry about the newbie questions and bad english hehe! Login - El Forum - 07-11-2012 [eluser]CroNiX[/eluser] Whatever controller/method does your login checking. I pass along the last url visited when logging in, so that if they get logged in it will redirect them back to the last page they were on, making it look like they never left. Login - El Forum - 07-11-2012 [eluser]Felipe Deitos[/eluser] hehehe Last one... here we go! I got my header and footer views inside a folder called includes... On submit the form it calls 'includes/validate_user' This is my includes controller: Code: <?php This is my users_model: Code: <?php How can i use this redirect to return to the page that i was viewing? Login - El Forum - 07-11-2012 [eluser]CroNiX[/eluser] Should be easy enough. In your login form, create a "last_url" hidden form field that has the value of current_url(). When they successfully log in, send them back to the last_url. Or, you could use the value of $this->input->server('REDIRECT_URL'), which may not be as accurate. Is there a reason why your validate() function doesn't return FALSE if they don't successfully login? Login - El Forum - 07-11-2012 [eluser]Felipe Deitos[/eluser] Thats it, got it... actually you must feel sorry for me hehehe cuz i am a *** newbie... I dont even know that this current_url exists... Like i said before it makes 2 days since i am working with CI I dont know if its right or not but i guess i didnt returned false in model because in the controller check if its true... if it is true make something... else other thing Its working, but i guess this is a not good practice, right? Login - El Forum - 07-11-2012 [eluser]CroNiX[/eluser] I would just Code: return ($query->num_rows == 1); //which will return TRUE if it is and FALSE if it isn't 1. Login - El Forum - 07-11-2012 [eluser]Felipe Deitos[/eluser] The king of the north! hehehehe its always nice improve my coding style! I Will use this always possible! Login - El Forum - 07-11-2012 [eluser]InsiteFX[/eluser] Code: <?php |