Php CodeIgniter-控制器-使用模板加载视图

Php CodeIgniter-控制器-使用模板加载视图,php,codeigniter,Php,Codeigniter,我有一个模板设计的每个页面,它是没有任何问题的工作,现在我有一个表单验证和模板的问题 my_controller //inside my controller function __construct() { parent::__construct(); $this->load->library('template'); } public function page1(){ $this->template->write('titl

我有一个模板设计的每个页面,它是没有任何问题的工作,现在我有一个表单验证和模板的问题

my_controller   //inside my controller

function __construct()
{
    parent::__construct();
    $this->load->library('template');     
}


public function page1(){
   $this->template->write('title', 'COMPANY');
   $this->template->write_view('content', 'company');
   $this->template->render();
}

public function validation(){
     //for page1 form validation
     //form validation here

     if ($this->form_validation->run() == FALSE){
         // here i need to call my page1 again to update the form error
         // option1: $this->load->view('page1');  // this is just loading page1, not loading with my template, template file has header, footer, js and css file includes
         // option2: $this->template->load('template', 'page1'); // it is loading page withing page
         // option3: $this->template->write_view('content', 'page1');
         //          $this->template->render();  // this is same as option2
     } else {
     $this->load->view('formsuccess');
 }
}
所以我的问题是,当同一个视图(在一个控制器中)已经加载了模板时,如何多次调用它

为更清晰起见进行了编辑 我的模板文件只是一个单独的文件(不象页眉、页脚那样分开)将包含所有页眉信息和页脚信息以及常见的样式表和脚本文件。 我有

<?php $content ?>
此页面正在进行表单验证,如果我的表单验证为FALSE,如何重新加载带有验证错误的模板页面


我已经尝试了很多方法,请检查我的选项1、2、3,我从未找到解决此问题的解决方案,现在请告诉我如何解决此问题?

如果我理解正确,您想显示验证错误吗

在视图文件中,放置以下内容:

简短的IF声明格式:

<?php if ( validation_errors() ) :?>
<div>
   <?php echo $validation_errors();?>
</div>
<?php endif;?>
<?php if ( validation_errors() ) {?>
<div>
   <?php echo $validation_errors();?>
</div>
<?php }?>

定期If声明格式:

<?php if ( validation_errors() ) :?>
<div>
   <?php echo $validation_errors();?>
</div>
<?php endif;?>
<?php if ( validation_errors() ) {?>
<div>
   <?php echo $validation_errors();?>
</div>
<?php }?>


您的控制器结构非常与众不同。最好先阅读并遵循CodeIgniter文档中的教程和演示。换句话说,您将有一个名为
edit
的控制器函数,可在
yourdomain.com/my_Controller/edit
访问该函数。这一功能将处理
编辑
页面上的所有内容,包括验证和模板输出。此基本CI结构在文档中都进行了非常仔细的解释。请参阅:是的,我知道教程和链接,但当您在带有表单验证的模板中加载页面时,没有解释。您可能知道,但如果您确实阅读了教程,您会看到此页面上的验证代码: