Welcome Guest, Not a member yet? Register   Sign In
New here - what's the best way of passing data to a view for generating meta titles etc?
#1

[eluser]35mm[/eluser]
OK I'm slowly picking things up here, but I have just been coding controllers to send data to the views for populating meta title, description and keyword tags, and I seem to be writing a lot of code and duplicating it in order to get the job done. Just to get the site name from the config was more long winded than I'd imagined!

Here's the minimum of what I am currently having to put in every function in every model at the moment just to get the site name and generate a title.
Code:
public function index() // select country
    {
        /* get site name and generate page title
        // don't have to generate description and keywords for
        // the join page - praise the lord!
         */
        $site_name = $this->config->item('site_name'); // bit long winded
        $data=array('title'=>'Join ' . $site_name); // zzzzzzzzzz
        // load the view
        $this->load->view('pages/register_country',$data); // is the pub open yet?
    }

So I'm wondering what the best method is for speeding this up? Are there already features built in to CI for doing these things? How can I make it available to all methods in a single controller?
#2

[eluser]CroNiX[/eluser]
Yes, you could have a base controller that does that automatically, and then have your controllers extend that controller instead of CI_Controller. Same with the model. You could also set up a lot in your controllers construct for things specific to that controller.

For more on base controllers, see this older article which allows for multiple base controllers.
http://philsturgeon.co.uk/blog/2010/02/C...ing-it-DRY




Theme © iAndrew 2016 - Forum software by © MyBB