CodeIgniter Forums
Best practise for forms and multiple views? - Printable Version

+- CodeIgniter Forums (
+-- Forum: Archived Discussions (
+--- Forum: Archived Development & Programming (
+--- Thread: Best practise for forms and multiple views? (/thread-40288.html)

Best practise for forms and multiple views? - El Forum - 04-05-2011

Hi, a hopefully easy question about how best to use a Controller and multiple Views to display a Form and submit it.

We are converting a small app to CI and not 100% sure how to best go about it, here is one example of a page that has a 8 views, as I've broken up our previous page into separate chunks as you can see below.

1. Is this best practise? It seems messy and unnecessary to have so many different views...

2. Also for my form, its 1/2 way down the page and preferably could be called from the 'keyword2/table' view to get it in the right spot for HTML code, but I know this is a big no no...

3. Should I be saving details to the DB in the Controller, as shown in my PHP comments?

Suggestions are welcomed.


function table($website_name = '', $website = '')
        $data['website'] = $website;
        $data['website_name'] = $website_name;

        // load our Custom SEO Library

        $data['meta_title'] = 'Dashboard';
        $this->load->view('header', $data);
        $this->load->view('menu_top', $data);

        $data['engine_id'] = $this->seo->get_engine_default();
        $this->load->view('website/dashboard', $data);
        $this->load->view('keyword2/table', $data);

        // edit Keyword Ranking form
        $this->load->helper(array('form', 'url'));

    // form validation, will get to this
    //$this->form_validation->set_rules('username', 'Username', 'required|min_length[5]|max_length[12]');

        if ($this->form_validation->run() == FALSE)
            $this->load->view('keyword2/edit', $data);
            // save stuff to db I guess?

            // ..then show Success view
            $this->load->view('keyword2/edit/success', $data);

        // Footer
        $this->load->view('footer', $data);