首页 \ 问答 \ 在Zend Framework 2中隐藏模块名称(Hiding Module name in Zend Framework 2)

在Zend Framework 2中隐藏模块名称(Hiding Module name in Zend Framework 2)

我刚刚从Zend Skeleton Application创建了一个ZF2应用程序。 骨架的默认路由需要URL中的模块名称。 例如,要在应用程序模块中的索引控制器中调用索引操作,我必须键入URL,如http://localhost/application/index/index

我想省略url中的模块名称( 因为我只需要一个模块用于我的想法 )所以如果我输入http://localhost/index/index ,我会得到相同的结果。

我尝试更改application / config中的默认module.config.php文件,如下所示 -

<?php

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',
                    ),
                ),
                '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(   
                                'action' => 'index',
                                '__NAMESPACE__' => 'Application\Controller'                             
                            ),
                        ),
                    ),
                ),
            ),            
        ),
    ),
    'service_manager' => array(
        'factories' => array(
            'translator' => 'Zend\I18n\Translator\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' => 'Application\Controller\IndexController',
            'Application\Controller\Home' => 'Application\Controller\HomeController',
        ),
    ),
    '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',
        ),
    ),
);

但它不起作用。 谁能帮我?


I just created a ZF2 application from Zend Skeleton Application. The default routing of the skeleton needs the Module name in the URL. For example, to invoke index action in index controller in application module, i have to type the url like http://localhost/application/index/index.

i want to omit the module name from the url (because i will only need one module for what i have in mind) so that if i type http://localhost/index/index, i would get the same result.

i tried changing the default module.config.php file in application/config like this -

<?php

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',
                    ),
                ),
                '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(   
                                'action' => 'index',
                                '__NAMESPACE__' => 'Application\Controller'                             
                            ),
                        ),
                    ),
                ),
            ),            
        ),
    ),
    'service_manager' => array(
        'factories' => array(
            'translator' => 'Zend\I18n\Translator\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' => 'Application\Controller\IndexController',
            'Application\Controller\Home' => 'Application\Controller\HomeController',
        ),
    ),
    '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',
        ),
    ),
);

but it's not working. can anyone help me?


原文:https://stackoverflow.com/questions/14600041
更新时间:2022-03-08 13:03

最满意答案

在这里,int / int将返回int只是这里22/7发生的事情给出3并且你输入它给float(3)给出3.0,但是如果你将执行float / int或int / float那么它将结果浮动,所以你将它们中的任何一个转换为浮动,如下所示。

float(22)/7替换float(22/7)


Here, int/int will return int only that is what happening here 22/7 gives 3 and you're type casting it to float(3) which is giving 3.0 but if you will perform float/int or int/float then it will result into float so you convert any of them to float as shown following.

replace float(22/7) with float(22)/7

相关问答

更多
  • 也就是python2与python3的区别了 python 3.5.2是最新版的python3 python 2.7.12是最新版的python2,这个版本是为了兼容以前版本的python又引入了一些新的功能。
  • 首先确定你的项目的工作目录在哪里,假设你有一个名为FolderX的目录。 转到目录的位置,按住shift并右键单击它,然后从右键单击选项中单击“在此处打开终端”。现在,您已在该目录中打开terminal/cmd ,输入venv\Scripts\activate.ba t或venv\Scripts\activate 。 确保在特定路径中有activate.py或activate.bat 。 如果没有安装,你也可以试试这个: pip install virtualenv 如果已安装它,则为该项目创建另一个虚 ...
  • 您必须首先执行SQL语句"PRAGMA case_sensitive_like = on" ,然后它应该工作。 You have to execute the SQL statement "PRAGMA case_sensitive_like = on" first, then it should work.
  • 您应该为3.6版编写代码的方式如下所示: https://github.com/zopefoundation/RestrictedPython 在“有问题的代码示例”下。 即,以下代码将起作用,即open将不会定义: from RestrictedPython import compile_restricted from RestrictedPython import safe_builtins source_code = """ open('/etc/passwd') """ byte_code = c ...
  • 问题不在于return JsonResponse({'status': '1'}) 。 回溯向您显示Django尝试保存Django会话时发生错误。 你必须在视图中做这样的事情: request.session['my_key'] = b'bytes' 对于该示例,您必须解码bytes对象(或使用字符串): request.session['my_key'] = b'bytes'.decode('utf-8') The problem isn't return JsonResponse({'status ...
  • 仅指定宽度也适用于浮点数字。 问题是宽度也包含小数点。 例如,做: "%10f" % math.pi # ' 3.141593' 如您所见,该字符串的长度为10个字符。 这里要考虑的另一件事是,默认情况下,python将输出6个小数点,所以“%3f”与“%3.6f”相同。 >>> "%3f" % math.pi '3.141593' >>> "%3.6f" % math.pi '3.141593' >>> 这就是为什么你没有得到预期的输出'3.1' 。 为了实现这一点,并了解您应该指定的以前的概念: ...
  • 在这里,int / int将返回int只是这里22/7发生的事情给出3并且你输入它给float(3)给出3.0,但是如果你将执行float / int或int / float那么它将结果浮动,所以你将它们中的任何一个转换为浮动,如下所示。 用float(22)/7替换float(22/7) Here, int/int will return int only that is what happening here 22/7 gives 3 and you're type casting it to floa ...
  • 我强烈建议使用virtualenv,并且永远不要修改系统python,除非必要时安装pip和virtualenv。 如上所述,许多操作系统都依赖于工作python2才能运行。 所以... apt-get remove python3 apt-get install python3 pip3 install virtualenv virtualenv -p python3 venv . venv/bin/activate # now you are in a nice python3 world, compl ...
  • 为Python 3.6更改了字节码格式,但我只是将更改推送到cx_Freeze,增加了对它的支持。 您可以自己编译或等待下一个版本 - 这应该是本周的某个时间。 The bytecode format changed for Python 3.6 but I just pushed a change to cx_Freeze that adds support for it. You can compile it yourself or wait for the next release -- which ...

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。