Welcome Guest, Not a member yet? Register   Sign In
Including multiple views
#1

[eluser]phpgeek[/eluser]
Hello everyone,
I'm having a bad time trying to show validation errors from multiple view files, it doesn't show them, see my code:
Code:
/*Prepago controller*/
    function index()
    {
        //Conseguir los planes        
        $comboPlanes= $this->getPlanes();
        
        //Elementos de página
        $data = array(
               'title' => 'Clientes por plan prepago',
                'Fecha' => $this->setFormPrepago(),
                'comboPlanes' => $comboPlanes,
                'comboStatus' => $this->setFormPrepago(),
                'comboModelo' => $this->getModeloEquipo()
          );
        $this->load->view('header', $data);
        $this->load->view('prepago/instrucciones');
        $this->load->view('welcome_message', $data);
        $this->load->view('prepago/form_pre_plan', $data);
        $this->load->view('footer');
    }
Code:
/*form_pre_plan view*/
<?php echo validation_errors();
      echo form_open('validation', array('name'=>'myform')); ?>
<table class="art-article" border="0" cellspacing="0" cellpadding="0">
  <tbody>                                        
    <tr>
      <td>Plan</td>
      <td>&lt;?php  echo form_dropdown('cmbPlanes', $comboPlanes, '177'); ?&gt;</td>                                                  
    </tr>                                              
  </tbody></table>                                              
  </p>
<p>
    <a class="art-button">Procesar</a>    
</p>
&lt;?php echo form_close();?&gt;
Once i submit, i validate this form using:
Code:
/*Validation controller*/
function index()
    {    
        $this->load->model('PrepagoModel');        
        $this->load->library('form_validation');
        $criteria= array('plan'=> $this->input->get_post('cmbPlanes', TRUE));
        $this->form_validation->set_message('required', 'Your custom message here');
        $config = array(array('field'   => 'cmbPlanes', 'rules'   => 'required'));
        $this->form_validation->set_rules($config);
        if ($this->form_validation->run() == FALSE){    
            //Go back to form_pre_plan and associate views (i can do this but it shows errors since it doesn't pass $data array)
            $this->load->view('header', $data);
            $this->load->view('prepago/instrucciones');
            $this->load->view('welcome_message', $data);
            $this->load->view('prepago/form_pre_plan', $data);
            $this->load->view('footer');            
            //I've tried this but it doesn't show validation errors and it misses other views
            redirect('prepago/form_pre_plan', 'location');
        }
        else{    
            $this->load->view('formsuccess');
            $arrPrepago= $this->PrepagoModel->selectPrepago($criteria);
        }
Is there any way to redirect to all those views or put them together to just show validation errors?

also i tried to do a view that includes all my views like this one..
Code:
/*prepagoIncluder.php*/
include_once 'header.php';
include_once 'prepago/instrucciones.php';
include_once 'welcome_message';
include_once 'prepago/form_pre_plan';
include_once 'footer.php';
And i'd be able to include just one view in my controller like this:
Code:
/*controller*/
$this->load->view('prepagoIncluder');


But this brings me a lot of problems since it fails to include every file in there. I'd appreciate any help here. Any ideas?
#2

[eluser]InsiteFX[/eluser]
This is how to use a view template, you can name it whatever you want.

view file application/views/your-view-name.php
Code:
<!DOCTYPE html>
&lt;html&gt;

&lt;head&gt;

    &lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /&gt;
    &lt;title&gt;&lt;?php echo $title; ?&gt;&lt;/title&gt;
    &lt;link href="&lt;?php echo base_url();?&gt;assest/css/main.css" rel="stylesheet" type="text/css" /&gt;

    [removed]
        //&lt;![CDATA[
            base_url = '&lt;?php echo base_url();?&gt;';
        //]]>
    [removed]

    &lt;!--[if IE 5]>
        &lt;style type="text/css"&gt;
            /* place css box model fixes for IE 5* in this conditional comment */
            .twoColFixLtHdr #sidebar1 { width: 230px; }
        &lt;/style&gt;
    <![endif]--&gt;

    &lt;!--[if lt IE 8]>
        &lt;style type="text/css"&gt;
            /* place css fixes for all versions of IE in this conditional comment */
            .twoColFixLtHdr #sidebar1 { padding-top: 30px; }
            .twoColFixLtHdr #mainContent { zoom: 1; }
            /* the above proprietary zoom property gives IE the hasLayout it needs to avoid several bugs */
        &lt;/style&gt;
    <![endif]--&gt;

&lt;/head&gt;

&lt;body class="twoColFixLtHdr"&gt;

    <div id="container">

        <div id="header">

            <h1>&lt;?php echo $title;?&gt;</h1>

        &lt;!-- end #header --&gt;
        </div>

        <div id="sidebar1">

            &lt;?php $this->load->view('nav'); ?&gt;

        </div>
        &lt;!-- end #sidebar1 --&gt;

        <div id="mainContent">

            &lt;?php $this->load->view($main);?&gt;

        </div>
        &lt;!-- end #mainContent --&gt;

        &lt;!-- This clearing element should immediately follow the #mainContent div in order to force the #container div to contain all child floats --&gt;
        <br class="clearfloat" />

        <div id="footer">

            <p>Copyright &copy; 2010 &lt;?php date('Y');?&gt; By Your Company, Inc | &lt;?php echo anchor('admin/login', 'admin');?&gt;</p>

        </div>
        &lt;!-- end #footer --&gt;

    </div>
    &lt;!-- end #container --&gt;

&lt;/body&gt;

&lt;/html&gt;

css file - root/asset/css/main.css:
Code:
@charset "UTF-8";
body  {
    font: 100% Verdana, Arial, Helvetica, sans-serif;
    background: #666666;
    margin: 0; /* it's good practice to zero the margin and padding of the body element to account for differing browser defaults */
    padding: 0;
    text-align: center; /* this centers the container in IE 5* browsers. The text is then set to the left aligned default in the #container selector */
    color: #000000;
}
.twoColFixLtHdr #container {
    width: 780px;  /* using 20px less than a full 800px width allows for browser chrome and avoids a horizontal scroll bar */
    background: #FFFFFF;
    margin: 0 auto; /* the auto margins (in conjunction with a width) center the page */
    border: 1px solid #000000;
    text-align: left; /* this overrides the text-align: center on the body element. */
}
.twoColFixLtHdr #header {
    background: #DDDDDD;
    padding: 0 10px 0 20px;  /* this padding matches the left alignment of the elements in the divs that appear beneath it. If an image is used in the #header instead of text, you may want to remove the padding. */
}
.twoColFixLtHdr #header h1 {
    margin: 0; /* zeroing the margin of the last element in the #header div will avoid margin collapse - an unexplainable space between divs. If the div has a border around it, this is not necessary as that also avoids the margin collapse */
    padding: 10px 0; /* using padding instead of margin will allow you to keep the element away from the edges of the div */
}
.twoColFixLtHdr #sidebar1 {
    float: left; /* since this element is floated, a width must be given */
    width: 200px; /* the actual width of this div, in standards-compliant browsers, or standards mode in Internet Explorer will include the padding and border in addition to the width */
    background: #EBEBEB; /* the background color will be displayed for the length of the content in the column, but no further */
    padding: 15px 10px 15px 20px;
}
.twoColFixLtHdr #mainContent {
    margin: 0 0 0 250px; /* the left margin on this div element creates the column down the left side of the page - no matter how much content the sidebar1 div contains, the column space will remain. You can remove this margin if you want the #mainContent div's text to fill the #sidebar1 space when the content in #sidebar1 ends. */
    padding: 0 20px; /* remember that padding is the space inside the div box and margin is the space outside the div box */
}
.twoColFixLtHdr #footer {
    padding: 0 10px 0 20px; /* this padding matches the left alignment of the elements in the divs that appear above it. */
    background:#DDDDDD;
}
.twoColFixLtHdr #footer p {
    margin: 0; /* zeroing the margins of the first element in the footer will avoid the possibility of margin collapse - a space between divs */
    padding: 10px 0; /* padding on this element will create space, just as the the margin would have, without the margin collapse issue */
}
.fltrt { /* this class can be used to float an element right in your page. The floated element must precede the element it should be next to on the page. */
    float: right;
    margin-left: 8px;
}
.fltlft { /* this class can be used to float an element left in your page */
    float: left;
    margin-right: 8px;
}
.clearfloat { /* this class should be placed on a div or break element and should be the final element before the close of a container that should fully contain a float */
    clear:both;
    height:0;
    font-size: 1px;
    line-height: 0px;
}

InsiteFX
#3

[eluser]InsiteFX[/eluser]
You can pass all $data like so which will make it global to views:
Code:
$data = array();

$data['title'] = 'Your Title Here'; // ETC.

$this->load->vars($data);

$this->load->view('Your-View-Name');

InsiteFX




Theme © iAndrew 2016 - Forum software by © MyBB