如何在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控制器函数必须打开两个视图,但我的问题是打开一个视图。
答案 0 :(得分: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
视图