In a previous post I have discussed about CodeIgniter framework and how to build a simple app using MySQL with no ORM support. Zend is also a good PHP MVC framework which is most popular nowadays, after the Zend company introduced it newer version Zend 2. It has more robust and developer friendly enhanced features included such as routing, form creation, additional module support(3rd party) and many more.
The NoSQL db has become a first selection nowadays, since the traditional server-side bulk database handling is getting frustrated sometimes ,but it is easy to deal with NoSQL because it has on-built robust and fast data execution feasibility, no need of very complex and disgusting queries to execute, and most suited for bulk data handling. Basically the best NoSQL giants are
3. Apache CouchDB
Those has its own and unique features , such as Redis not suitable for bulk data handling but suitable for real time communication web apps.
But as a whole , all NoSQL systems primarily use JSON stuff for internal and external data processing. As an example for data insertions and retrieves they use simple JSON queries.
Here we discuss about MongoDB as a NoSQL engine for our Zend application.
So what is Doctine ? sometimes word makes you weird but it is an excellent PHP library for Object Relational Mapping (ORM) tasks. As we know Java use Hibernate and .NET use LINQ or NHibernate as their ORM tool, PHP not going to become second in ORM world, yes, it has Doctine!
So, the time to discuss about a basic application using Zend,MongoDB and Doctrine, are you ready?
First we discussed about configuration part of all those three units(The installation and configuration)
Get Zend Framework .
Basically, as a practice we use Zend Skeleton application to build a new application other than building Zend application from sketch.Its pretty easy , if you have git installed on your machine just clone it to your machine using this command
git clone https://github.com/zendframework/ZendSkeletonApplication.git
After clone it copy it to desired location(usually in Linux /var/www/ ,Aka-Document Root)
(I think you already set up PHP+MySQL+Apache on your system, if not do it now, just in Ubuntu/Debian/Mint apt-get install php mysql-server apache2 ……)
Then you need to install Zend inside this skeleton application, what you have to do is , go to your skelton application location using your terminal or cmd. You can see there are two files called composer.phar and composer.json is available in that directory.The composer.json includes the libraries/modules you need to download (simple dependency list) to the for application up and running. You may see Zend is already in your composer.json file.
Just execute the command
composer phar self-update
composer phar install
If you like you can add a separate virtual host for your application, or other wise just develop it from your document root.For development purposes I recommend you to use NetBeans-PHP IDE to increase your development speed and for self understanding the structure and flow of the code.
Other than that you may need to mod_rewrite on in your Apache configuration.
If you are done, go to http://localhost/ZendSkeletonApplication to visit the pre-built Zend2 skeleton application.
Get Mongo .
Download it from http://www.mongodb.org/downloads and install or the easy way for Debian like systems is
apt-get install mongodb
Don’t forget to install mongo-php library because missing this thing is put you in a deep trouble,
pecl install mongo
Also you need to add line extension=mongo.so in your php.ini file (may be found it in two places just add that line in both, just search to find them).
Check whether your Mongo library is bound with your PHP installation, (echo phpinfo();)
So it is Doctine time .
In order to install Doctrine module to your skeleton application you need to add Doctrine dependencies in your composer.json file , open it and add following line under require section,
and change minimum-stability as,
composer phar update
This will install Doctrine module under vendor section in your skeleton application (Zend library also goes to vender section)
So if no errors up to now? you are almost done, then we discuss how to develop an application in next article.
Useful Links :