从网址CakePHP中删除动作叫什么名字

从网址CakePHP中删除动作叫什么名字

本文介绍了从网址CakePHP中删除动作叫什么名字?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用CakePHP的发展我在CakePHP的网站,我想从应用程序URL我该怎么办回回的删除操作(或者视图)的名字。我的要求是我要代替视图名称添加参数最近我的网址是这样的:

但我需要

我的.htaccess文件中包含

的.htaccess在根文件夹

 < IfModule mod_rewrite.c>
   RewriteEngine叙述上
   重写规则^ $ [L]
   重写规则(。*)的应用程序/ Web根目录/的index.php / $ 1 [L]
< / IfModule>
 

的.htaccess在app文件夹

 < IfModule mod_rewrite.c>
  RewriteEngine叙述上
  的RewriteBase / liberty_new / APP /
  重写规则^ $根目录/的index.php / [L]
  重写规则(。*)根目录/的index.php / $ 1 [L]
 < / IfModule>
 

在的.htaccess文件夹根目录

 < IfModule mod_rewrite.c>
 RewriteEngine叙述ON
 的RewriteBase /
 的RewriteCond%{} REQUEST_FILENAME!-d
 的RewriteCond%{} REQUEST_FILENAME!-f
 重写规则^(。*)/ $ 1 [QSA,L]
< / IfModule>
 

解决方案

您这样做在你的配置\ routes.php文件文件。将路由器 PARAMS,因为你需要写的网址。不要编辑htaccess的文件,也可以/会破坏CakePHP的路由。

 路由器::连接('/:控制器/:参数1 /:参数2',阵列('行动'=>索引),阵列('参数1'=> [A-ZA-Z0-9] +','参数2'=>'[A-ZA-Z0-9] +'));
 

本应该将所有requestes任何控制器,该控制器的索引功能,通过PARAMS 1和2。当然,这是可以高度定制。我强烈建议你阅读有关文档路由,从来没有改变htaccess的,除非你不得不这样做。

http://book.cakephp.org/2.0/ EN /开发/ routing.html#路由配置

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:

but I need

My .htaccess files are like below

.htaccess in root folder

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

.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 in webroot folder

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

You do this in your Config\routes.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]+'));

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中删除动作叫什么名字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-05 14:06