2017-08-09 37 views
0

如果我在我的網頁的類別/索引/ $ 1網站上,並且想要回電到domain.com/home,則不適用於我。Codeigniter 3 - 如何回撥到家

這就是我的路線

$route['default_controller'] = 'home'; 
$route['404_override'] = ''; 
$route['translate_uri_dashes'] = FALSE; 
$route['admin'] = 'admin/login'; 
$route['category/(:any)'] = 'category/index/$1'; 
$route['category/(:any)/(:num)'] = 'category/index/$1/$2'; 
$route['page/(:any)'] = 'page/index/$1'; 

如果我叫domain.com/about並點擊我的導航「家」,它的工作。但是,如果我讓他domain.com/aboutdetails/index/1就在家點擊這一個:

domain.com/aboutdetails/index/home

htaccess的

#RewriteEngine on 
#RewriteCond $1 !^(index\.php|images|robots\.txt|style|cdn|check\.php) 

RewriteEngine on 
#RewriteBase/
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.*)$ index.php?/$1 [L] 
+1

我們展示了'$航線的代碼 –

+0

重新排序的地方[ '類別/(:任何)/(:NUM)'] = '類別/索引/ $ 1/$ 2';'和'$路線[」 category /(:any)'] ='category/index/$ 1';'。 – Tpojka

+0

你可以讓我們瞭解你的控制器和視圖嗎? –

回答

0

我想,你可以使用:

<a href="<?php echo base_url()?>home">Home</a> 
+0

那也是我的第一個想法。但如果我的儀表板上的創建者現在是外部鏈接>他使domain.com/domainextern.com/所以我不能使用這 –

+0

我不明白。 –

+0

你能解釋更多嗎? –

0

如果你想使用你的配置路由器回家使用domain.com。 如果你想使用domain.com/home添加下一行路線:

$route['home'] = 'home/index'; 

Considerer使用初始連接和限幅器(正則表達式),例如:

$route['^home$'] = 'home/index'; 

好,要打印鏈接不使用base_url(),它用於加載資產或其他返回項目根目錄,使用site_url()。

在application/config.php文件設置爲空把$ config [ 'index_page']:

//$config['index_page'] = 'index.php'; 
$config['index_page'] = ''; 

,然後創建SITE_URL()鏈接:

site_url('home'); 

如果你想創建鏈接與更多的參數,你可能會傳遞數組。

site_url(array('home', $param2));