As a hot PHP framework, Zend Framework offer a command tool named zend_tool, let us install it to our desktop of Ubuntu. see the following:
1 install php-cli
#sudo apt-get install php5-cli php5-dev
2 create direcotory
#cd /home/edwin/Zend
#mkdir tool
#mkdir library
3 check out load Zend framework
Zend_Tool library
#cd tool
#svn co http://framework.zend.com/svn/framework/laboratory/Zend_Tool/ ./
Zend Framework Stand Library
#cd library
#svn co http://framework.zend.com/svn/framework/standard/trunk/library/ ./
3 add 2 library to php.ini's include path
#sudo gedit /etc/php5/cli/php.ini
then , add "include_path = ".:/home/edwin/Zend/tool/library:/home/edwin/Zend/library" to the bottom line;
4 test it
#cd /home/edwin/Zend/tool/bin
#php zf.php
you will get soem errors like following:
zf.php cannot find the Zend Framework Labratory Library. Please either set the $zendFrameworkPath in zf.php OR set the ZFL_PATH environment variable.
So, that means php's include path was wrong. I checked it, but there was no problem on it. By many test about it, the solution is fllowing: you need change zf.php's directory path"/" into " DIRECTORY_SEPARATOR" .
/**
* DEV ONLY START - this will be removed when this hits incubator
*/
$zendFrameworkPath = null;
$zendFrameworkLabPath = null;
if ($zendFrameworkPath === null) {
$zendFrameworkPath = @include_once 'Zend'. DIRECTORY_SEPARATOR .'Loader.php'; //change this line
if ($zendFrameworkPath === false) {
// get the env var?
$zendFrameworkPath = getenv('ZF_PATH');
if ($zendFrameworkPath == '' || !file_exists($zendFrameworkPath)) {
die('zf.php cannot find the Zend Framework Standard Library. Please either set the $zendFrameworkPath in zf.php OR set the ZF_PATH environment v
ariable.' . PHP_EOL);
}
}
}
if ($zendFrameworkLabPath === null) {
$zendFrameworkLabPath = @include_once 'ZendL'. DIRECTORY_SEPARATOR .'Tool'. DIRECTORY_SEPARATOR .'Framework'. DIRECTORY_SEPARATOR .'Endpoint'. DIRECTORY_
SEPARATOR .'Cli.php'; //change this line
if ($zendFrameworkLabPath === false) {
// get the env var?
$zendFrameworkLabPath = getenv('ZFL_PATH');
if ($zendFrameworkLabPath == '' || !file_exists($zendFrameworkLabPath)) {
die('zf.php cannot find the Zend Framework Labratory Library. Please either set the $zendFrameworkPath in zf.php OR set the ZFL_PATH environment
variable.' . PHP_EOL);
}
}
}
if ($zendFrameworkLabPath !== 1) {
set_include_path($zendFrameworkLabPath . PATH_SEPARATOR . get_include_path());
}
if ($zendFrameworkPath !== 1) {
set_include_path($zendFrameworkPath . PATH_SEPARATOR . get_include_path());
}
unset($zendFrameworkPath, $zendFrameworkLabPath);
/**
* DEV ONLY STOP
*/
require_once 'Zend/Loader.php';
Zend_Loader::registerAutoload();
// run the cli endpoint
ZendL_Tool_Framework_Endpoint_Cli::main();
At the end, copy the zf.sh and zf.php to /usr/bin
#sudo cp zf.sh /usr/bin/zf
#sudo cp zf.php /usr/bin/zf.php
then, you can use the command zf at the terminal:
#zf show version
Zend Framework Version: 1.7.1
That is Ok! You could code some cool scripts by it or php-cli now
2 comments:
Hey Edwin,
Cheers for your tutorial on Zend_Tool. I am just trying it now on Ubunutu 8.10, ZF 1.95.
require_once 'Zend/Loader.php';
Zend_Loader::registerAutoload();
this line in zf.php is now deprecated in 1.8+
replace with this
require_once 'Zend/Loader/Autoloader.php';
$loader = Zend_Loader_Autoloader::getInstance();
$loader->registerNamespace('App_');
Post a Comment