我正在创建一个zend framework 2网站,我想创建一些独立的php文件(使用一些Model对象),所以我可以把它们放在cronjob中。我还希望将它们放在webroot之外,而不能公开访问它们。
问题是没有解决任何模型对象。 我已经包含了init_autoloader,但我仍然必须明确要求所有文件。
有些人知道如何以自动加载仍然有效的方式创建独立的引导程序文件吗?
答案 0 :(得分:0)
将$ app-> bootstrap() - > run()更改为网关中的$ app-> bootstrap()(index.php)
答案 1 :(得分:0)
如果有人想知道完整的解决方案是什么样的,那么它就是:
<?php
/**
* in my case, the script was put in a subfolder of the project-root, called 'cron'
* make sure you adjust this according to where you put it.
*/
chdir(dirname(__DIR__));
// Setup autoloading
require 'init_autoloader.php';
Zend\Mvc\Application::init(require 'config/application.config.php');
/**
* your code goes here
*/
echo date("d-m-Y H:i:s").": cron finished";