This guide will guide you through configuring the Zend Framework which is a very popular and powerful MVC framework for PHP, the idea is to configure it using the libraries provided on the Zend Server package installer.
In a previous post I explained how to set up a Zend Server installation, follow it so you can have both, Zend Server CE and the Zend Framework installed on your system.
Once you have downloaded and installed all the necessary packages this is the folder structure where u can find the files for the Zend Framework, for this guide I'm using Zend Server version 5 which is at the moment the latest release and it comes also with the latest version of the Zend Framework v 1.10:
/usr/local/zend/share/ZendFramework (root folder for the Zend Framework)
/usr/local/zend/share/ZendFramework/bin (shell scripts folder, these scripts will help you handle your project config, I'll explain later)
/usr/local/zend/share/ZendFramework/library/Zend (Framework library files)
Ok, now that we have all the tools, let's create our first PHP application using the Zend Framework, as I mentioned above, Zend Framework comes together with a shell script that will help creating or modifying element on our MVC project structure, in order to use this script we'll have to create first a link to it just for easy handling globally through the command line, on Linux you create a link by typing:
$ sudo ln -s /usr/local/zend/share/ZendFramework/bin/zf.sh /usr/local/bin/zf
Let's now create a new PHP project in our home folder, we do so by typing:
$ zf create project /home/username/my_first_project
the command will create the whole project structure including some initial config files that you can alter later while developing your project. Once the command is done the folder structure you'll see will look similar to:
my_first_project |-- application | |-- Bootstrap.php | |-- configs | | `-- application.ini | |-- controllers | | |-- ErrorController.php | | `-- IndexController.php | |-- models | `-- views | |-- helpers | `-- scripts | |-- error | | `-- error.phtml | `-- index | `-- index.phtml |-- library |-- public | |-- .htaccess | `-- index.php `-- tests |-- application | `-- bootstrap.php |-- library | `-- bootstrap.php `-- phpunit.xml
Now we need to link the Zend Framework's library files to our library project so we can make use of them, to do so we need to create a extra link that will point our library folder to our Zend Framework's current installation, type this in your terminal:
$ ln -s /home/username/my_first_project/library path/to/ZendFramework/library/Zend
and voilà! You are all set up to start coding your application with all the advantages that Zend Framework brings.
You can find more info about what the zf.sh script does by typing:
$ zf --help