0

ページを表示するときにユーザーIDをURLに添付しようとしています。または、別のユーザーのページを表示するときに同じことを行います。Unable to load the requested file: account/profile/218.phpこのコードでこのエラーが発生しています:

//Routes.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]
4

2 に答える 2

1

使用する:

$route['profile/:num'] = "account/profile/$1";

設定ファイルの index.php を削除します

于 2013-02-07T21:32:48.803 に答える
1

application/config/routes.phpファイルに、

$route['profile/(:num)'] = "account/profile/$1";

ここで読むことができるルーティングの詳細

public function profile( $user_id ) 
{

    $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'] = $user_id;
    $data['profile_icon'] = 'profile';
    $data['main_content'] = 'account/profile/'.$user['id'];
    $this->load->view('includes/templates/profile_template', $data);

}

profile メソッドに追加のパラメーターを追加します。このパラメーターはユーザー ID になるため、このメソッド$user['id'] = $user_id;を使用する必要はありません$this->uri->segment(4);

htaccess ファイルを次のように変更することをお勧めします。

<IfModule mod_rewrite.c>
    RewriteEngine On

    RewriteCond %{SCRIPT_FILENAME} -d [OR]
    RewriteCond %{SCRIPT_FILENAME} -f
    RewriteRule "(^|/)\." - [F]

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
于 2013-02-08T21:29:03.343 に答える