Here's what I've done, which works, but I am curious if it's the best/most efficent/most maintainable, etc method:
I created Hans_Zend_View.php with Nikolaos' code in the application directory (same as bootstrap... I can move it, but there for testing).
Then in bootstrap I did:
require_once 'Hans_Zend_View.php';
$view = new Hans_Zend_View();
$viewRenderer = new Zend_Controller_Action_Helper_ViewRenderer();
$viewRenderer->setView($view);
Zend_Controller_Action_HelperBroker::addHelper($viewRenderer);
There was a "setViewSuffix('php')" after "setView($view)" that caused an exception, so I removed it. Also, I'm not clear on "addHelper" -- removing that line caused an exception, but the name "Helper" seems strange. Didn't I just extend Zend_View? Is Zend_View itself a "helper"?
Thanks,
Hans
On Fri, Jan 30, 2009 at 9:35 AM, Nikolaos Dimopoulos <nikos@niden.net> wrote:
Create a new class:class Hans_Zend_View extends Zend_View
{public function esc($var){return parent::escape($var);}public function e($var){return parent::escape($var);}}So when you want to use esc instead of escape it will work. You will only need to use the Hans_Zend_View class instead of the Zend_View. By extending Zend_View you have all the available resources of that class and also you add to it with your own logic i.e. esc function.If in your class you declare a function that has the same name as a function that is present in the class that is being extended, your function will override that one. Hence if for instance you usedpublic function escape($var){return 'blah blah';}you would effectively 'kill' the Zend_View's escape function. (just an FYI)I hope this helps.Nikolaos--On Fri, Jan 30, 2009 at 10:24, Hans Anderson <windsurf17@gmail.com> wrote:
I'm new to ZF and to some of the concepts of OO type systems in general, though I've used PHP for quite some time. So, my apologies if this is really basic, but how can I efficiently create a replacement for $this->escape() that would still use all of the settings (like SetEscape(), etc) but be named $this->e() or $this->esc(), just for cleaner view files (with the caveat that $this->e() isn't as immediately understandable as $this->escape()).
Do I need to extend Zend_View and change how the whole MVC system works or is there some other way?
Not a hugely important thing, but it keeps occurring to me to ask.
TIA,
Hans
The contents of this message may contain confidential or privileged information and is intended solely for the recipient(s). Use or distribution to and by any other party is not authorized. If you are not the intended recipient, copying, distribution or use of the contents of this information is prohibited.
--
Hans Anderson
+ growth is sparse on the tops of mountains +
http://hansanderson.com/
Psalm 41:1
没有评论:
发表评论