Reputation: 18250
I've followed the steps to create a Zend Framework 2 application from the skeleton ( http://framework.zend.com/manual/2.0/en/user-guide/skeleton-application.html )
There also is a very nice tutorial for the ZF2 native console support available http://framework.zend.com/manual/2.0/en/modules/zend.console.introduction.html
Now the tutorial says:
Let’s assume that we’d like our application to handle the following command line:
> zf user resetpassword [email protected]
When a user runs our application (zf) with these parameters, we’d like to call action resetpassword of Application\IndexController.
Problem is that there is no description available on how to get the script running on CONSOLE ( currently windows ) - there's no zf or any other executable script in the created folder structure
Any hints?
ideally would be a bin folder in the application root directory which contains a entry-script for each application module
e.g. run a application module called module1
php appfolder/bin/module1.php --verbose
or
php appfolder/bin/cli.php module1 --verbose
Upvotes: 2
Views: 3323
Reputation: 1448
For those interested... based on Michel Feldheim's answer I've improved it slightly to handle symlinks as well and it also does not matter where you run the script from as it will always find the correct location. This one does however use bash"
#!/bin/bash
PHP_BIN=`which php`
SOURCE="${BASH_SOURCE[0]}"
while [ -h "$SOURCE" ] ; do SOURCE="$(readlink "$SOURCE")"; done
scriptDir="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
rootDir="$( cd -P "$( dirname "$scriptDir/../../../../" )" && pwd )"
if test -x "${PHP_BIN}"; then
cd $rootDir
"${PHP_BIN}" "public/index.php" "${@}"
exit "${?}"
fi
echo "php binary not found, please install php-cli"
exit 1;
In above example, $scriptDir is where the actual script you are running resides. And rootDir should be the base directory of your application. So lets assume the application lives under /data/www/someapplication and this application contains a modules/Application/bin folder with the filename run. From linux path (/) running:
sh /data/www/someapplication/modules/Application/bin/run
Would change directory into /data/www/someapplication, and then run:
php public/index.php <your arguments>
Upvotes: 1
Reputation: 18250
I found the solution. Just like a web-based ZF2 application the entry point is the index.php in appfolder/public
The example app from the tutorial above is called this way
php.exe public\index.php user resetpassword [email protected]
change into your ZF2 application folder
mkdir bin
touch bin/app
chmod +x bin/app
put this into your app file
#!/bin/sh
PHP_BIN=`which php`
WDIR=`dirname ${0}"`
if test -x "${PHP_BIN}"; then
cd "${WDIR}"
"${PHP_BIN}" "../public/index.php" "${@}"
exit "${?}"
fi
echo "php binary not found, please install php-cli"
exit 1;
Now you should be able to run your app this way
app user resetpassword [email protected]
Upvotes: 5
Reputation: 3726
A command line tool used to be shipped with ZF1 versions. Probably the tutorial is referring to that.
Upvotes: -1