Every now and then, the question comes up of if its a good idea to learn PHP before one learns CodeIgniter, or after one learns CodeIgniter.
I teach technical training for 2 universities, a college, and do a lot of corporate training, so I often find people who are just starting out and wanting to pursue a tool. For a long time my knee-jerk advice was “learn the skill first, then come back to the tool.” That said… the longer I think about it, the more I can see how learning PHP through a framework like CodeIgniter could be really useful. So here is my current position on the topic.
If you don’t know PHP and want to learn, then learn it at the same time as you learn CodeIgniter
One of the major risks of this though, is that it might be easy to confuse what is “native” PHP and what is CodeIgniter. So you still must learn the basics of PHP, and if you haven’t spent at least a few hours reading websites like php.net, you haven’t paid your dues ;)
After you’ve got the PHP basics down, get yourself a decent PHP book (anything from Apress, or Wrox, or O’Reilly). Now, before you crack the book, read through the CodeIgniter userguide, and print off the table of contents for your reference, even if you don’t understand it yet. As you read your PHP book, check the CodeIgniter table of contents to see if what you’re reading about is already something CodeIgniter handles. Try to implement concepts the book shows through CodeIgniter, then compare it to how CodeIgniter might do something, then ask yourself “why is it doing that?” For example, if you look at one of those “intro” tutorials, or basic PHP books, they tell you that to read form submissions you should use $_POST[‘form_field’]; and that’s all they say about it. Then they show some really neat example of creating a guestbook or something and tell you to that you can save your work into the db by using
mysql_query ("INSERT INTO table (fullname) VALUES (" . $_POST['fullname'] . ")");
and you think “cool”, but in reality that is horribly bad practice, as it leaves you wide open for attacks. Now let’s compare it to the way CI does something. CI would never let you get away with something so sloppy. CI wants to sanitize the input, clean the input, shorten it, take it out for dinner, wine and dine it for 2 months and then maybe, it’ll let it into the database. Hmm… I wonder why?... And now we’ve learned a useful lesson that all programmers should learn - namely, never trust input and clean up everything.
So punchline - I think learning PHP alongside CI could work, but you still need to pay attention to the underlying PHP, logic and practices.
If you do decide to start PHP with CI, drop by the forums and say hi!