Welcome Guest, Not a member yet? Register   Sign In
Common methods for all controllers
#1

[eluser]owidiuszek[/eluser]
Hello,

What is the best way to make few methods available to all controllers?

for example some result view:

Code:
function showResult($text, $state)
    {    
        $data['page'] = "result_view";
        $data['text'] = $text;
        $data['state'] = $state;
        $this->load->view('main', $data);
    }
And I would liek to access it from every controller in my app like:
$this->showResult('aaa','bbb'); (or similar)

without pasting this code inside each controller.

Should I create for example maincontroller and then extend all others basing on it?
Or maybe usage of library or helper would be better?
#2

[eluser]umefarooq[/eluser]
if your loading view for your result you can use widget plugin for your problem have look on the link

http://ellislab.com/forums/viewthread/109584/
#3

[eluser]mattpointblank[/eluser]
This is what libraries and helpers are for. If it's just a small function then a helper seems best to me.
#4

[eluser]davidbehler[/eluser]
Quote:Should I create for example maincontroller and then extend all others basing on it?

That's exactly what I would do. No need for a helper/library here.
#5

[eluser]Boris Strahija[/eluser]
You could use MY_Controller
http://ellislab.com/codeigniter/user-gui...asses.html
#6

[eluser]owidiuszek[/eluser]
MY_Controller works nicely and smoothly.

But if it is the same idea as making own controller and extending others on it - what is the point of making it as a library?

Anyway Thanks Wink




Theme © iAndrew 2016 - Forum software by © MyBB