繁体   English   中英

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

[英]How to use two views in one controller in codeigniter

如何在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控制器功能必须打开两个视图,但是我的问题是打开一个视图。

尝试像

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

您可以从myaccountprofile myaccount访问其他两个视图

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

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM