Processing WordPress Links

WordPress offers a feature to provide pretty links for your posts.

This would be something like or even or depending on the scheme you choose in your permalink settings.

You may need to process this link to get the actual post id. Say if you are.


  1. Building an API
  2. Redirecting traffic
  3. Using XMLRPC
  4. Writing out an entirely new interface for wordpress.

Good news is that if you have access to the database on which the wordpress installation runs from, this is relatively trivial.

The only part you need to parse is the post name in our case integrating-laravels-auth-with-sentinel  Do a lookup on the wp_posts table post_name column and presto you are done.

A possible implementation of the above steps in Laravel 4.2 would be

The Model to retreive the id

The Interface on which you will code your link parsing algorithm

A simple url parser




Integrating Laravel’s Auth with Sentinel

User authentication & authorization system is a common use case in a lot of apps. Thankfully Ryan Durham has a package that bootstraps resources needed for a fully functional authorization system in Laravel. You can install the package from packagist


"require": {
    "laravel/framework": "4.1.*",
    "rydurham/sentinel": "1.*"


You can check out the actual package on github Sentinel

The system is based on Cartalyst Sentry package

Now this all works well. Unfortunately users logged in via sentry are not automatically logged on to Laravel’s native system as such the Auth facade is unusable.

This to me is a problem because I am more likely to switch out the sentry authentication system than I am to switch out the entire Laravel framework for any one particular project.

Thankfully Sentinel fires off events when a user logs in, logs out or registers. There are other events, but this are the ones we need.

As such we can listen to this events and update the native Laravel system to authenticate as well.



Make sure all the files are loaded on boot by Laravel. Now whenever there is a user action on Sentry, it will be immediately mirrored on Laravel’s Auth.

Till next time.

Happy coding.







Git | What to ignore

One of the most abused commands in git has to be

git add .

and the least used files has to be .gitignore .

I will not go into details on how .gitignore works the docs cover it quite well, in summary the file specifies what files git should ignore.

If you are wondering what files to ignore, here are some clues.

IDE Meta Files

Almost all IDEs generate a special folder in your project to store the projects meta data. An example would be the nbproject folder for netbeans.

The entire directory needs to be ignored.

Images, Videos, Documents and other binary files

This are generally user generated contented and not code. Version controlling this assets will lead to unnecessary bloat.

Furthermore if you use github  there are limits to the size of the files .

External Libraries

Libraries that you use for your system an example would be the vendor folder automatically generated by composer need to be ignored.

While this libraries are code, you did not write the libraries and have no reason to version it. If you are deploying using git then you can just as easily upload the libraries or run composer update on the remote server and get the same files once more.

Application Output

Unless in edge cases you should never version the output of your code. eg CSV reports, logs, pdfs etc

This is because the data can be easily regenerated and even more importantly it is not part of your code.


If you are using a file based database system like SQLite. Make sure to ignore the database files. If you need a backup. You can setup automated backups separately.

In conclusion you can use this as a general rule of thumb

If you did not write it, don’t version it


Have any extra additions of your own? Please add to the comments section below.

Till next time. Happy coding!!



Users Table Structure

For all applications a solid database design is absolutely essential, for small applications, a well designed database may mean the application is practically done.

Almost all applications require a users table which tends to be overly bloated. A typical structure looks something like this

Now this is all good but this has several flaws

  • The table has to be changed whenever any of the attributes changes
  • The table and any helper files you may have (models, migrations, forms, controllers etc) are not reusable across your different projects
  • You can not easily test access control functions
  • You will end up with a lot of “ifs” to determine existence of data or even worse role the user plays.

We need to clean this up to a couple of separate tables like this

This finally leaves us with clean and reusable structure


You should consider applying the same concepts to all your tables, general rule should be if a table has any group of attributes that you seem to use a lot together, strip them out and build a new table for them.

Till next time. Happy coding!





Setting up papertrail on forge.

Looking for log files can be quite a hustle. Fortunately forge  ( ) + papertrail (  )makes this a downright simple process. Assuming you already have an active forge and papertrail

Step 1:

Create a new logging system in papertrail

Take note of your specific link.

Hint: It is the content in large text***.
Step 2:

Login to your forge installation.

Select the server you want to manage and then navigate to the monitoring tab.

There is an option for papertrail. Paste in your link and click install.

Step 3:

Navigate back to papertrail and wait till your server shows up on the “All Systems” list.

And you are good to go. Happy logging!!


The Final Word

Among the list used keywords in php is “final”

The definition from

PHP 5 introduces the final keyword, which prevents child classes from overriding a method by prefixing the definition with final. If the class itself is being defined final then it cannot be extended.

If you are anything like me, then your first thought must have been why would I want to kill inheritance and polymorphism. This does seem like a needless, neigh, a downright harmful operation. However this keyword plays a very important role in your application design.

One use case is where you would want to carry out the Introduce Parameter Object Refactor .

Our original class looks like this:

Once we have refactored:


So far all is well. Now imagine way into the future, you decide to make the date output a bit more user friendly, and being a good developer you extend the DateRange class with a new method

While all may look well. This bit of code will break all classes that used it as parameter!

When you really think about it, you realize that DateRange had no business being extended and should have been treated as a primitive object, just like the parameters it replaced.

As such this class should be declared final to protect it from further meddling and even more importantly to ensure consistency of your code.