Git storage options in a MVC structured PHP Framework

We’ve recently been racking our brains over possible ways to keep a PHP Framework we’ve been developing, agile within individual projects. The Framework is still quite young development wise, but it is mature enough to develop sites on. So ideally what we wanted to do was create a Git repository for our Framework under a organization account on the lovely Github. Once done, the tricky part was trying to separate the framework code from the individual sites code.

This was quite interesting because what it would enable us to do is continuously develop and push changes to our framework from each and every individual site we make separate from the core Controllers, Models and Views of the individual sites / projects that the Framework was deployed on.

To help visualize this here is an example directory structure of the framework.

git stroage option one Git storage options in a MVC structured PHP Framework

We’re fairly new to Git and having used SVN in the past, it was quite a jump, however we’re pretty in love with Github and the whole approach. So naturally we decided we had to make this work, after a few days of brain racking and scrobbling the two choices became evident.

Choice 1

Clone the Framework into a the workspace for a new site, and add to the Frameworks repository add a gitignore on folder application/ which is where anything unique to each site will reside. Also move the assets folder from the root into the application and add a .htaccess redirect for any URI string starting ^assets/blahblah to application/assets/blahblah which allow direct access to stylesheets, images and javascript using a simple /assets/images/bob.png call.

Due to the application folder being ignored by the frameworks repository, you can then ‘init’ a new git repository inside the application folder and work on your site completely separate from the framework and commit, pull and push as you wish without effecting the cloned framework. Whats also handy is you could if you so wanted add changes to the framework and push them right to the main repository which also works well for us when the framework is still very much in development.

Choice 2
The second approach was to utilise the advantage that our Framework can be installed into sub directories and thus we can specify the location of our core folder, right in our index.php file. This would allow us to make our directory structure relatively similar to that of before, but something more like this.

git storage option two Git storage options in a MVC structured PHP Framework

Now what we would do here is set in our config within the application folder

	define('EXT', '.php');
	define('ROOT', dirname(dirname(__FILE__)).'/Fury-PHP/');
        # this is the important line
	define('SYS', 'lib/core/');

Now onto the important thing, we would Git init in the root but add the Framework into lib via git submodules, this would allows us to manage the source of the Framework right to its main repository but also allow us to commit and update the submodule without effecting our application instance. The only problem being you now would need a index.php and .htaccess file added per application, which isn’t such a bad thing in fairness.

We’ve not decided what approach we prefer the most, so we’re most likely in true testing practices going to try out both methods putting them to use in real life examples and see how we go from there.

We might post a follow up to this post to let you all know how we get on. Nevertheless we hope this post might be helpful to anyone running a similar Framework and wanting to continuously improve and develop it across multiple websites and projects.

Blog written by Dave

I am one of the Directors of Bytewire and I like to blog about lots of different and interesting stuff surrounding the website design and development world.

One comment so far

  1. Ivo Sabev
    May 28, 2011 at 4:48 am

    Dave, great article. I am currently debating the same issue for a small framework I am working on myself. I think I am inclined towards Choice 1, but what did you guys decide at the end?

Leave your thoughts

You may use these HTML tags and attributes in your comments.