Welcome Guest, Not a member yet? Register   Sign In
How to reuse code in controllers ?
#1

[eluser]tfliam[/eluser]
Hi, I'm building a large website and there's a lot of similar coding in many controllers, how could I put them in a separate file for code reusing?

For eg in my system/application/controllers/home.php, I have

Code:
<?php

class Home extends Controller {

    function Home()    {parent::Controller();}
    
    function index()
    {    
        $array_controller = $this->web_controller->get_web_controller_by_controller('home');
        
//CODE << CONTAINS OVER 20 LINES OF SIMILAR CODING
    }
}
?&gt;

and then in many other files, I'll have similar coding for eg. in my system/application/controllers/article/article_submit.php, I have

Quote:&lt;?php

class Article_Submit extends Controller {

function Article_submit() {parent::Controller();}

function index()
{
$array_controller = $this->web_controller->get_web_controller_by_controller('article_submit');

//CODE << CONTAINS OVER 20 LINES OF SIMILAR CODING
}
}
?&gt;
#2

[eluser]tfliam[/eluser]
Nvm, found the solution of using a library. Big Grin
#3

[eluser]wiredesignz[/eluser]
Glad we could help. Wink
#4

[eluser]stoefln[/eluser]
i use my own controller which extends the CI controller. i provide some methods in MY_Controller which i can use / call /override in my special controllers then...
#5

[eluser]Mirage[/eluser]
stoefin,

/*Care to elaborate? The CI controller classes are by design not extendable..*/

Doh! Nevermind!

Note to self: Drink coffee before posting to the forum in the morning. I seemed to remember that Controllers were once excluded from extending, but per doco it appears that it's legit.

-m




Theme © iAndrew 2016 - Forum software by © MyBB