在ZF2骨架中,路由器配置使用一个键:
'__NAMESPACE__'正是:
'__NAMESPACE__' => 'Application\Controller',cf: https : //github.com/zendframework/ZendSkeletonApplication/blob/master/module/Application/config/module.config.php#l32
我们尝试在我们的模块路由器配置中使用没有引用:
__NAMESPACE__ => 'Application\Controller',但它似乎打破了配置。
为什么我们使用引号代替
__NAMESPACE__得到它的价值?
in ZF2 skeleton, router configuration uses a key :
'__NAMESPACE__'precisely :
'__NAMESPACE__' => 'Application\Controller',cf: https://github.com/zendframework/ZendSkeletonApplication/blob/master/module/Application/config/module.config.php#l32
We tried in our modules router config to use without quote:
__NAMESPACE__ => 'Application\Controller',but it seems to break configuration.
why do we use quote instead of
__NAMESPACE__to get its value ?
最满意答案
因为默认情况下,配置文件没有声明名称空间。 配置解析器可以读取字符串
'__NAMESPACE__'
并正确确定命名空间。
如果要在没有引号的情况下使用它,可以在配置文件中声明:
namespace Application;并使用__NAMESPACE__而不引用。
这就是为什么你有时会在教程中看到Doctrine config的样本:
'doctrine' => array( 'driver' => array( 'application_entity' => array( 'class' => 'Doctrine\ORM\Mapping\Driver\AnnotationDriver', 'paths' => __DIR__ . '/../src/' . __NAMESPACE__ . '/Entity', ), 'orm_default' => array( 'drivers' => array( __NAMESPACE__ . '\Entity' => 'application_entity', ) ) ) ),because by default, config files hasn't namespace declared. Config parser can read string
'__NAMESPACE__'
and determine correctly the namespace.
If you want to use it without quotes, you can declare in your config file :
namespace Application;and use __NAMESPACE__ without quote.
That's why you can see sometimes in tutorials for Doctrine config's sample like :
'doctrine' => array( 'driver' => array( 'application_entity' => array( 'class' => 'Doctrine\ORM\Mapping\Driver\AnnotationDriver', 'paths' => __DIR__ . '/../src/' . __NAMESPACE__ . '/Entity', ), 'orm_default' => array( 'drivers' => array( __NAMESPACE__ . '\Entity' => 'application_entity', ) ) ) ),更多推荐
发布评论