(on Wednesday, 11 March 2009, 07:01 AM -0700):
> I have a question about some of the standard placeholder view helpers.
>
> First of all, in order for my code I am outputting to look good when I
> "View->Show Source" in the browser, I am having to overwrite the
> __toString() function for a couple of these standard placeholders to
> something like
>
> <?php
> class My_View_Helper_HeadTitle extends Zend_View_Helper_HeadTitle
> {
> public function __toString()
> {
> return parent::__toString() . PHP_EOL;
> }
> }
>
>
> All I am doing is adding a break to the end of the outputted text (PHP_EOL)
> but it makes such a difference. Otherwise I get my <html> tag on the same
> line as my doctype and others. This may seem like a pointless exercise, but
> in fact for front end developers it is very helpful to be able to read clean
> looking HTML code using View Source (as Firebug is only available on
> Firefox!)
>
> Is there any reason why this isn't included on the standard placeholders?
Not really. One thing to note, if you put a trailing space following
your closing PHP tag and then do a newline, you'll get the newline:
<?php echo $this->headTitle() ?> <!-- space precedes... -->
If you would like to see the PHP_EOL appended by default, please file a
feature request in the tracker.
> Also, our company coding standards use TABs for HTML output and not SPACEs.
> I see there is a getWhitespace() function which sets the number of spaces
> for some placeholders (used in HeadLink for example) but I was wondering if
> there are plans to give the option whether to use a SPACE or a TAB?
>
> I would also overwrite this function to use tabs instead, but I don't know
> how. Does anyone know what I need to do to overwrite this?
It's already possible. Use the setIndent() method, and pass it a string
with a tab:
$this->headScript()->setIndent("\t");
> Finally, I've written a custom view helper to display a valid HTML nested
> list using data read from my model. I'm returning this HTML back to my
> layout. However, the data that I've read from my model is not clean so I
> want to escape it before displaying it. How can I call the view helper
> escape() function from within my own view helper (which extends
> Zend_View_Helper_Abstract)?
$this->view->escape($text);
The $view public property is registered by default when extending
Zend_View_Helper_Abstract.
--
Matthew Weier O'Phinney
Software Architect | matthew@zend.com
Zend Framework | http://framework.zend.com/
没有评论:
发表评论