我有Zend Framework命令行应用程序。我在此应用程序中使用的所有模型和内容现在都在默认模块(应用程序前缀)中,但我想将它们移动到cli模块。当我将模型移动到application / cli / model文件夹并重命名类名时,自动加载器无法找到它们。我也有管理模块,它工作正常。
这是我的server.php文件:
defined('APPLICATION_PATH')
|| define('APPLICATION_PATH', realpath(__DIR__ . '/../application'));
defined('APPLICATION_ENV')
|| define('APPLICATION_ENV', (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'development'));
require_once 'Zend/Application.php';
$application = new Zend_Application(
APPLICATION_ENV,
APPLICATION_PATH . '/configs/application.ini'
);
$application->getBootstrap()->bootstrap(array('date', 'config'));
这是我的application.ini:
[production]
phpSettings.display_startup_errors = 0
phpSettings.display_errors = 0
includePaths.library = APPLICATION_PATH "/../library"
bootstrap.path = APPLICATION_PATH "/Bootstrap.php"
bootstrap.class = "Bootstrap"
appnamespace = "Application"
resources.frontController.controllerDirectory = APPLICATION_PATH "/controllers"
resources.frontController.params.displayExceptions = 0
resources.frontController.moduleDirectory = APPLICATION_PATH "/modules"
resources.layout.layoutPath = APPLICATION_PATH "/layouts/scripts/"
resources.modules[] = ""
如何使模块在命令行模式下工作?
答案 0 :(得分:2)
我猜你错过了Cli模块的bootstrap文件 - 它应该存在于application/modules/cli/Bootstrap.php
。您可能还需要确保通过将模块和前端控制器资源添加到阵列来初始化模块和前端控制器资源,从而为您提供:
$application->getBootstrap()->bootstrap(array('date', 'config', 'modules', 'frontController'));
如果不是,我们将需要更多信息,包括您获得的错误,您尝试使用的课程以及定义的位置。
答案 1 :(得分:1)
您需要的是一个cli入口点。
通常您在浏览器中输入index.php(或/)上的应用程序,也可以通过http输入。这通常会构建响应和路由器。因为你不是通过网络进行的,所以你必须稍微调整一下。
因此,创建一个用作入口点的文件,例如cli.php(从public / index.php复制它)。并在其中进行一些调整
// Define path to application directory
defined('APPLICATION_PATH')
|| define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../application'));
// Define application environment
defined('APPLICATION_ENV')
|| define('APPLICATION_ENV', (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'production'));
// Ensure library/ is on include_path
set_include_path(implode(PATH_SEPARATOR, array(
realpath(APPLICATION_PATH . '/../library'),
get_include_path(),
)));
/** Zend_Application */
require_once 'Zend/Application.php';
// Create application, bootstrap, and run
$application = new Zend_Application(
APPLICATION_ENV,
APPLICATION_PATH . '/configs/application.ini'
);
// bootstrap and retrieve the frontController resource
$front = $application->getBootstrap()
->bootstrap('frontController')
->getResource('frontController');
//Which part of the app we want to use?
$module = 'default'; //or other module
$controller = '<your controller>';
$action = '<your action>';
//create the request
$request = new Zend_Controller_Request_Simple ($action, $controller, $module, $options);
// set front controller options to make everything operational from CLI
$front->setRequest($request)
->setResponse(new Zend_Controller_Response_Cli())
->setRouter(new Custom_Controller_Router_Cli())
->throwExceptions(true);
// lets bootstrap our application and enjoy!
$application->bootstrap()
->run();