Welcome Guest, Not a member yet? Register   Sign In
Advice regarding best practices with Codeigniter
#1

[eluser]epseix[/eluser]
Guys, I am looking for a bit of advice regarding structure and/or best practice for page content through Codeigniter MVC.

My website template takes the standard structure of having a main content section on every page (populated by MySQL), with a static header, footer and sidebar of common links, features etc.

I've learned how to work with the database and Codeigniter MVC and as far as my main content goes.

However... I now need to begin to populate the data for my sidebar and header/footer etc. - and I'm unsure about the best way to instigate other MySQL queries around the main query to do this.

Is auto-loading the most readily-used solution?

Would I create these queries in a helper, or would I have to load with every controller?

I suppose my real question is - what does everybody else do?
#2

[eluser]satie[/eluser]
Too many questions. Post an example.
#3

[eluser]epseix[/eluser]
[quote author="satie" date="1371073149"]Too many questions. Post an example.[/quote]

Sure.

Question 1:-

My view file requires output from 2 separate mySQL queries - how do I implement a second mySQL query into the MVC framework of Codeigniter?

(Although I think this should probably be in the Coding forum)

Question 2:-

Is this (ie. a second or third mySQL query) the best method for generating data for the likes of a header, footer, sidebar etc.

eg. my sidebar contains a list of links for last 5 blog entries which are stored in the database.

Regards,
#4

[eluser]satie[/eluser]
Ok:

Controller:
Code:
public function riepilogo()
{
    $data['first_query'] = $this->model_db->function_one();
    $data['second_query'] = $this->model_db->function_two();
    $data['main_content'] = array(
        'view_header'
        , 'view_two'
        , 'view_footer'
    );
    $this->load->view('templates/main', $data);  
}

In templates/main:

Code:
if (isset($main_content)) {                  
     foreach ($main_content as $mc) {
        $this->load->view($mc);
    }
}




Theme © iAndrew 2016 - Forum software by © MyBB