1
我創建了一個網上商店與供應商系統,我希望每個供應商的個人資料顯示與他的用戶名在URL中。 我現在的地址顯示與身份證號碼一樣我在Codeigniter中創建自定義網址,但發佈數據無法顯示
www.mydomain.com/home/profile/1
我像URL希望我的我的網址顯示的用戶名:
www.mydomain.com/username
我的代碼是在這裏:
型號
//get all vendors
public function vendor_profiles()
{
$where = array('ven_status' => 'Active');
$this->db->select()
->from('vendor_login')
->where($where,'DESC');
$data = $this->db->get();
return $data->result_array();
}
//get single vendor through id number
public function vendor_profile($id)
{
$where = array(
'vendor_id' => $id,
'ven_status' => 'Active',
);
$this->db->select()
->from('vendor_login')
->where($where,'DESC');
$data = $this->db->get();
return $data->first_row('array');
}
Cont輥
//show all vendors profile
public function vendor_profiles()
{
$data['profiles'] = $this->front->vendor_profiles();
$this->load->view('vendors',$data);
}
//show single vendor profile through id
public function profile($id)
{
$data['profile'] = $this->front->vendor_profile($id);
$this->load->view('profile',$data);
}
瀏覽:
//here is show all vendor profiles (vendors.php)
<?php foreach($profiles as $vendor) : ?>
<a href="<?=base_url();?>home/profile/<?=$vendor['vendor_id'];?>"><img src="<?=base_url();?>uploads/<?=$vendor['ven_img'];?>"></a>
<a href="<?=base_url();?>home/profile/<?=$vendor['vendor_id'];?>"><?=$vendor['ven_firstname'];?></a>
<?php endforeach; ?>
//Here is single vendor profile show (profile.php)
<p><img src="<?=base_url();?>uploads/<?=$profile['ven_logo'];?>"></p>
<p><img src="<?=base_url();?>uploads/<?=$profile['ven_img'];?>"></p>
<p>First Name : <?=$profile['ven_firstname'];?></p>
<p>Last Name : <?=$profile['ven_lastname'];?></p>
<p>Username : <?=$profile['username'];?></p>
這裏是我擊潰:
require_once(BASEPATH .'database/DB.php');
$db =& DB();
$query = $db->get('vendor_login');
$result = $query->result();
foreach ($result as $row) {
$rout["home/profile/" . $row->username] = "home/profile/" . $row->vendor_id;
}
$ rout或$ route?請先檢查一下,讓我們知道輸出。 您可以考慮閱讀關於路由的CI教程:https://ellislab.com/codeigniter/user-guide/general/routing.html –