Zend framework2 Zend Framework index.php__主任和服务经理
C:\Program Files(x86)\Zend\Apache2\htdocs\zf2 tutorial\public\index.php:Zend framework2 Zend Framework index.php__主任和服务经理,zend-framework2,Zend Framework2,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.
<?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();
并运行:
php控制台.php
输出为:
C:\ProgramFiles(x86)\Zend\Apache2\htdocs\zf2 tutorial\public
显然,这似乎是错误的目录,因为“init_autoloader.php”实际上位于此处:
C:\ProgramFiles(x86)\Zend\Apache2\htdocs\zf2教程
我的书中还提到:
Zend\Mvc\Application::init(需要'config/Application.config.php')->run()
调用Zend\Mvc\应用程序的bootstrap()方法。我不知道对init()的调用如何转换为对bootstrap()的调用。有人能给我解释一下吗
我的书还说,对init的调用负责实例化一个新的ServiceManager对象,尽管我不确定如何实现,因为我在应用程序模型的bootstrap方法中没有看到与ServiceManager有任何关系的东西。有人能给我解释一下吗
谢谢你的发帖
参考zf2教程/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__,
),
),
);
}
}
显然,这似乎是错误的目录,因为“init_autoloader.php”实际上位于这里:C:\Program Files(x86)\Zend\Apache2\htdocs\zf2 tutorial
您的console.php
的输出是不同的,因为在index.php
中您将看到这一行
chdir(dirname(__DIR__));
此有效设置将一个目录更改为C:\Program Files(x86)\Zend\Apache2\htdocs\zf2 tutorial
,它是应用程序的根目录,与init\u autoloader.php
所在的文件夹相同
我的书中还提到:Zend\Mvc\Application::init(需要'config/Application.config.php')->run();调用Zend\Mvc\应用程序的bootstrap()方法
您将Zend\Mvc\Application
与名为Application
的框架应用程序模块混淆。它们不是一回事
你的书中提到的引导正在代码中发生
如您所见,这是一个静态方法,它实例化了ServiceManager
,并在最终引导应用程序之前继续设置服务
为了进一步阅读,我建议您通过阅读这里的文档来熟悉MVC
层
chdir(dirname(__DIR__));