从cakephp中的Url中删除动作名称?

Remove action name from Url in cakephp?(从cakephp中的Url中删除动作名称?)
本文介绍了从cakephp中的Url中删除动作名称?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

可能的重复:
如何从 cakephp 中的 url 中删除动作名称?

我正在使用 cakephp 在 Cakephp 中开发我的网站,我想从应用程序 URL 中删除操作(或视图)名称,我应该怎么做.我的要求是最近我想添加参数来代替视图名称,我的 URL 如下所示:

I am using cakephp to develop my website in Cakephp and I would like to remove action(or view )name from the application URL what should I do fro that. My requirement is I want to add the parameters in place of view name recently my URL is like:

域名/控制器名/视图名/param1/param2"

"domainname/controllername/viewname/param1/param2"

但我需要

域名/控制器名/param1/param2"

"Domainname/controllername/param1/param2"

我的 .htaccess 文件如下

My .htaccess files are like below

根文件夹中的.htaccess

.htaccess in root folder

<IfModule mod_rewrite.c>
   RewriteEngine on 
   RewriteRule    ^$     [L]
   RewriteRule    (.*) app/webroot/index.php/$1 [L]
</IfModule>

.htaccess 在应用程序文件夹中

.htaccess in app folder

 <IfModule mod_rewrite.c>
  RewriteEngine on
  RewriteBase /liberty_new/app/
  RewriteRule    ^$    webroot/index.php/    [L]
  RewriteRule    (.*) webroot/index.php/$1    [L]
 </IfModule>

.htaccess 在 webroot 文件夹中

.htaccess in webroot folder

<IfModule mod_rewrite.c>
 RewriteEngine ON
 RewriteBase /
 RewriteCond %{REQUEST_FILENAME} !-d
 RewriteCond %{REQUEST_FILENAME} !-f
 RewriteRule ^(.*)$ /$1 [QSA,L]
</IfModule>

推荐答案

您在 Config outes.php 文件中执行此操作.设置 Router 参数以根据需要编写 URL.不要编辑您的 htaccess 文件,否则它会/会破坏 CakePHP 路由.

You do this in your Config outes.php file. Set the Router params to write the URL as you need. Do not edit your htaccess files or it can/will break CakePHP routing.

Router::connect('/:controller/:param1/:param2', array('action' => 'index'), array('param1' => '[a-zA-Z0-9]+', 'param2' => '[a-zA-Z0-9]+'));

这应该将所有请求发送到任何控制器到该控制器的索引函数并传递参数 1 和 2.当然,这可以高度定制.我强烈建议您阅读文档中有关路由的内容,除非必须,否则不要更改 htaccess.

This should send all requestes to any controller to the index function of that controller and pass params 1 and 2. Of course, this can be heavily customized. I would strongly suggest you read about routing in the documentation and never alter htaccess unless you have to.

http://book.cakephp.org/2.0/en/development/routing.html#routes-configuration

这篇关于从cakephp中的Url中删除动作名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以
PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的
mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)
Laravel Gmail Configuration Error(Laravel Gmail 配置错误)
Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)
Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)