2013-05-17 50 views
0

我創建了一個zend框架2網站,我想創建幾個獨立的php文件(使用一些Model對象),所以我可以將它們放在cronjob中。我也想把它們放在webroot之外的地方,它們不能公開訪問。zend框架2:webroot之外的引導文件

問題是沒有模型對象被解析。 我已經包含init_autoloader,但仍然必須明確要求所有文件。

是否有人知道如何創建獨立的引導文件,使自動加載仍然有效?

+0

我所用ZF做1個項目是複製網關腳本被遺漏了' - >運行()'關'$ APP->自舉()的 - >運行(); ' – Orangepill

+0

我很高興爲ZF 2項目確認此作品! :-) 我不知道如何標記評論作爲解決方案,雖然.... – marty

回答

0

更改$ APP->自舉() - > run()的,以$ APP->自舉()在網關(的index.php)

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";