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

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.
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_body_view', $data);

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.??

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:
$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)


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:
function display_form()
    // display form.

function process_form()

    // 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!

Hey thanks for reply. In the example given, what code would be in the display function?

I always load a main template and include other templates that I might need from that template. For instance:

// Put stuff in data array to send to view

<?php require_once 'page_head.php'; ?>

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

<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 id="footer">
    &lt;?php require_once 'footer.php'; ?&gt;

&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.

[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.