Table of Contents
Sahana Zend Framework Experiment
Introduction
Document will help you to catch up with Sahana Zend Framework experiment.
Why Zend Framework ?
- Being one of the most popular PHP framework it has a large community and a user based.
- It has a Component based design and feature a glue type framework rather than a full stack framework.
- It is highly flexible and based on good design patterns.
Setting up the Dev-Environment
Requirements
- Being a PHP application you need to have LAMP stack or alternative ( XAMP ).
- Apache-modrewrite will be needed to enable nice urls (recommended).
- Latest version of Zend Framework. http://framework.zend.com/download/latest
- Latest version of Doctrine library. http://www.doctrine-project.org/
- BZR to get the source code.
- PHPUnit to run unit tests.
- PHP-cli
Setting up LAMP stack
If you are using Dabian or Ubuntu you can use synaptic or apt to install Apache , PHP and MySql. If you are using a diffrent Linux distribution please see the distribution documentation on how to install packages. If you are a windows user you can download and install XAMP.
Setup Zend Framework
After you download the ZendFramework archive extract it to a preferred location. Our preferred directory would be “/usr/share/ZendFramework”. Then you need to edit the php.ini file to set the ZendFramework path in include paths. To do that open the php.ini file using a preferred editor and change the following line according to your setup.
; UNIX: “/path1:/path2” include_path = “.:/usr/share/ZendFramework/library”
Specifying the path on windows systems is bit different from the above example please see the example in php.ini file on how set paths in windows.
Setup Doctrine ORM Library
Similar to Zend Framework set-up first extract and copy the Doctrine library to a location according to you prefrence. Then add doctrine location to the php.ini include paths like in the example bellow. Remember not to delete the Zend framework path while setting the path to doctrine.
; UNIX: “/path1:/path2” include_path = “.:/usr/share/ZendFramework/library:/usr/share/Doctrine/lib”
Configuring Apache
Enable mod-rewrite set Allow-override as All to enable .htaccess
BZR version control
The code is in a bzr branch hosted on launchpad you would need to install bzr in your system to get a checkout. For more details to set-up bzr and to configure it to work with launchpad visit the following links.
PHPUnit
If you are using Ubuntu 9.10 follow http://matthewturland.com/2010/01/03/phpunit-and-xdebug-on-ubuntu-karmic/
PHP-Cli
On ubuntu you can use apt-get install php5-cli to install the command line interface. After you install rebember to set the ZF and Doctrine path in php.ini file related to php-cli.
Other tools we recommend
- Xdebug which is a debugging tool for PHP
- Firebug - Client side JS debugging tool
Refer the documentation of the respective tools for how to install and use them.
Setting up the Application
Getting the Source
Currently the code is hosted on lp use bzr checkout to obtain a copy.
bzr checkout lp:~hevayo/+junk/shn-zf-ex
Once you obtain the source create a symlink to “sahana/public” directory inside the web server document root.
Set up the database
- Use “sahana/database/schema/schema.sql” sql script to create the database
- Open application.ini under “sahana/application/configs” directory and change username , password and database name according to your mysql setup.
doctrine.dsn = "mysql://username:password@localhost/databasename"
Thats it
Now go to a browser and access the public directory of the application.
Developer Notes
Directory Structure
sahana/ application/ - Contain the main application files Bootstrap.php - main bootstrap file of the application configs controllers layouts - Contain main layouts models modules modulename/ controllers views database/ - Contain database related files data/ fixtures/ sql/ migrations/ schema/ - Contain the scripts used to create the database. library/ - Directory where Zend , Doctrine libraries should be if they are not configured system wide. Sahana/ - Sahana specific framework libraries. public/ - This is the directory which you expose to the web, it contains the main request handler "index.php". tests/ - Framework specific tests. scripts/ - Contains utility scripts like the doctrine-cli tool.
Integrating ZendFramework and Doctrine
References :
The integration was carried out according to the above references.
Steps
- Created database directories
- Add doctrine resource to application.ini
- Initialise the doctrine resource in bootstrap.php
Changing Application environment
Zend App is capable of running in different environments Ex: development , testing, production. And you can have have diffrent configuration for each environment. Ex: You can have three separate databases for development, testing and production. The configuration for all of the environments are in application.ini.
To set the environment of a application, add the following environment variable to .htaccess or virtual host.
SetEnv APPLICATION_ENV development
Sahana Zend Extentions
Sahana Paginator
Sahana Query
Road map
Areas to Test
- Self containing modules.
- Doctrine integration with ZF
- Sessions
- REST services
- Authentication and ACL
- L10n and I18n.
- Unit Testing.
- Caching library.