Codeigniter GET ID有多个页面

时间:2016-09-11 13:22:09

标签: php codeigniter

我使用Codeigniter框架创建一个网站,我搜索在URL中创建具有相同数据的多个页面,但我不知道它的调用方式..

我的用户个人资料(user/profile)带有ID(user/profile?id=2)。 但我希望,另一个具有相同信息的页面看起来像user/profile?id=2/maps,因为user/maps?id=2很复杂而不是逻辑......

怎么做到这个?怎么称呼?

另一个小问题,如何用Username替换“2”?比如user/handleruser/handler/maps

2 个答案:

答案 0 :(得分:0)

你可以使用User控制器和profile()函数在codeigniter中调用简单的函数。作为参考,你可以参考下面的代码:

class User extends CI_Controller {

public function __construct()
{
    parent::__construct();
}

public function profile($id=0,$page='')
{
    //do your logic here depending on the parameters above        
}

所以你可以像这样打电话

http://your_base_url/user/profile/2
http://your_base_url/user/profile/2/map

如有任何疑问,请与我联系。

答案 1 :(得分:0)

感谢您的回答@Zeeshan。 实际上,我的控制器看起来像这样:

类用户扩展CI_Controller {

public function profil()
{
    // Récupération de l'ID dans l'url
    $this->data['id'] = $this->input->get('id', TRUE);

    // Statistiques du profil
    $this->data['countReview'] = $this->review_model->countReview($this->data['id']);

    // Chargement du profil de l'utilisateur
    if (ctype_digit($this->data['id'])) {
        if ($this->user_model->getUser($this->data['id'])) {
            $this->data['users'] = $this->user_model->getUser($this->data['id']);
            $this->data['reviewsNext'] = $this->review_model->getReviewsByUser_Next($this->data['id']);
            $this->data['reviewsPrevious'] = $this->review_model->getReviewsByUser_Previous($this->data['id']);
        } else {
            $this->session->set_flashdata('error', 'Utilisateur introuvable.');
            redirect(site_url());
        }
    } else {
        $this->data['error_report'][] = "Utilisateur introuvable.";
        redirect(site_url());
    }

    $this->load->view('template/header');
    $this->load->view('template/menu');
    $this->load->view('user/profil', $this->data);
    $this->load->view('template/footer');
}

什么是$ id = 0,$ page =''?

感谢

相关问题