One Controller

#11
[eluser]$ilovephp[/eluser]
[quote author="n0xie" date="1271706057"][quote author="ranjeet_sangle" date="1271705959"]If you are working on a single website with a team then its not feasible to keep a single controller because all the members cant work on a single file simultaneously. [/quote]
That's what you use a SCM for.[/quote]

You also said that it depends from the situation. Can you give scenario or a situation where in it is better to use only one controller?

#12
[eluser]John_Betong[/eluser]
I take it that you did not search for extending MY_Controller so here is how to have individual controllers that use extend the

./application/libraries/MY_Controller.php
Code:
class MY_Controller extends Controller
{
    function __construct()
    {    
        parent::Controller();

        $this->load->helper('html');
    }
  
    function fred($title='Jack')
    {
      echo heading($title);
    }

}//endclass

 

./application/controllers/ci_first.php
Code:
class ci_first extends MY_Controller
{
    function __construct()
    {    
        parent::Controller();
    }
  
    function index
    {
      $this->fred();

      $this->fred('jack');

      $this->fred('harry');

    }

}//endclass
 
./application/controllers/ci_second.php
Code:
class ci_second extends MY_Controller
{
    function __construct()
    {    
        parent::Controller();
    }
  
    function index
    {
      $this->fred();

      $this->fred('jack');

      $this->fred('harry');

    }

}//endclass
 
 
 
 

#13
[eluser]$ilovephp[/eluser]
[quote author="John_Betong" date="1271757883"]I take it that you did not search for extending MY_Controller so here is how to have individual controllers that use extend the

./application/libraries/MY_Controller.php
Code:
class MY_Controller extends Controller
{
    function __construct()
    {    
        parent::Controller();

        $this->load->helper('html');
    }
  
    function fred($title='Jack')
    {
      echo heading($title);
    }

}//endclass

 

./application/controllers/ci_first.php
Code:
class ci_first extends MY_Controller
{
    function __construct()
    {    
        parent::Controller();
    }
  
    function index
    {
      $this->fred();

      $this->fred('jack');

      $this->fred('harry');

    }

}//endclass
 
./application/controllers/ci_second.php
Code:
class ci_second extends MY_Controller
{
    function __construct()
    {    
        parent::Controller();
    }
  
    function index
    {
      $this->fred();

      $this->fred('jack');

      $this->fred('harry');

    }

}//endclass
 
 
 
 [/quote]

Thank you very much! I find it very useful.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


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