打开 phpcms目录 找到base.php
我们在最下面添加一个方法。如下图:
public static function load_router(){ $router = self::load_sys_class('router'); $config = self::load_config('urlrouter');//读取从写配置文件 $router->init($config); return $router; }好了继续
打开 phpcms\libs\classes\param.class.php
找到
if(!get_magic_quotes_gpc()) { $_POST = new_addslashes($_POST); $_GET = new_addslashes($_GET); $_REQUEST = new_addslashes($_REQUEST); $_COOKIE = new_addslashes($_COOKIE); }在他下面添加3行
$route = pc_base::load_router()->parseRequest(); if($route){ @list ( $_GET['m'], $_GET['c'], $_GET['a'] ) = explode ( '/', $route, 3 ); }打完收工。
接着下载附件解压出来class放倒phpcms\libs\classes目录下
怎么使用,默认情况下
支持 /admin/index/login?usename=admin 或者 /admin/index/login.html?username=admin这种风格的解析
没考虑API入口,因为兼容原来的嘛!
想要自定义URL咋办,好跟我来
caches\configs 创建配置文件
urlrouter.php
内容如下
$rules = array ( 'index' => 'content/index/index',//首页 'search' => 'search/index/index',//搜索 'register' => 'member/index/register',//注册 'login' => 'member/index/login',//登录 //'<application:\w+>/<controller:\w+>/<action:\w+>' => '<application>/<controller>/<action>', //'<application:\w+>/<controller:\w+>' => '<application>/<controller>/index', //'<application:\w+>' => array('<application>/index/index','bbb'=>'ccc'), ); return array ( 'enablePrettyUrl' => true, 'rules' => $rules, 'showScriptName' => false, 'suffix' => '.html', );好了。
怎么创建这么NB的URL呢?
在来
还记得$route = pc_base::load_router()->parseRequest();这样代码不?
好 $url=pc_base::load_router()->createUrl('member/index/login',array('user'=>'aaa'));
自动生成 /login.html?user=aaa 咋样神器吧!
要带上域名咋整?
$url=pc_base::load_router()->createAbsoluteUrl('member/index/login');
自动生成 http://xxx.xxx.xxx/login.html咋样神器吧!
附件下载router.class.php.zip
还忘记了一点要想隐藏index.php
那么根据自己的服务器对号入座吧web.config
<?xml version="1.0" encoding="UTF-8"?> <configuration> <system.webServer> <rewrite> <rules> <rule name="URL Rewrite 1" stopProcessing="true"> <match url="^(.*)$" /> <conditions logicalGrouping="MatchAll"> <add input="{HTTP_HOST}" pattern="^(.*)$" /> <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" /> <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" /> </conditions> <action type="Rewrite" url="index.php/{R:1}" /> </rule> </rules> </rewrite> </system.webServer> </configuration>nginx
server { listen ****; server_name domain.com; root document_root; index index.php index.html index.htm; if (!-e $request_filename) { rewrite ^/(.*) /index.php/$1 last; } }apache
<IfModule rewrite_module> Options +FollowSymLinks IndexIgnore */* RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . index.php </IfModule> # 以下是一些文件的缓存设置,可修改或去掉 <IfModule expires_module> ExpiresActive On ExpiresByType text/css "access plus 3 days" ExpiresByType image/png "access plus 14 days" ExpiresByType image/gif "access plus 14 days" ExpiresByType image/jpeg "access plus 14 days" ExpiresByType application/x-shockwave-flash "access plus 28 days" </IfModule>Lighttpd
$HTTP["host"] =~ "(www.)?domain.com$" { url.rewrite = ( "^/(.+)/?$" => "/index.php/$1", ) }除此之外在模板中如何使用呢?
在global.func.php文件的最底下添加如下代码
function U($route,$parameter = array()){ return pc_base::load_router()->createAbsoluteUrl($route,$parameter); }那么在模板中可以直接使用
如 {U('member/index/login',array('aa'=>'bb'))}