Sunday, April 15, 2012

Setting Up Modular Application Structure In Zend Framework.


I would be taking time out to write blog posts on Zend Framework and I hope to share as much as I can.

I started using Zend framework a couple of months back and it gets the job done nicely. The only pain I had when I picked up the framework was the relative steep learning curve (steep when compared to things like Kohana and Code Igniter which I have played with in the past). And the steep learning curve is not as a result of the framework being inherently difficult to use but due to the apparent paucity of up to date and useful resources and guides out there. Truth be told, the level of documentation has improved in recent times, but I feel a framework as matured as Zend deserves more.

My ensuing posts on Zend Framework won’t touch on the basics, i.e. setting up the framework; understanding MVC, how controllers work etc. No, the things I would write about would be a little bit above the basics. The ideal audience would be someone who has managed to set up a working copy of the framework but still find concepts like Auto loading, Resource plugins, View Helpers etc. little bit fuzzy.

Looking for setup articles? You would find a nice one on Nettut. The quick start guide on Zend.com is also a good read.

So that been said, let’s get to business.

The very first thing I would blog about is something I feel you should take into consideration right after you have mastered the set up process of Zend Framework and you are able to set up your project. And this is Directory structure your application would take.

Before we get into the details, let’s talk about what I mean by Directory Structure in the context of Zend Framework. It is simply the way your files are arranged in directories in the file system.

There are different ways you can have your files laid out on the file system for your application and the way you choose would go a long way in determining how your application is structured and managed.   The recommended structure (my personal recommendation and a couple of others) would be the Modular structure.

As you must probably know, if you use Zend_Tool  to create your project the default layout would look thus:

/app
    application/
        configs/
        controllers/
     ErrorController.php
              IndexController.php
        views/
             helpers/
             scripts/
                 error/
                      error.phtml
                 index/
                      index.phtml

        forms/
    docs/
    library/
    public/
        css/
        js/
        images/
        uploads/


In this set up, there is one general Controllers, Views, and Models folder where all the respective controllers, views and models files would be found. This set up is workable for a relatively small project, but when it comes to a much larger project the modular directory structure is most of the time advised.

And what is the Modular Directory Structure? It looks like this.


/app
    application/
        configs/
        modules/
             default/
                   controllers/
                   layouts/
                   views/
                   forms/
             admin/
                   controllers/
                   layouts/
                   views/
                   forms/
             profile/
                   controllers/
                   layouts/
                   views/
                   forms/
    search/
                   controllers/
                   layouts/
                   views/
                   forms/
    docs/
    library/
    public/
        css/
        js/
        images/
        uploads/


In this set up, your models, views, and controllers are grouped together into self-contained “boxes” based on the different functional areas of your Web application. So for example if you have a web application that has the following functionalities/sections Admin, profile, search. You can easily package the files (controllers, views, models and more) responsible for these sections into distinct boxes (actually directory). Having such helps in having an easily decoupled and manageable set up where new functionality or third party component can easily be plugged in into your application.


So how do we create a modular directory structure in Zend?

There are two ways. You can either do it with the Zend_Tool or create it manually. It is recommended you use the Zend_Tool. Creating it manually is just having to create the files and directories the Zend_Tool would have created for you automatically.

Note that to use the Zend_Tool you need to set it up. Find instructions on how to do this here

To create a modular application structure using Zend_Tool, issue the following command:


# mkdir /var/www/app
# cd /var/www/app
# zf create project .
Creating project at /var/www/app


Now change into the app directory and issue the following command, to create the admin module

zf create module admin

The following operations would be performed


Creating the following module and artifacts:
/var/www/app/application/modules/admin/controllers
/var/www/app/application/modules/admin/models
/var/www/app/application/modules/admin/views
/var/www/app/application/modules/admin/views/scripts
/var/www/app/application/modules/admin/views/helpers
/var/www/app/application/modules/admin/views/filters
Updating project profile '/var/www/app/.zfproject.xml'


Now as you can see you have your respective ‘controllers’, ‘models’, views/scripts, views/helpers, views/filters created. All you now need to do is to populate them with respective .php and .phtml files.

But we are not finished yet. Final thing to do in other to have our Zend Framework Module aware is to edit the application.ini file appropriately. To do so, just add the following lines to the end of the Production block.

resources.frontController.moduleDirectory = APPLICATION_PATH "/modules"

resources.modules[] =


One last thing that you might want to do is to have autoloading functionality within your module. To do this, just create a Bootstrap.php file inside your module directory, in this case admin and have the following codes contained in it


class Admin_Bootstrap extends Zend_Application_Module_Bootstrap
{


public function _initload()
{

//your code goes here
}
}


And you have everything set up.

To access your admin module, navigate to the url: http://hostname/admin/

Thursday, April 12, 2012

Google: The Overrated Poster Child Of Innovative Tech Company?


Lately, I have found myself reviewing Google with a more objective point of view and becoming a little critical of the company’s success with innovation. Do not get me wrong, I still think Google is a great company where any developer would enjoy working; just that its awesome cool tech aura is fading and my rose tinted glasses are falling off.

Truth be told, I, like most developers out there had bought into the Google brand and I really believed in their “do no evil” mantra. Google could do no wrong; they were cool; all about innovation and committed to developers and cutting edge technology! While, other tech companies are the villains. (Note that most of the time other tech companies often refer to Microsoft).

We end up labeling these other companies as “the evil doers” who held back the frontiers of technology with crappy software just to protect their cash cows and their bottom line; the slow bureaucratic corporate mammoths and Google on the other hand was innocent of all similar antics and was the company that is fast as a whip and always pushing the envelope when it comes to technology.

But as the rose tinted glasses fell off, Google stopped being that much of the good guy and in all honesty, I presently consider their do no evil motto; patronizing. And for good reasons, various events have lead to this perception.

First on the list would be the Mocality scandal. Where a staff of Google allegedly hacked into the database of Mocality: a business directory based in Kenya, one of the biggest in Africa, and tried using the information sourced to sell Google’s services. You can read the full account here and note from the account, that the crime appears not to be a localized one, perpetuated only by folks in Google Kenya. Yes, this atrocity is far from being a companies culture but the actions of some miscreant but yet it left a sour taste especially if you read the full lowdown.


Next, you have Google’s unscrupulous practice of sabotaging startups that they do not like or feel threatened by. Read about the experiences of Yelp and the most recent that I came across is that of Hatchlings which you can read here, another victim to Google questionable behavior.

Further, to consolidate my growing skepticism, you have the recent “Search my world” thing which was just a blatant “do evil” move; a move that corrupts the fairness of search results in favor of Google's own products. View Focus on Users for more info on this.

Add all these up and you’d understand why I really feel Google’s “Do no Evil” is patronizing.

The final event that led to my present view of Google was the purchase of a Windows Phone; a Nokia Lumia. I got the phone and I was honestly impressed by the cool and refreshing feel of its operating system which I think is a massive and superb job well done on the part of Microsoft and before I knew it, the negative perception of Microsoft being one of the bad guys; a corporate mammoth that is slow to innovate, started to drop.

Interesting right? And typical of such situations, where you find yourself reevaluating your opinion about a bad guy, I ended up also reevaluating my opinion of the so called good guys; hence the revaluation of Google.

What even made this reevaluation of Google such an inevitable event is the almost close to knee jerking reaction I usually get from people whenever I talk about how cool the new Windows phone is. They usually reply; "hey its Microsoft not Google (or Apple), don’t expect us to take you seriously.” It would appear that in their minds, the impression of “If it’s not Google then it isn’t cool" is well imprinted and Google has the copyright on cool tech. Seems lot of people have been brainwashed?

It’s called Brand capital yes I know and yes Google has it; but no more; at least for me.

This rant seeks to put things in a bit of perspective by any chance and to take a more critical look at things as it concerns Google. Like I said earlier on, I still think Google is a great company in tech, just that it’s cool factor; the halo; the trendy aura that is often acclaimed to them, might just be a little bit overrated.

You see, the brand capital Google enjoys makes people to automatically think Google is cool and its cool majorly because people believe they do innovation right and create the perfect environment for it. They do cool stuff with tech. But once I began to take a more critical look at Google, I begin to doubt how really successful the company has been with innovation; homebrewed innovation, not just the ones they buy over and slaps the Google name on.

How well has Google done in coming up with an innovative service or product and become successful with it? What appears to be the situation seems very interesting.

I would hereby quickly list some of the cool and great stuff we know from Google, Just outline them in two different lists and see if they testify to how well Google does innovation.

First List

Google Maps
One of the flagship services of Google, an innovative product that has radically changed how we find our way. But Google Maps was never a home brewed innovation. It was an acquired product. The original creators of Google maps are Lars Rasmussen and Jens Rasmussen with Australians Noel Gordon and Stephen Ma. They were the ones that co-founded Where 2 Technologies, the mapping-related start-up in Sydney, Australia that made Mapping solutions that was later bought over by Google in October 2004 to become Google Maps.

Youtube
Another of Google's Popular product which has also revolutionized the way video is consumed. They say in a 2 month period we have more videos being uploaded to Youtube than if ABC, NBC and CBS air new contents 24/7 non-stop since 1948; truly disruptive right? Yet Youtube was another acquired technology. Youtube was created by 3 former PayPal employees Steve Chen, Chad Hurley and Jawed Karim back in February 2005. It was bought over by Google in 2006. It is worth noting that before the acquisition, Google had its own Video sharing service called Google Videos, which never really had much of a success.

Android
And yes we have Android. And yes it is also an acquired asset! Surprise surprise? The initial developers of the Mobile Operating system was Android Inc a company founded by Andy Rubin. It was later purchased by Google in 2005. (iOS and Mango on the other hand are OS that were built from ground up by the companies backing them).

Blogger
Blogger is another popular and successful Google service which also was not conceived within Google. Blogger was originally created by Evan Williams (who later went on to create twitter) and Meg Hourihan. Their company, Pyra labs was acquired by Google in 2003.

Google Analytics
Ha! Yes! all the lovers of Analytics; a truly innovative product, has changed the way we now do online marketing and SEO. It has to be Google to pull such a product off right? But bet most of you don’t know that Google Analytics was also an acquired asset. The original company was Urchin Software Corporation and it was purchased by Google in 2005.

Google AdWords
Even Google Adwords. The core idea that powers Google revenue stream was never invented at Google. The original inventor of the idea of ads based on Pay per click was Bill Gross. Read more on this here

Interesting?

But this is not all. Let us look at another set of cool tech things that came out of Google.

Second List

Orkut
Am sure a huge amount of people would be hearing this service for the first time. Orkut is Google’s own Social Networking site that nobody uses. And by the way, Orkut had been in existence way before Facebook came on the block. Here http://www.orkut.com
Orkut is proudly Google!

Google Wave
Yes Google wave was another Innovation that came out of Google. It was supposed to be the bold attempt at re-imaging how we communicate and collaborate online. Truly and really Innovative? But we all know where Google wave is today? In the deadpool

Google Buzz
Haha! Google Buzz. Another home brewed Google product meant to take Twitter head on. It was an innovative social networking and micro blogging tool that integrated nicely with your email. It was cool innit? But guess it was too cool to be a hit. You would find Google buzz in the deadpool too.

Knol
Yet another ambitious project by Google. A knol was supposed to represent a unit of Knowledge. Quite cool. If you wondering what the hell Knol is, it is not your fault. The whole Knol idea never took off.

Knol was supposed to be the Wikipedia killer. It was a project that aimed to include user-written articles on a range of topics just like Wikipedia only that it was supposed to be better. By the way, Knol is also in the deadpool.

Google Plus
To be fair, it is too early to comment on this one :)

So did you see any Trend here? Any peculiarities between the two sets of Google products? any characteristics that are shared amongst the two lists?

Truth is, it has not being a tale of absolute misses but looking at the the general observation the facts stacks up nicely for us to see a trend and more importantly bring some balance to the way we perceive the company.

I would desist from giving further comments on the lists. I would rather allow you draw up your own conclusions.

The only thought I would want to leave you with is this: maybe if you look at things a bit more critical, maybe you would find that Google might not be that much of an Outlier; the poster boy for innovative tech companies that we all seem to make them to be and maybe they are as evil as the rest of the bunch or perhaps the rest are as good...

UPDATE

We can add Google Glass to these lists...I guess we know where it would fall under!