2012-12-04 55 views

回答

1
$route['/(:any)'] = "/user_controller/newfunction/$1"; 

,或者嘗試htaccess的

RewriteEngine On 
RewriteRule ^([^/]*)$ /user_controller/newfunction/$1 [L] 
+0

頁面沒有正確重定向錯誤顯示其他網站的URL。 –

+0

你應該記住的東西像 http://www.domain.com/user_controller/newfunction/username 之間的 http://www.domain.com/profile/username –

+0

但在這裏,我要像展示domain.com/username用於此特定控制器。 –

0

/application/config/routes.php

$route['/all/other/routes/must/come/first!'] = "wherever/you/want"; 
$route['/(:any)'] = "/user_controller/newfunction/$1"; 
+0

該頁面沒有正確重定向錯誤顯示其他網站的URL。請用例子來解釋第一個。 –

+0

如果您提供了錯誤的例子,將真正幫助 – Dale

+0

的網頁沒有正確重定向 試圖訪問的網站的其他控制器時,發現下面的錯誤。 Firefox檢測到服務器正在以永不完整的方式重定向該地址的請求。 –

0

它更容易使用的應用程序中發現CI路由系統/配置/ routes.php文件

$route['(:any)'] = 'user_controller/newfunction/$1'; 

不要忘記設置自己的基本網址在應用程序/ config/config.php

$config['base_url'] = 'http://www.domain.com/'; 

添加記住刪除URL中的index.php。編輯.htaccess文件在您的站點

RewriteEngine on 
RewriteCond $1 !^(index\.php|assets|_searches|robots\.txt|favicon\.ico) 
RewriteRule ^(.*)$ /index.php/$1 [L] 
現在在你user_controller

的根源,功能newfunction看起來就像這樣:

<?php if (! defined('BASEPATH')) exit('No direct script access allowed'); 

class user_controller extends CI_Controller { 

    public function __construct() { 
     parent::__construct(); 
     // load things like models, libraries, helpers 
    } 

    function newFunction($slug) 
    { 
     echo 'hello my name is'.$slug; 
    } 
} 

當您訪問http://www.domain.com/nash,你的代碼應該打印出來納什