【发布时间】:2014-03-26 03:45:35
【问题描述】:
C:\Program Files (x86)\Zend\Apache2\htdocs\zf2-tutorial\public\index.php:
<?php
/**
* This makes our life easier when dealing with paths. Everything is relative
* to the application root now.
*/
chdir(dirname(__DIR__));
// Decline static file requests back to the PHP built-in webserver
if (php_sapi_name() === 'cli-server' && is_file(__DIR__ . parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH))) {
return false;
}
// Setup autoloading
require 'init_autoloader.php';
// Run the application!
Zend\Mvc\Application::init(require 'config/application.config.php')->run();
如果我将文件放在名为 console.php 的同一目录中:
<?php
echo __DIR___
?>
然后运行:
php 控制台.php
输出是: C:\Program Files (x86)\Zend\Apache2\htdocs\zf2-tutorial\public
显然,这似乎是错误的目录,因为“init_autoloader.php”实际上位于此处: C:\Program Files (x86)\Zend\Apache2\htdocs\zf2-tutorial
我的书还说: Zend\Mvc\Application::init(require 'config/application.config.php')->run();
调用 Zend\Mvc\Application 的 bootstrap() 方法。我不确定对 init() 的调用如何转换为对 bootstrap() 的调用,有人可以向我解释一下吗?
我的书还说,对 init 的调用负责实例化一个新的 ServiceManager 对象,尽管我不确定如何,因为我在 Application 模型的引导方法中看不到任何与 ServiceManager 有任何关系的东西。有人可以向我解释一下吗?
感谢您发布...
参考zf2-tutorial/Module/Application/Module.php
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/ZendSkeletonApplication for the canonical source repository
* @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
namespace Application;
use Zend\Mvc\ModuleRouteListener;
use Zend\Mvc\MvcEvent;
class Module
{
public function onBootstrap(MvcEvent $e)
{
$eventManager = $e->getApplication()->getEventManager();
$moduleRouteListener = new ModuleRouteListener();
$moduleRouteListener->attach($eventManager);
}
public function getConfig()
{
return include __DIR__ . '/config/module.config.php';
}
public function getAutoloaderConfig()
{
return array(
'Zend\Loader\StandardAutoloader' => array(
'namespaces' => array(
__NAMESPACE__ => __DIR__ . '/src/' . __NAMESPACE__,
),
),
);
}
}
【问题讨论】:
标签: zend-framework2