Welcome Guest, Not a member yet? Register   Sign In
Can an controller extend an other?
#1

[eluser]kbkb[/eluser]
I would like an master controller from which my other normal controller can extend.

I want to specify things like

$this->view("head", $data);

on one single point. At the moment i have to specify in every controller, or even worse: in every single action, the template for the page-head with generated variables like menus.


Or is there a better way to specify one master layout which can render inerhit other layouts?
#2

[eluser]jedd[/eluser]
[url="http://codeigniter.com/wiki/Header_and_Footer_and_Menu_on_every_page_-_jedd/"]Here's how I do it[/url].

Though I'm really surprised you didn't find that page when you searched the wiki before posting this question.
#3

[eluser]kbkb[/eluser]
hi! Thats a really nice approach. But just let me sure, that i get it right:

You write, that you have in your MY_Controller code which specifies $this->data['main_menu_view'];

( I think thats in the constructor from MY_Controller? right?



And in the end you parse the whole $this->data (which is filled from MY_ AND the real specified controller).


I think about filling in content which is generated from an own view Smile

But the hottest question: I cant extend an other controller! I get an error that the Class "MY_controller" is not found. Where have i put the controller to extend from?
#4

[eluser]jedd[/eluser]
[quote author="kbkb" date="1251823667"]
( I think thats in the constructor from MY_Controller? right?
[/quote]

Yes - though I have a couple of private functions within MY_Controller, most of the good stuff happens in the constructor of course.


Quote:And in the end you parse the whole $this->data (which is filled from MY_ AND the real specified controller).

I pass the $this->data construct across to my view(s), yes. I'm sure I mentioned that in that wiki page.

Quote:I think about filling in content which is generated from an own view Smile

You mean as opposed to generating from my own view? The trick will be to put your own view in there instead.


Quote:But the hottest question: I cant extend an other controller! I get an error that the Class "MY_controller" is not found. Where have i put the controller to extend from?

I'm really surprised that you didn't find the answer to this when you followed the link in my wiki page where I first mention MY_Controller, or again when you used the [url="http://www.google.com/search?as_sitesearch=ellislab.com/codeigniter/user-guide/&q=my_controller&sa=Go"]CI User Guide's search feature and looked for MY_Controller[/url].
#5

[eluser]kbkb[/eluser]
I just wanna go sure that i understand everything right.
I appreciate your answer very much! This helps a lot.

Thanks for guiding me to the guiding me to the right point of the manual. I don't even think about to read about extending core-classes because this seems very high level. I have made the assumption that some things are more intuitive here. But every part of the manual is really a small part and understandable. I won't be frightend to read the rest now Wink Looked allready in the meantime at every entry about helper in the manual and find it very helpfull.

thank you again!
#6

[eluser]jedd[/eluser]
The CI User Guide is a truly marvellous piece of documentation - I simply can't write as concisely as the various authors of that document can.

The downside is that you often find critically important pieces of information described, almost en passant, in half a sentence.

Having said that, I do think the MY_Controller feature should be a) implemented (and empty) by default in future releases, b) discussed in more detail in the guide.




Theme © iAndrew 2016 - Forum software by © MyBB