background preloader

PHP

Facebook Twitter

 CodeIgniter Base Classes: Keeping it DRY. Most applications in CodeIgniter will have various types of pages. The public frontend, a backend admin panel, perhaps some sort of moderator or staff panel, etc. Logic for these types of pages is normally copied between all of their different Controllers which means, for example, if the way the admin area protection is handled is changed there will be lots of Controllers to change and test. This logic can instead be shared by some creative extending of the Controller class to create custom Base Controllers like Public_Controller, Admin_Controller, etc. WTF are you talking about?

The idea is that most of your controllers share something in common with each other. Wicked! The first step is to create these Base Controllers. application/core/MY_Controller.php MY_Controller is a basic core library extension. All we have done here is create a base class that all of our Controllers and "controller types" will inherit. Application/core/Public_Controller.php application/core/Admin_Controller.php. Xdebug and You: Why You Should be Using a Real Debugger – Juan Treminio. In my Setting Up a Debian VM, Step by Step tutorial I showed you how to install and enable Xdebug on a VM but I didn’t really explain what Xdebug is, why you should use it, or how to actually begin working with it. Xdewhatchamacallit? Xdebug is a PHP extension that was written and is maintained by Derick Rethans. It provides debugging and profiling capabilities, although I’ll be mostly focusing on the debugging aspects in this tutorial.

With it you can set a breakpoint and pause the execution of a script to see the state of your application at that exact point, including what variables/objects have been instantiated and what their values are. Xdebug completely replaces the need to litter your code with echo, print_r() or var_dump() calls, and displays information on all variables, not just the one you passed. It also allows you to change the values of one or more variables on the fly, affecting the execution of your application. IDE/Text Editor Support Installing Xdebug Your Code Wrapping it Up.

Slim Framework. Programming Are Hard — Abstract classes, abstract methods, interfaces, what? October 3, 2013 If you've been developing with PHP for any length of time you've probably heard of concrete classes, abstract classes, abstract methods, and interfaces. Many of the popular frameworkd encourage you to "program to an interface", but what does that mean?

And when should you program to an abstract class, or define an abstract method? Let's figure this out. What's what? I could give you definitions, but most people have a hard time wrapping their heads around these ideas without examples. Starting small First things first, let's define a small, achievable goal. Sweet. Your users are really enjoying getting emails when their friends post pictures of their cats. Abstract classes and methods Cool, now we can send emails and SMS messages to our users...but our classes look very similar. We can use abstract classes when we have similar objects that share some functionality but do things a bit differently.

Warning! Note! Message queue Hmm...this works, but it could be a lot better. PHP Dependency Injection. Dependency injection is the answer to more maintainable, testable, modular code. Every project has dependencies and the more complex the project is the more dependencies it will most likely have. The most common dependency in today’s web application is the database and chances are if it goes down the application will all together stop working. That is because the code is dependent on the database server, which is perfectly fine.

Not using a database server because it could one day crash is a bit ridiculous. Even though the dependency has its flaws, it still makes life for the code, and thus the developer, a lot easier. The problem with most dependencies is the way that code handles and interacts with them. What I really mean is the problem is in the code and not the dependency. The book object now is given full access to the database once it is constructed. This raises the question, how exactly does the book get access to the database? This is, at its finest, dependency injection. PHP: Hypertext Preprocessor.