Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何在codeigniter中的一个控制器中使用两个视图_Php_Codeigniter - Fatal编程技术网

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

Php 如何在codeigniter中的一个控制器中使用两个视图,php,codeigniter,Php,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')

如何在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);
您可以从
myaccount
profile

或者在视图文件中调用其他两个视图,如post_profile页面中的

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

该$profile将从控制器获取,并被分配到
post\u profile
view

中,您没有收到任何错误吗?您似乎有一个额外的
}
。你会看到你的代码是否缩进得更好。为什么不从第一个视图调用第二个视图,调用firstview并将第二个视图插入其中it@FayeqAli Khan如何在第一个视图中插入第二个视图我将尝试但仅打开
post_profile
视图而不打开
profile
视图然后尝试第一个ansi将尝试此
$this->data['myaccount']=$this->template->set_layout('myaccount')$此->数据['profile']=$this->template->build('profile',$this->data)$此->模板->构建('post_profile',$this->data)