Calendar
QuicksearchCategoriesGet Jimdo!Get a free website with professional content management features at Jimdo.com!
|
Extending Zend_Controller_ActionSunday, July 2. 2006Comments
Display comments as
(Linear | Threaded)
Isnīt it called "Zend_Controller_Action"? ;D
CWAC = Creation With Application Components? :]
Btw nice articles about your mashup framework. I also created one with ZF + Smarty + Pear::LiveUser and an extended Action class similar to yours.
Did you have a look at http://www.akrabat.com/2006/03/05/zend-framework-views-and-the-front-controller/ ?
Hope to read more of your CWAC soon :]
Oops, yeah, messed that one up in the title - it's corrected now
Nice solution
I wrote something along those lines, I'm not fan of automatic output though. I prefer to call a render method in my controller's actions but that is a matter of taste. Since I end up writing it often I might switch to your approach. It is pretty trivial to add a class members to say you don't want any template applied (think feed).
BTW, you can replace
$name = get_class($this);
$name = substr($name, 0, strlen($name)-10); // strip the word "Controller" from the name
with
$controllerName = $this->_action->getControllerName();
Actually, I tried to do just that, but $this_action didn't seem to contain anything at the time the constructor runs.
Ah yes, you're right. there is no easy way about that one.
$this->_action is set in the run() method ...
Why don't you use _CLASS_ instead of get_class($this)?
Because _CLASS_ always contains the name of the actual class it's been written into, so in this case it would always contain "CWAC_Controller_Action".
Ah, yes, you're right. You are in a parent class ...
I didn't mention anything ...
Another minor improvement suggestion:
You can call substr with negative numbers as argument
substr($name, 0, strlen($name)-10) -> substr($name, 0, -10)
This saved at least one microsecond (or two)
Nice post. I had been doing something similar with configuration settings and just making sure my code followed the same standard. I like this extending idea, as it will force other developers who will eventually get access to my code, to always follow the same rules.
Thanks for the article.
PS: In all my controllers, I have made a __construct, which sets up $this->_view = Zend::registry('view'); as well as page titles, or variables for views.
Not bad approach. I did mine a bit differently though. I extended both the Controller_Action and View classes.
Within the Controller_Action, I setup the "bridge" to my View class and loaded a config file with SimpleXML. Within my View class I took a queue from CakePHP: I overloaded the render() method by calling layouts inserting specific controller's views into it. Each Controller's view is within individual view directories, like CakePHP. I also added renderElement() method for elements (god I love elements).
Like Cake, I also have the ability to override the default layout and default view page, allowing me to have different pages depending on the action (very important for some of my pages).
It's very CakePHP esqueue for the most part.
what does smarty do with the zend framework ?
zend framework is a mvc framework, it has a viewer and a controller ... is enough to separate bussines logic from presentation logic, smarty is useles, unles you want users to submit their templates, also in this case you have alternatives... using apache htaccess to limit some of php functions.
Smarty the interpreted language inside an interpred language (PHP), usless piece of code ... one question bothers me ... why are so many people use this useles thing anyway ? ....oh right ... mediocre programmers .... a lot of php programmers are beginers .... but they must evolve as programmers ... or maybe just learn how to program ... not to write code ... this means that you need to know more than a programming language ...
Anyway, evolve ... smarty people ...
Marcus,
Very cool component, you've saved me the work of doing this myself.
I've been playing around with your CWAC_Controller_Action class, and was noticing pages taking a lot longer to render.
So I looked into my accesslogs and found that for every single page request I made, the server was receiving 4 GET requests.
As soon as I turn _noMasterViews to true (whereby only rendering the "actionView"), it goes back to the expected 1 GET request.
Any idea what this might be about?
John,
I have no clue whatsoever. I have run into a similar problem, though: When issuing a POST request, I'm suddenly getting two requests instead of one. When I try to redirect in the action method after a POST, the Apache segfaults on me.
As I've had other problems with the "output on destructor call" approach as well, I changed this to explicitly calling a render() method on the controller instead. No effect whatsoever.
I then tracked things down to calling my ActiveRecord's save() method before the redirect. Commenting that out, I got no second request and no more segfault on redirect.
Unfortunately I have not yet been able to reproduce this bug with a stripped-down version of all the processes involved... so far, I'm only getting this behaviour with the full-blown code base, which doesn't help much in nailing down the ultimate cause
|
Recent CommentsThu, 12.02.2009 13:12
I am not sure I will be able t
o make it on either weekend.
Go for either weekend and I wi
ll see if I am in the ar [...]
Tue, 20.01.2009 18:32
In den letzten Wochen sind in
diversen englischsprachigen Bl
ogs sehr interessante und teil
weise recht ausfhrliche [...]
Tue, 13.01.2009 13:40
Well I am mostly at fault for
the "complexity". I actually u
sed pretty much all the advanc
ed features in real worl [...]
Mon, 05.01.2009 10:24
I agree completely: KISS.
S
ince rights management can be
complicated, I find it works b
est when you push it dow [...]
Mon, 03.11.2008 23:58
Hi! Are you planing to share t
he slides of your talk? TIA!
Sat, 25.10.2008 10:13
Am nchsten Montag (27.10.) beg
innt die 14. Internationale PH
P Konferenz in Mainz und luft
bis zum Freitag (31.10.) [...]
Entry's Links
Content license |
|||||||||||||||||||||||||||||||||||||||||||||||||
Hi Matthew, have you considered the use case where you have your views split up into a global section that remains constant for the whole application (e.g. a common page header), a controllerspecific view (e.g. a navigation sidebar) and, finally,...
Tracked: Mar 08, 00:31