Tuesday, August 28, 2012

Understanding Zend Framework’s Plugin: Resource Plugin...(Part Three)

This post on Resource Plugin would be the last in the series of posts on Plugins as we have it in Zend Framework that I started a couple of weeks back. The previous two posts were on Simple Class/Front Controller Plugin and Controller Action Helper and View helpers.

Resource Plugin are tied to bootstrapping process in Zend Framework. In order to get a good understanding of Resource Plugins, it would be good to first of all take a step back and have an overview of what Bootstrapping means in Zend Framework’s context. This would help in getting a better understanding of what actually goes on when we say we want to make use of or write our own Resource plugins.

So what exactly is Bootstrapping?

Whenever a Zend Framework application is accessed, the following process must occur in order for the application to run and respond to a request. These processes occur in the order that they are listed below:

1.Application Bootstrapping: This is the process of preparing the application and making sure things needed to run it are available: setting up application environment etc.

2.URL Routing: Process of getting the URL and determining the respective Modules, Controller, Action that is being referred to in the application.

3.Dispatch: This is actually the process of initiating and calling the necessary controller and action from the specified module (if module is specified)


Sunday, August 05, 2012

Understanding Zend Framework’s Plugin: Controller Action Helper Plugin, and View Helper...(Part Two)

Last week I started off with the first post in a series of post on plugins as you have in Zend Framework. This is the second part of the series, where I would look at Zend framework’s Controller Action Helper and View Helper, since the previous post covered Simple Class plugin and Front Controller plugin - you can read it here.
As I said in my previous post, the idea behind these series of posts is to shed some light on plugins and the different incarnation that exists within Zend framework;


Controller Action Helper

First let me start by explicitly saying that Controller Action Helper and Front Controller Plugin are different, although they may sound alike. Read about Front Controller Plugin here.

Controller Action Helpers are the kind of Plugins that are tied to your Controller Actions, and just as Front Controller plugin, they can run specific tasks at some predefine stages of the MVC cycle; though this isn't mandatory. The key difference between Front controller plugins and Controller Action Helper is that your controllers can interact with action helpers to change their behavior, or use some on-demand functionality while this is not the case with Front Controller plugins.



Sunday, July 22, 2012

Understanding Zend Framework’s Plugin: Front Controller Plugin, Controller Action Helper, View Helper, Resource Plugin...(Part One)


This post is the first of three posts on Zend Framework's plugin. It would give a quick overview of the concepts of Plugins in Zend Framework. The aim is to provide an easy and short explanation of various plugin related concepts in zend framework; making it easy for a new comer to get up and running in no tim.

Usually, after getting the basics of Zend framework; that is: setting up your projects, using the Zend_Tool,  using controllers and views etc, more often than not, the next points of confusion for the new user usually stems from having to grapple with the various minor concepts within Zend framework.

An example of these concepts is the idea of Plugins. Plugins by itself is a simple concept right? But within Zend Framework, there are so many variant of plugins that it could quickly get perplexing to a new user.

What is a Front Controller Plugin? What is a Resource Plugin? What about our View Helpers? How are these different from Controller Action Helper? Wait. There is a Controller Action Helper? How is it different from our Front Controller Plugin? As you see...it could get confusing pretty fast.

Like I said in my previous post on how to set up a modular application structure, zend framework itself is not inherently difficult, just that it could take a while to wrap a head around how everything fits together, plus the paucity of useful and up to date resources out there does nothing to help matters.



Monday, July 02, 2012

Introduction to Git and GitHub

A presentation I made for an even earlier this year on Git. The presentation covers the basic work flow of init, clone, add, commit and push. Other commands like git remote, git pull etc are briefly touched.


Wednesday, May 30, 2012

Maxlen Jquery Plugin

You know that little functionality where you want to limit the characters entered into an input field while showing the user how many characters they have entered or how much characters remaining? Think Twitter style, that limits the characters entered to 140 and shows you how many characters you have left for your tweet?

This is exactly the functionality the Maxlen JQuery Plugin implements, a JQuery plugin I had to put together as I got tired of the repetitiveness of having to implement this in my projects.

Thing is, I recently implemented this function twice on two different projects in the last 2month, and I got irritated with having to copy and paste code all about the place. And so I used it as an excuse to just write a JQuery plugin.

JQuery obviously has a cool Plugin architecture so it did not take much time to put my first JQuery Plugin together :)

Maxlen JQuery Plugin is that: a simple JQuery plugin that allows you easily limit the number of characters that a user can write in a field and state either how many characters has been used or how many characters is left. It works with both Textarea field and the Input type text HTML element.


How It Works
Maxlen JQuery Plugin can be used on either Textarea element or Input[type=text]. Once the Plugin is activated for the desired field, the number of characters entered would then be limited based on supplied settings. The default characters allowed is 160. This can easily be changed.

The really useful part of the Maxlen JQuery Plugin is the feedback it gives users as they type in, as the allowed character length can easily be done with the HTML maxlength property. The plugin has two options of showing this: It can either show how many characters has been used or how many characters are remaining before the stipulated limit is reached.

Usage is simple. To activate the plugin on a textarea with an ID of "feedback" write:

$(document).ready(function()
{
$('textarea#feedback').maxlen();

}
);

This would use the default values and limit allowed characters to 160.

Maxlen JQuery Plugin can be used on more than one element at the same time. So the following code would work:

$(document).ready(function()
{
$('textarea,input').maxlen();
}
);

or

$(document).ready(function()
{
$('textarea').maxlen();
$('input').maxlen();
}
);

Note that even though the type of Input is not specified, the plugin would only take effect on input[type=text]

Options available

The previous codes initiates the Plugin with its default settings. But that is not the only way it can be used. It offers some level of customization options.

To initiate the plugin with all the full options, you have:

$('textarea').maxlen({
      'limit' : 160,
      'order' : 'desc',
      'class' : 'maxlen_class',
      'position' : 'above'
    });

A quick explanation of the options:

limit
States the limit of characters allowed. Default is 160.

order
States whether the plugin would show how much characters has been used in the limit specified or how much is remaining.The allowed options are 'desc' and 'asc'. 'desc' shows remaining characters, 'asc' shows used characters. The default is 'desc'.

class
States the class name for the indicator showing the characters. The default is maxlen_class. You can change this to whatever string you want. Use this class name to style the indicator.

position
States where the indicator should be placed, whether above the input element or below. The allowed options are 'above' and 'below' The default is 'above'.

That is all to it.

So now that the plugin is out there, I hope it would prove useful to others too. To get your hands on it and for full details on how to use it in your project, please head over to Github where it is hosted. You can grab it here and find the readme file here

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!