• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
several controller

#1
Hi , sorry for english , in every controller i have :

Code:
Code:
       $this->load->view('templates/header_user',$data);
       $this->load->view('templates/menu_user',$data);
       $this->load->view('controller/view', $data);
       $this->load->view('templates/footer_user',$data);


Because menu_user are used in several controller  and i want send a value  to menu , how can i do this ?
Reply

#2
Create a MY_Controller

Comments on how to use in the header section of the class.

PHP Code:
<?php
defined
('BASEPATH') OR exit('No direct script access allowed');

/**
 * Class Base
 * 
 * File must be saved as MY_Controller.php in
 * ./application/core/MY_Controller.php
 * 
 * Place all your code that is used in all controllers
 * in this controller and then extend all controllers with Base
 * 
 * class Your_Controller extends Base
 * 
 */
class Base extends CI_Controller
{
 
   /**
     * Class properties go here.
     * -------------------------------------------------------------------
     * public, private, protected, static and const.
     */


 
   // -------------------------------------------------------------------

 
   /**
     * __construct ()
     * -------------------------------------------------------------------
     *
     * Class    Constructor
     *
     * NOTE: Not needed if not setting values or extending a Class.
     */
 
   public function __construct()
 
   {
 
       parent::__construct();

 
       log_message('debug'"Base Controller Class Initialized");
 
   }

 
   /**
     * index ()
     * -------------------------------------------------------------------
     *
     */
 
   public function index()
 
   {

 
   }

 
   // -------------------------------------------------------------------

  // End of Base Controller Class.

/**
 * Class Backend
 */
class Backend extends Base
{
 
   /**
     * Class properties go here.
     * -------------------------------------------------------------------
     * public, private, protected, static and const.
     */


 
   // -------------------------------------------------------------------

 
   /**
     * __construct ()
     * -------------------------------------------------------------------
     *
     * Class    Constructor
     *
     * NOTE: Not needed if not setting values or extending a Class.
     */
 
   public function __construct()
 
   {
 
       parent::__construct();

 
       log_message('debug'"Backend Controller Class Initialized");
 
   }

 
   /**
     * index ()
     * -------------------------------------------------------------------
     *
     */
 
   public function index()
 
   {

 
   }

 
   // -------------------------------------------------------------------

  // End of Backend Controller Class.

/**
 * Class Frontend
 */
class Frontend extends Base
{
 
   /**
     * Class properties go here.
     * -------------------------------------------------------------------
     * public, private, protected, static and const.
     */


 
   // -------------------------------------------------------------------

 
   /**
     * __construct ()
     * -------------------------------------------------------------------
     *
     * Class    Constructor
     *
     * NOTE: Not needed if not setting values or extending a Class.
     */
 
   public function __construct()
 
   {
 
       parent::__construct();

 
       log_message('debug'"Frontend Controller Class Initialized");
 
   }

 
   /**
     * index ()
     * -------------------------------------------------------------------
     *
     */
 
   public function index()
 
   {

 
   }

 
   // -------------------------------------------------------------------

  // End of Frontend Controller Class.

// End of MY_Controller Controller Class.


/**
 * -----------------------------------------------------------------------
 * Filename: MY_Controller.php
 * Location: ./application/core/MY_Controller.php
 * -----------------------------------------------------------------------
 */ 

Make sure that you extend all your controllers from Base

Or use can extend the controller using Frontend or Backend
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply

#3
Hello,
I've created a library that manages the templates of a website: CodeIgniter Layout Library
It saves you from writing the 4 loads in every controller.
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.