我试图在查看他们的页面时将用户 ID 附加到 URL,或者在查看另一个用户页面时将用户 ID 附加到 URL。我收到此错误Unable to load the requested file: account/profile/218.php
代码:
//路由.php
$route['default_controller'] = "home";
$route['404_override'] = '';
$route['profile/:num'] = "account/profile";
//I've also tried doing
$route['profile/([a-z]+)/(\d+)'] = "profile/$1/id_$2";
//没有产生上述错误的uri段的控制器:
public function profile()
{
$this->load->helper('date');
$this->load->library('session');
$session_id = $this->session->userdata['id'];
$this->load->model('account_model');
$user = $this->account_model->user();
$data['user'] = $user;
$data['profile_icon'] = 'profile';
$data['main_content'] = 'account/profile/'.$user['id'];
$this->load->view('includes/templates/profile_template', $data);
}
当我使用这个时:
public function profile()
{
$this->load->helper('date');
$this->load->library('session');
$session_id = $this->session->userdata['id'];
$this->load->model('account_model');
$user = $this->account_model->user();
$data['user'] = $user;
$user['id'] = $this->uri->segment(4);
$data['profile_icon'] = 'profile';
$data['main_content'] = 'account/profile/'.$user['id'];
$this->load->view('includes/templates/profile_template', $data);
}
它会产生此错误:
无法加载请求的文件:account/profile/.php
* *编辑
HTACCESS
Deny from all
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]