在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
最满意答案
在这里,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)
withfloat(22)/7
相关问答
更多-
萧山劲松小学新伟业电脑培训中心人民路206号[2023-05-18]
22 -
python 3.5.2和2.7.12的区别[2022-07-30]
也就是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 ...
-
在python 2.7.12中格式化(formatting in python 2.7.12)[2023-11-16]
仅指定宽度也适用于浮点数字。 问题是宽度也包含小数点。 例如,做: "%10f" % math.pi # ' 3.141593' 如您所见,该字符串的长度为10个字符。 这里要考虑的另一件事是,默认情况下,python将输出6个小数点,所以“%3f”与“%3.6f”相同。 >>> "%3f" % math.pi '3.141593' >>> "%3.6f" % math.pi '3.141593' >>> 这就是为什么你没有得到预期的输出'3.1' 。 为了实现这一点,并了解您应该指定的以前的概念: ... -
不同的结果22/7在python 2.7.12和3.6 [重复](different result 22/7 on python 2.7.12 and 3.6 [duplicate])[2023-08-12]
在这里,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(Freezing Python 3.6)[2022-07-14]
为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 ...