1

如何在codeigniter的一个控制器中使用两个视图

public function myaccount($user_id) {

    $this->load->model('blog');

    if(isset($_POST['post'])){
    if(strlen($_FILES['inputUpProfile']['name']) > 0) 
    {
    $pic = $this->do_upload('inputUpProfile');

    if ($this->input->post('post') == ''){$type="image";} else {$type="image-with-text";}
    }

    else {$pic = ""; $type = "text"; }

        $result = $this->blog->addPost($user_id, $type  , $this->input->post('post'),$pic);
    }
    if(isset($_SESSION['user_id']) || !empty($_SESSION['user_id'])){
    $result = $this->blog->getPost($user_id, 0 , 10);
    $this->template->build("profile" , array("response"=>$result));     
    }
    else{
    $this->template->build('registration_view',$this->data);
    }


    $this->data['user'] = $user;
    $this->data['errors'] = $this->errors;
    $this->template->set_layout('myaccount');
$this->template->build('profile',$this->data);
    $this->template->build('post_profile',$this->data);

    }
}

这个 ic 控制器功能必须打开两个视图,但我的问题是打开一个视图。

4

1 回答 1

0

试试喜欢

$this->data['myaccount'] = $this->template->set_layout('myaccount');
$this->data['profile'] = $this->template->build('profile',$this->data);
$this->template->build('post_profile',$this->data);

myaccount您可以从和访问另外两个视图profile

或在您的视图文件中调用其他 2 个视图,如 post_profile 页面中的尝试

$this->template->build('profile',$profile);

该 $profile 将从分配给post_profile视图的控制器中获取

于 2013-08-21T06:06:22.863 回答