ZF2 ZendSkeleton为什么在默认路由中使用'

编程入门 行业动态 更新时间:2024-10-26 14:31:57
ZF2 ZendSkeleton为什么在默认路由中使用'__NAMESPACE__'键?(ZF2 ZendSkeleton why using '__NAMESPACE__' key in default route?)

在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', ) ) ) ),

更多推荐

本文发布于:2023-07-16 07:26:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1125421.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:路由   ZendSkeleton

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!