2013-05-07 46 views
0

我想重定向到一個使用外部js文件的控制器,以便我的url地址欄看起來像[這不是鏈接](http:/project/index.php/TravellerController/create/1 ) 我在JavaScript代碼如下所示:php codeigniter uri

u55.style.cursor = 'pointer'; 
$axure.eventManager.click('u55', function(e) { 

if (true) { 
self.location.href=$axure.globalVariableProvider.getLinkUrl('TravellerController'); 

} 
}); 

的U55是我的「家」的意見鏈路標識符文件 我TravellerController看起來是這樣的:

<?php 
class TravellerController extends CI_Controller { 
public function index()           
{ 
$data=$this->get_data(); 
} 
function get_data(){ 
*some code...* 
redirect('TravellerController/create/'.$data); 
{ 
function create(){ 
*some code...* 
} 
} 
?> 

所以,如果我點擊該鏈接我的網址地址字段,然後看起來像這樣:

[這不是一個鏈接](HTTP:/project/index.php/home/create/TravellerController)

但我想它看起來像這樣:

[這不是一個鏈接](http:/project/index.php/TravellerController/create/1)

+0

換句話說,即使在不同的用戶登錄時,它也只能得到相同的一行數據 – 2013-05-07 13:15:21

回答

0

從我的角度來看,您沒有從基於用戶標識的數據庫獲取登錄用戶。當用戶登錄時,您將值存儲在會話中,這很好,但您需要在數據庫中找到登錄的用戶。

添加新的功能,你的模型:

function getUser($userid) { 
    $this->db->select('*'); 
    $this->db->from('profile'); 
    $this->db->where('id', $userid); 
    $query = $this->db->get()->result(); 
    return $query; 
} 

而在你的控制人變更情況:

$data['info'] = $this->profileModel->get_all_info(); 

$data['info'] = $this->profileModel->getUser($session_data['id']); 

我不能完全肯定你2個表,所以上面的代碼基本上是一個例子。如果您的用戶名在表中是唯一的,您也可以使用它從數據庫中獲取正確的用戶。

我希望這會有所幫助。

+0

好的,我確實做到了,但我在瀏覽器中得到了這個錯誤 – 2013-05-07 13:56:07

+0

你可以在你的控制器中做一個var_dump,有用戶?的var_dump($數據[ '信息']); – Bananam00n 2013-05-07 14:00:24

+0

確定我確實做到了,但我得到了我的瀏覽器「 一個PHP錯誤遇到 嚴重性這個錯誤:警告 消息:的foreach提供了無效的參數() 文件名:查看/ profile.php 行號:51「 和這行第51行包含此代碼」<?php foreach($ info as $ u_key){?>「我已將此代碼放入我的視圖中,以便它會填充即從db讀取並顯示用戶配置文件信息例如他的頭銜和國家。在$ info數組中傳遞的數據來自「function update_info($ data,$ id)」,就像在我的模型中一樣,並且在控制器中我使用$ data ['info'] = $ this-> profileModel-> get_all_info(); – 2013-05-07 14:02:37