Welcome Guest, Not a member yet? Register   Sign In
Where to put functions for all my controllers
#11

[eluser]Mr. Pickle[/eluser]
[quote author="n0xie" date="1273847104"]Try:
Code:
function __construct()
[/quote]

Cheers for that, figured it out seconds before your reply Big Grin
#12

[eluser]WanWizard[/eluser]
[quote author="Mr. Pickle" date="1273843407"]Hi WanWizard, this info is about extending libraries, not extending the (main) controller is it? Or do I miss something here?[/quote]
Depends on what you want.
If you have something that you want to have available (p.e. security checks), you can extend the Controller to MY_Controller, and add it there. If it is just about having methods available to all your controller (from a reuse point of view), a library is the logical option.
#13

[eluser]Buso[/eluser]
remember that this is not a CI pattern, its just OOP. Also, you don't need to redefine the constructor, unless you want to add something to it.

when extending Controller, if you redefine the constructor, you have to use parent::Controller() instead of parent::__construct(), because that's how the called when they wrote it (i think its for php4 compatibility or something). After that, call your constructors __construct(), so you don't have to think about their names
#14

[eluser]Mr. Pickle[/eluser]
But what if your parent has got only a __construct() and not a OwnName();
If I keep to php5 this would be complete strict CI coding wouldn't it?

I don't understand what you mean with being able to call the __construct afterwards, at that point the relation is already set up, isn't it? Maybe you can explain further? Thanks!
#15

[eluser]Mr. Pickle[/eluser]
Is it also considered clean if you set up an array from your controller?
Accessible througout extended controllers using for example:
Code:
$this->nameofarray;

and then within the controller you specify more details like content.

Code:
$data['main_content'] = 'main/content';

    $pass_on = array_merge($this->nameofarray, $data);

    $this->load->view('viewfile', $pass_on);

I'd like to know, but maybe I'm way outside the normal programming guidelines.
#16

[eluser]cadee[/eluser]
Another option is use HMVC. You can then call the news controller as a “view partial” in your views and all your other controls remains clean
_________________________________________________________________
SEO Agency
SEO Newcastle
#17

[eluser]pickupman[/eluser]
Here is a great article on this topic from Phil Sturgeon. If you click on the code tab section of his site, you will also find his awesome cache library. It's even better than the built in class, as you can cache any model or library call, and is only a config file with a library folder. You then can use:
Code:
$this->cache->model('your_model_name', 'your_model_method', array('your_parameters')); //Fourth option is a integer for cache length default in config file




Theme © iAndrew 2016 - Forum software by © MyBB