Welcome Guest, Not a member yet? Register   Sign In
Another 'best practice' question about controllers (and PHP classes in general)
#1

[eluser]Bleeding Edge Productions[/eluser]
Hi guys,

Apologies for another best practice question. Assuming:

Code:
class Homepage extends MY_Controller {
    
    /**
     * Set page specific variables
     */
    protected $page_id             = 'pageidhere';
    protected $parent_id           = 'parentidhere';
    protected $page_title          = 'Page Title Goes Here';
    protected $h1_text             = 'Heading 1 Text';
    protected $page_color          = '#fff000';
    protected $bg_position         = '50px 200px';
    protected $h1_margins          = '60px 0px 40px 400px';
    protected $meta_description    = 'Meta description here.';
    protected $meta_keywords       = 'keywords, go, here';
    protected $meta_robots         = 'INDEX,FOLLOW';
    
    // --------------------------------------------------------------------
    
    /**
     * Constructor - inherits site-wide variables from MY_Controller.
     */
    public function __construct() {
        
        parent::__construct();
        
    }
    
    // --------------------------------------------------------------------
    
    /**
     * Generate the page
     */
    function index(){
        
        /**
         * Assign variables to the $pagevars array
         */
        $pagevars['base']                = $this->base;
        $pagevars['assets']              = $this->assets;
        $pagevars['page_id']             = $this->page_id;
        $pagevars['parent_id']           = $this->parent_id;
        $pagevars['page_title']          = $this->page_title;
        $pagevars['h1_text']             = $this->h1_text;
        $pagevars['page_color']          = $this->page_color;
        $pagevars['bg_position']         = $this->bg_position;
        $pagevars['h1_margins']          = $this->h1_margins;
        $pagevars['meta_description']    = $this->meta_description;
        $pagevars['meta_keywords']       = $this->meta_keywords;
        $pagevars['meta_robots']         = $this->meta_robots;
        
        /**
         * Load the view
         */
        $this->load->view('homepage', $pagevars);
        
    }
    
}

Is it best to set the variables as protected variables outside the index() function (as I have done here), rather than directly in $pagevars, or does it make no difference? I only have one page being rendered per controller, so there is no need to have the variables per-function.

Cheers!

Martin


Messages In This Thread
Another 'best practice' question about controllers (and PHP classes in general) - by El Forum - 10-06-2010, 05:03 AM



Theme © iAndrew 2016 - Forum software by © MyBB