• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Page layout system

#1
[eluser]jbads[/eluser]
Hi, I've been wondering how other people deal with the layout of their pages. Here is an example of how I've been doing it.
Code:
function register(){

// any data that may need to be sent to view

                //Set header variables
        $page_header['title']   =   "Registration";
    
        //load page
        $this->load->view('index_header_view', $page_header);
        $this->load->view('index_menu_view');
        $this->load->view('index_body_view', $data);
        $this->load->view('index_sidebar_view');
        $this->load->view('index_footer_view');
}

now if someone loads this page and fills in form the form action goes to the registration processing function, now if there is an error with the data they submitted, ie required fields aren't filled in, it redirects to /register page again but post data is obviously cleared and the user must start the form again.

You see my problem?

So how do the rest of you deal with page layout / templates etc.??

#2
[eluser]mrtopher[/eluser]
I tend to use more of a layout approach. So instead of having three or four templates which I load in and around my content line by line, I have a layouts folder in the views folder which has the overall look and feel and I simply load individual views in those layouts.

For example:
Code:
$page_data = array(
    'some_content' => 'some content'
);

$temp_data = array(
    'page_title' => 'Some title',
    'left_column' => $this->load->view('navigation',0,TRUE),
    'right_column' => $this->load->view('form',$page_data,TRUE)
);

$this->load->view('layouts/page_layout',$temp_data);


In regards to your validation question, I don't redirect the users. I simply make a call to the form display function from within the process function.

For example:
Code:
function display_form()
{
    // display form.
}

function process_form()
{
    $this->load->library('validation');

    // validation rules

    if($this->validation->run() == FALSE) {
        $this->display_form(); // displays form and still have access to post data.
    }
    else {
        // do processing
    }
}

Hope this helps!

#3
[eluser]jbads[/eluser]
Hey thanks for reply. In the example given, what code would be in the display function?

#4
[eluser]JoostV[/eluser]
I always load a main template and include other templates that I might need from that template. For instance:

Controller:
Code:
// Put stuff in data array to send to view
$this->load->view('form',$this->data);

View:
Code:
<?php require_once 'page_head.php'; ?>

<div id="navbar">
    &lt;?php require_once 'navbar.php'; ?&gt;
</div>

<div id="content">
    &lt;?php require_once $data['content_view']; // Controller sets the proper content view file in $this->data['content_view'], so we load that file ?&gt;
</div>

<div id="footer">
    &lt;?php require_once 'footer.php'; ?&gt;
</div>

&lt;?php require_once 'page_tail.php'; ?&gt;

Since the subview files are included in the main view file tehy also have acces to any data in $this->data.

#5
[eluser]louis w[/eluser]
I built a custom library which wraps a view. The wrapper contains the header, footer and common includes. Then I call the library either with a view (which then gets called by the wrapper) or give it a data strng which gets included in the wrapper.

It's quite handy.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.