Sunday, 15 May 2011

php - CodeIgniter - Controller - loading view with template -



php - CodeIgniter - Controller - loading view with template -

i have template design each page , working without issues, have problem form validation , template.

my_controller //inside 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 need phone call page1 1 time again update form error // option1: $this->load->view('page1'); // loading page1, not loading template, template file has header, footer, js , css file includes // option2: $this->template->load('template', 'page1'); // loading page withing page // option3: $this->template->write_view('content', 'page1'); // $this->template->render(); // same option2 } else { $this->load->view('formsuccess'); } }

so question how can phone call same view (within 1 controller) multiple time when loaded template?

edited more clarity

my template file single file ( not separated header, footer) have header info , footer info mutual style sheet , script files. having

<?php $content ?>

variable name within template pass content controller.

for illustration see page1 function(),

$this->template->write('title', 'company'); // write value on variable $this->template->write_view('content', 'page1'); //view page write on template $this->template->render(); // final template render

this page having form validation, if form validation false, how can reload template page validation error?

i have tried many way, please check option1, 2, 3, never got solution solve this, please tell me how can solve this?

if understand correctly, want display validation errors?

inside view file, set following:

short if-statement form:

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

regular if-statement form:

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

validation errors doc

php codeigniter

No comments:

Post a Comment