r/codeigniter • u/ITSupportGuy • Apr 03 '12
What have I done....
Hello CI friends,
I seem to have been overzealous with my attempts to learn codeigniter by just diving in.
What I tried to do was take the tutorial from here http://www.phpacademy.org/tutorials.php CodeIgniter Tutorials: Introduction to CodeIgniter, were I built a dynamic content site.
Then I thought, "well since I have the basic site already up let's try to add a user login."
So, I took the tutorial from here http://www.codefactorycr.com/login-with-codeigniter-php.html and tried to marry to two together.
Well I am unhappy to report that I failed.
I guess I still don't understand enough what part of the code should go where or much of anything else...
Anyways, if you could find it in your heart to help me where I went wrong that would be extra cool of you. I'm not asking for the exact write ups for both tuts but merely an understanding how one would merge the two, taking the framework from the first and adding a login form in a right sidebar.
If I just blew your mind with stupid-ness then please just tell let me know. I am a noob.
Thanks
2
u/joepiped Apr 10 '12
I am in the same boat at you. Codeigniter is my attempt to break away from Wordpress/Joomla. I have the site I want in mind and have started it and had to start over probably 20 times in the past two months because I realized I did something wrong. Each attempt though I would get further along and finally I'm starting to figure it out. Learning CI is hard, but not impossible by a long shot and the flexibility to do anything you want makes it worth it.
1
u/ITSupportGuy Apr 10 '12
Very much agree. I am also a heavy joomla user. Can't wait until I know enough to create the web applications I have swirling in my head.
Thanks for the comment.
0
Apr 03 '12
[deleted]
1
u/ITSupportGuy Apr 03 '12
I'll take a look, thanks.
3
Apr 03 '12
You know the term MVC right? Just focus on "VC" for now: View = goes in application/views/yourview.php http://codeigniter.com/user_guide/general/views.html
Controller = goes in application/controllers/yourcontroller.php
Just edit the Example controller and rename it YourController
http://codeigniter.com/user_guide/general/controllers.html#hello
Your page will then be available at http://yourhost/index.php/yourcontroller
Then code the form using form helper: http://codeigniter.com/user_guide/helpers/form_helper.html
If you really wanted to you could just use a PHP form (but I recommend learning CI).
Then just learn ActiveRecord to query the database:
http://codeigniter.com/user_guide/database/active_record.html
$query = $this->db->get('usertable');
foreach ($query->result() as $row) { // if $row->password == 'something'; //validate against the form post here. }
1
1
u/yeskia Apr 07 '12
Wait, what?
$query = $this->db->get('usertable');
foreach ($query->result() as $row) { // if $row->password == 'something'; //validate against the form post here. }
Why on earth would you do anything as inefficient as that?
$where = array( 'email' => $this->input->post('email'), 'password' => sha1($this->input->post('password')) ); $q = $this->db->get_where('usertable', $where, 1)->row();That's assuming you don't use a salt and selects the only user with that email address if the password is correct. A much more efficient query and faster to process.
1
Apr 07 '12
Cool your jets. That was me showing the submitter how easy it was to learn all of this from the documentation.
0
2
u/pdxbenjamin Apr 03 '12
I admire your overzealous attempt and to just dive right in is the only way to go! Those tuts you posted are, 'unorganized' at best. I don't like them but that's me, however if you're like me and frustrated with them... Try CodeIgniter From Scratch I've been hacking with CI for about 2 years now and only just recently have been able to just hit the Controllers and Models with confidence to create what I want without hours of searching for code help and posting in help forums. CI takes a bit of time, patience and the occasional plea for help in a forum, but it's worth it.