Skip to end of metadata
Go to start of metadata

<ac:macro ac:name="unmigrated-inline-wiki-markup"><ac:plain-text-body><![CDATA[

<ac:macro ac:name="unmigrated-inline-wiki-markup"><ac:plain-text-body><![CDATA[

Zend Framework: Zend_Html Component Proposal

Proposed Component Name Zend_Html
Developer Notes http://framework.zend.com/wiki/display/ZFDEV/Zend_Html
Proposers Felix
Revision 1.2 - 22 June 2006: forgot to change section 5 ...
1.1 - 21 June 2006: added link to code package
1.0 - 21 June 2006: Initialisation (wiki revision: 7)

Table of Contents

1. Overview

Zend_Html is a base component handling HTML elements. Already included: some derived classes (like Zend_Html_A, Zend_Html_Img, etc.), and a document, form and table generator.

2. References

3. Component Requirements, Constraints, and Acceptance Criteria

  • Generates structured HTML code (HTML 4.01 or XHTML 1.0)
  • Automatic content and attribute values escaping
  • Handles forms, including filtering and validation against rules
  • Building tables

4. Dependencies on Other Framework Components

  • Standard PHP Library (SPL) Functions (access to table rows and cell like an array)
  • Zend (loadClass feature)

5. Theory of Operation

It works already in my laboratory, but it's not completly tested.

6. Milestones / Tasks

zone: Missing {zone-data:milestones}

7. Class Index

  • Zend_Html
  • some like Zend_Html_A, Zend_Html_Img, ...
  • Zend_Html_Document
  • Zend_Html_Form
  • Zend_Html_Input
  • Zend_Html_Input_Text, Zend_Html_Input_Submit, ...
  • Zend_Html_Form_Group (grouping elements)
  • Zend_Html_Form_Rule_...
  • Zend_Html_Form_Filter_...
  • Zend_Html_Form_Builder_...
  • Zend_Html_Table
  • Zend_Html_Tbody, Zend_Html_Tr, Zend_Html_Td, ...
  • some more

8. Use Cases

UC-01
  • two simple elements
  • document with a form
  • a simple table

9. Class Skeletons

Most parts already exists in my laboratory. See my small website. Package is currently named Fx_Html. A documentation is not yet available (except for the phpdoc comments).

]]></ac:plain-text-body></ac:macro>

]]></ac:plain-text-body></ac:macro>

Labels:
None
Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.
  1. Jun 21, 2006

    <p>"5. Theory of Operation</p>

    <p>The component is instantiated with a mind-link that ..."</p>

    <p>I like the mind-link interface. Definitely keep that in the final version.</p>

  2. Jun 22, 2006

    <p>Oops, this section I overlooked.</p>

  3. Jun 22, 2006

    <p>I think that would be more interesting create one helper for each label, than add a new component to the framework</p>

  4. Jun 28, 2006

    <p>1. I don't see anything to generate selects or groups of radio and checkboxes. One of the only reasons that I use HTML generation is to set the selected/checked state of select/radio/checkboxes from data from a datasource or redisplaying submitted data. I like the same interface to generate radio/checkboxes as selects because they are all conceptually similar and it makes it easy to switch between them. </p>

    <p>2. I would remove the form controller stuff from this code. I think adding client side Javascript filtering/validation would be a great thing to have. But that is be as far as this code should go. </p>

    <p>3. How could you integrate this with Javascript/CSS effects to create slick presentations? It might be nice to have plugins to utilize some of the nice Javascript libraries around. </p>

    <p>4. Mostly this kind of code is used by Form Controllers and things like that. So it should be designed to provide a friendly interface for things like that. </p>

    1. Jun 29, 2006

      <p>1. should work this way</p>
      <ac:macro ac:name="code"><ac:plain-text-body><![CDATA[
      $f = new Zend_Html_Form('test', 'get');

      $f->addElement($f->form_header(null, 'select and a checkbox group'));

      $options = array('0' => 'value1', '8' => 'value2', '15' => 'value3');
      $f->addElement($f->select('select', 'a select', $options));

      $f->addElement(
      $f->form_group('cbgroup', 'some checkboxes')
      >setSeparator($f>br())
      >addElement($f>input_checkbox('c1', null, 'check1', 'value1'))
      >addElement($f>input_checkbox('c2', null, 'check2', 'value2')));

      $f->addElement($f->input_submit(null, 'send'));

      $f->build();
      echo $f;
      ]]></ac:plain-text-body></ac:macro>

      <p>I like the idea to treat select, radio and checkboxes the same way. I think I will add both a radiogroup and a checkboxgroup element that works like the select.</p>

      <p>2. No, I wouldn't. I like PEAR's HTML_Quickform. The Fx(Zend)_Html_Form part is inspired by this package. Client side validation/filtering ... currently I don't need this functionalty, so I did not implement it, but I'm not against it.</p>

      <p>3. How would you combine Javascript/CSS with a HTML element (<input type=...>)? Using some of the element's attributes (onclick, id, ...). You can add attributes to all descendants of Fx(Zend)_Html accessing object properties ( $html->id = 'foo'; ) or using add() ( $html->add(array('id' => 'foo')); ). For anything else I need a use case. (Currently I'm still ignoring the Web2.0 hype, so I don't know what the needs are for a HTML object to be slick. (I hope this wasn't completly wrong english. <ac:emoticon ac:name="smile" /> ))</p>

      <p>4. Maybe I don't understand your meaning, but my intention was to build the Form part as a form controller and to use it as easy as possible. If it has no friendly interface please tell me how should a friendly interface look like.</p>

      1. Jun 29, 2006

        <p>4. Oh, I mean "form controller" in the sense of PEAR's HTML_Quickform (controls one form) not in the sense of HTML_Quickform_Controller (controls a bunch of forms). If you mean the last one ... this could be part of version 2.0 of Fx(Zend)_Html_Form.</p>

  5. Jun 30, 2006

    <p>I think the idea of creating/manipulating an HTML object is very useful, but I wouldn't begin to tie it together with other classes too tightly - Forms, for example, may not always need to be rendered in HTML (Willie pointed me in the direction of XForms, and HTML_QuickForm2 is already considering other decorators).</p>

    <p>So, a vote for Zend_HTML_xxx but not to perform form creation, validation, etc - leave that job for more suitable classes.</p>

  6. Sep 11, 2006

    <p>Funnily enough I have been working on something very similar, but as a replacement for the framework helper classes.</p>

    <p>The problem with the helper classes is that they immediately produce HTML, rather than allowing nested tags to be formed. The system I have been using is integrated with (my subclass of) Zend_View to allow tags to be added to each other and to be styled, and then rendered when the view is output.</p>

    <p>The syntax is like this:</p>
    <ac:macro ac:name="noformat"><ac:plain-text-body><![CDATA[
    // make a context
    $html = new Sprocket();

    // make a div
    $a_div = $html->div();
    $a_div->class = 'a_nice_css_class_';

    // add some tags to the div
    $a_div->h1("A heading");
    $a_div->p("Some text");

    $a_link = $html->a("Click here");
    $a_link->href = 'http://example.com';
    $a_link->class = 'a_css_link_class';

    [...]

    // output the HTML:
    echo $html->render();
    ]]></ac:plain-text-body></ac:macro>
    <p>There is some more information on this system <a href="http://cosmo7.com">here</a>. The system is called Sprockets right now; it uses a single Tag class for HTML tags and factory methods to produce more complex blocks of code.</p>

    <p>Would anyone be interested in this as a framework component? (I'm developing the system to use in a form building system, so most of the work involved is going to be done anyway).</p>

  7. Nov 14, 2006

    <ac:macro ac:name="note"><ac:parameter ac:name="title">Moved to Laboratory</ac:parameter><ac:rich-text-body>
    <p>We've reviewed this proposal and we feel it shows promise. But we have no plans to include it in Zend Framework 1.0. We're moving it to the ZF Laboratory so you can work on it some more, and share your code.</p>

    <p>There is a valid use case for this, like Perl's CGI.pm methods.</p>

    <p>But it's hard to see how Zend_Html works in the MVC paradigm that Zend Framework seeks to promote. I'm concerned that it would be easy for a developer to misuse this component and create spaghetti code, blurring the separation between code and presentation.</p>

    <p>Can you work on clarifying the cases in which you would use this Zend_Html component in the context of MVC? Would you use Zend_Html as a substitute View engine, or would you call Zend_Html methods from within a standard ".phtml" style View engine?</p></ac:rich-text-body></ac:macro>

  8. Aug 13, 2007

    <p>Hi,<br />
    I registered here to add my own contribution to this topic:<br />
    I released today a free library, close to both components already mentioned above.<br />
    I did not know them before, and after announcing my own contribution on the Zend Framework community, i was told of it.<br />
    Here is the web page about HoP : <a href="http://ac-mb.info/a_x/hop.html">http://ac-mb.info/a_x/hop.html</a></p>

    <p>What is the state of this component right now ?</p>

    <p>From the Hop doc page :</p>

    <p>HoinP means HTML objects in PHP. The easy spelling is HoP.</p>

    <p>It's free software under LGPL</p>

    <p>The purpose of this library is to offer a structured way to generate XHTML markup from PHP, without the traditional interleaving of PHP chunks, HTML chunks and echo statements all over.</p>

    <p>It is an intermediate concept between templating systems (I don't like the paradigm) and PHP DOM extensions (over complicated for the purpose). It will fit well in MVC designed applications and is close to the definition of helpers in the Zend Framework. In fact, the first draft of this library is older than the ZF 1.0 release, while it shares some conceptual similarities with these helpers.</p>

  9. Mar 18, 2009

    <p>This is a very old proposal... I created a much simpler component to assemble HTML and XML. It doesn't have specialized subclasses (although there could be).</p>

    <p>I wonder if such a component can be useful for the library. Usage would be like:</p>

    <ac:macro ac:name="code"><ac:default-parameter>php</ac:default-parameter><ac:plain-text-body><![CDATA[
    Zend_Html_Element::setMode(Zend_Html_Element::XHTML);

    $list = new Zend_Html_Element('ul');
    foreach($result as $row) {
    $item = new Zend_Html_Element('li');
    $list->append($item);

    $item->append($row['name'])
    ->title($row['descrition'])
    ->addToken('class','person');
    }
    $list->addToken('class','employees');
    echo $list;
    ]]></ac:plain-text-body></ac:macro>

    <p>I've got this code lying around (it is pretty trivial...) if there is interest.</p>

    1. May 19, 2009

      <p>It's great to see your approach. I have considered about similar components. May I support your proposal?</p>

      <p>How do you figure to sort out differences between your component and DOM or SimpleXML?</p>