【发布时间】:2016-04-02 03:47:19
【问题描述】:
我遇到了这个错误,谁能帮忙..
解析错误:语法错误、意外的“类”(T_CLASS)、需要标识符 (T_STRING) 或变量 (T_VARIABLE) 或 /opt/lampp/htdocs/zendd/module/Application/config 中的“{”或“$” /module.config.php 第 76 行
这是我的代码
'Application\Controller\Index' => Controller\IndexController::class
错误指向 module.config.php 中的这一行
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/ZendSkeletonApplication for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
namespace Application;
return array(
'router' => array(
'routes' => array(
'home' => array(
'type' => 'Zend\Mvc\Router\Http\Literal',
'options' => array(
'route' => '/',
'defaults' => array(
'controller' => 'Application\Controller\Index',
'action' => 'index',
),
),
),
// The following is a route to simplify getting started creating
// new controllers and actions without needing to create a new
// module. Simply drop new controllers in, and you can access them
// using the path /application/:controller/:action
'application' => array(
'type' => 'Literal',
'options' => array(
'route' => '/application',
'defaults' => array(
'__NAMESPACE__' => 'Application\Controller',
'controller' => 'Index',
'action' => 'index',
),
),
'may_terminate' => true,
'child_routes' => array(
'default' => array(
'type' => 'Segment',
'options' => array(
'route' => '/[:controller[/:action]]',
'constraints' => array(
'controller' => '[a-zA-Z][a-zA-Z0-9_-]*',
'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
),
'defaults' => array(
),
),
),
),
),
),
),
'service_manager' => array(
'abstract_factories' => array(
'Zend\Cache\Service\StorageCacheAbstractServiceFactory',
'Zend\Log\LoggerAbstractServiceFactory',
),
'factories' => array(
'translator' => 'Zend\Mvc\Service\TranslatorServiceFactory',
),
),
'translator' => array(
'locale' => 'en_US',
'translation_file_patterns' => array(
array(
'type' => 'gettext',
'base_dir' => __DIR__ . '/../language',
'pattern' => '%s.mo',
),
),
),
'controllers' => array(
'invokables' => array(
'Application\Controller\Index' => Controller\IndexController::class
),
),
'view_manager' => array(
'display_not_found_reason' => true,
'display_exceptions' => true,
'doctype' => 'HTML5',
'not_found_template' => 'error/404',
'exception_template' => 'error/index',
'template_map' => array(
'layout/layout' => __DIR__ . '/../view/layout/layout.phtml',
'application/index/index' => __DIR__ . '/../view/application/index/index.phtml',
'error/404' => __DIR__ . '/../view/error/404.phtml',
'error/index' => __DIR__ . '/../view/error/index.phtml',
),
'template_path_stack' => array(
__DIR__ . '/../view',
),
),
// Placeholder for console routes
'console' => array(
'router' => array(
'routes' => array(
),
),
),
);
【问题讨论】:
-
你的代码是这样的吗?您是否考虑过缩进/格式化您的代码?有助于查看语法错误。 ...啊好多了
-
感谢您的快速回复。这是它指向 76 的完整代码,即 'Application\Controller\Index' => Controller\IndexController::class
-
控制器方法是不是叫
class?可能是reserved/ keyword 问题?抱歉,对 ZF2 配置不太熟悉。简单的测试是将class重命名为foo并查看错误是否发生变化。 -
这是一个从 github 下载的骨架应用程序主文件,它给出了这个错误。第一次尝试使用zend。
-
如果我将类更改为 foo 。它给出了未定义的类常量'foo'
标签: php zend-framework