I have a php script needing Zend classes. It can be run in a browser, but errors occur when run the script by command lines in command prompt.
require_once 'Zend/Loader.php'; // It can work in a browser but failed by command lines
I also tried:
require_once 'C:\wamp\www\zf_project\library\Zend\Loader.php';
and
ini_set('include_path',
ini_get('include_path') .
PATH_SEPARATOR .
dirname(__FILE__). DIRECTORY_SEPARATOR. 'library');
But failed.
Then I need to load the class:
Zend_Loader::loadClass('Zend_Rest_Client');
How can I use Zend classes?
Thanks in Advance!
If all you want is to use Zend classes via autoloading—without bootstrapping your whole application—all you need to do in ZF1 (which it what you seem to be using):
Also note, you don't need to call
Zend_Loader::loadClass
to load a class, this is done automatically by the autoloader when you use the class name in normal code, for example by calling the constructor as I've done above.When you run it from web browser, the include path is set in public/index.php and then bootstrap the application. Similarly, you can copy public/index.php (e.g. as setup.php) and include it in your command line code. Also, copy the bootstrap bits that you need into that file.
Note that in ZF2 there is "console route" that let you create MVC command line script.
Here's my setup.php, notice how I load configuration with "new Zend_Config". Just 'require' this file in file you want to run from command line (console).
Edit: you have to set APPLICATION_PATH correctly in '/relative/path/to/application/'.