2008年8月21日星期四

Re: [fw-mvc] Include raw HTML into Zend_Form

On 21/08/2008 17:46, "Matthew Weier O'Phinney" <matthew@zend.com> wrote:

> -- Oscar Reales <oreales@gmail.com> wrote
> (on Thursday, 21 August 2008, 04:54 PM +0200):
>> Well at the end, the solution that Matthew purpose and the solution I
>> purposed before are the same: extends the Zend_Form_Element to creat your
>> own formElement (rawHtml). But i can´t understand why Matthew you says it is
>> "best" to overwrite "render" method instead of create the correspondant view
>> helpers, etc... For this "new element"......
>
> Because if all you're doing is rendering text verbatim, and there's no
> need for extra decorators, then this is the simplest, most
> straight-forward solution.

Ok. So is not the "best" solution but the simplest one. Then, i insist:
would be much better to do it at the right way. "Code today thinking in
tomorrow" is my way of see it. If you do it at the right way once, then you
can uses it at future projects without change nothing and following the
Zend_Form_Elements conventions.


>
>> If all you need is to render the "rawHtml" you can do that in the
>> viewHelper, but the form Element will behave in a standard way. ViewHelpers
>> of the Form Elements are quite useful: recently I have finished a project
>> where i need to render the output of form elements in "extjs" instead of
>> "xhtml"....... Creating different view helpers for each different form
>> element did the job without change nothing at the "form creation"
>> level........ This is why i suggest create Element, Helpers, etc....
>>
>> Overriding the render() method, the new "My_Form_Element_RawText" will not
>> have the possibility of using "decorators", etc..., the standard behavior of
>> a "Form_Element" will be broken, will it not???.....
>>
>>
>>
>> On 21/08/2008 16:08, "Matthew Weier O'Phinney" <matthew@zend.com> wrote:
>>
>>> -- Gordon Ross <gr306@ucs.cam.ac.uk> wrote
>>> (on Wednesday, 20 August 2008, 10:11 PM +0100):
>>>> Thanks for that. Where should I put it ? I don't really want to slap
>>>> it in the main Zend directories...
>>>
>>> Well, as the class is called "My_Form_Element_RawText", I'd put it in
>>> library/My/Form/Element/RawText.php.
>>>
>>> Basically, we recommend you create your own, unique namespace prefix --
>>> such as we have 'Zend_', and Solar uses 'Solar_', etc. Use this as a
>>> top-level directory underneath your library/ directory (which will
>>> contain Zend/ as well), and you should be all set.
>>>
>>> You'll need to tell Zend_Form about the location of this prefix, though;
>>> you can do that easily enough:
>>>
>>> $form->addPrefixPath('My_Form_Element', 'My/Form/Element/', 'element');
>>>
>>> and you'll be all set to start using it.
>>>
>>>> PS If ever you have the unfortunate experience to bump into me, I
>>>> think I owe you a few beers....
>>>
>>> I won't say no. :)
>>>
>>>> ----- Original Message -----
>>>> From: Matthew Weier O'Phinney <matthew@zend.com>
>>>> To: fw-mvc@lists.zend.com <fw-mvc@lists.zend.com>
>>>> Sent: Wed Aug 20 18:59:38 2008
>>>> Subject: Re: [fw-mvc] Include raw HTML into Zend_Form
>>>>
>>>> -- Gordon Ross <gr306@ucs.cam.ac.uk> wrote
>>>> (on Wednesday, 20 August 2008, 06:31 PM +0100):
>>>>> On 19/08/2008 09:05, "Oscar Reales" <oreales@gmail.com> wrote:
>>>>>
>>>>>> Well, in that case, there is another option that I have though to
>>>>>> implement
>>>>>> sometimes: extends a custom formElement that renders html. You can call
>>>>>> this
>>>>>> element "text" - "rawHtml" or something similar. Create the formEelement,
>>>>>> the viewHelper, decorators etc.... It is much more work but once it is
>>>>>> done,
>>>>>> you can uses it in any project.
>>>>>
>>>>> Out of all the options I've seen so far, I think this one is probably the
>>>>> best. As you say, though, it may not be the simplest. I'm starting to look
>>>>> at the existing elements to see what work is involved. I'm hoping it won't
>>>>> be too much work...
>>>>
>>>> It's not. :)
>>>>
>>>> In this case, I'd suggest simply extending Zend_Form_Element, and then
>>>> overriding render() to simply return the element value:
>>>>
>>>> class My_Form_Element_RawText extends Zend_Form_Element
>>>> {
>>>> public function render(Zend_View_Interface $view = null)
>>>> {
>>>> return $this->getValue();
>>>> }
>>>> }
>>>>
>>>> And that way you can re-use it to enter arbitrary text anywhere:
>>>>
>>>> $form->addElement('rawText', 'foo', array(
>>>> 'value' => 'This is some text to insert somewhere...',
>>>> ));
>>>>
>>>> --
>>>> Matthew Weier O'Phinney
>>>> Software Architect | matthew@zend.com
>>>> Zend Framework | http://framework.zend.com/
>>
>>

没有评论: