Issues

ZF-46: New HtmlList helper (TRAC#45 borjafp@vivirasturias.com)

Issue Type: Improvement Created: 2006-06-20T00:45:05.000+0000 Last Updated: 2007-07-05T14:43:08.000+0000 Status: Resolved Fix version(s): - 0.6.0 (16/Dec/06)

Reporter: Zend Framework (zend_framework) Assignee: Borja Fernandez (borjafp) Tags: - Zend_View

Related issues: Attachments: - htmlList.txt

Description

http://framework.zend.com/developer/ticket/45

This helper allows render a ordered/unordered list.

<pre class="highlight">
Index: HtmlList.php
===================================================================
--- HtmlList.php    (revision 0)
+++ HtmlList.php    (revision 0)
@@ -0,0 +1,60 @@
+<?php
+/**
+ * Zend Framework
+ *
+ * LICENSE
+ *
+ * This source file is subject to the new BSD license that is bundled
+ * with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * <a href="http://framework.zend.com/license/new-bsd">http://framework.zend.com/license/new-bsd</a>
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@zend.com so we can send you a copy immediately.
+ *
+ * @package    Zend_View
+ * @subpackage Helper
+ * @copyright  Copyright (c) 2006 Zend Technologies USA Inc. (<a href="http://www.zend.com">http://www.zend.com</a>)
+ * @license    <a href="http://framework.zend.com/license/new-bsd">http://framework.zend.com/license/new-bsd</a>     New BSD License
+ */
+
+
+/**
+ * Helper to generate a "List" element
+ * 
+ * @package    Zend_View
+ * @subpackage Helper
+ * @copyright  Copyright (c) 2006 Zend Technologies USA Inc. (<a href="http://www.zend.com">http://www.zend.com</a>)
+ * @license    <a href="http://framework.zend.com/license/new-bsd">http://framework.zend.com/license/new-bsd</a>     New BSD License
+ */
+class Zend_View_Helper_HtmlList {
+   
+   /**
+     * Generates an 'ordered/unordered' list.
+     * 
+     * @access public
+     * 
+     * @param array $items Members of the list
+     * 
+     * @param Boolean $ordered Specifies ordered/unordered
+     *
+     * 
+     * @return string The list XHTML.
+     */
+   public function htmlList($items, $ordered = false)
+   {
+       $thelist='';
+       foreach ($items as $item)
+       {
+           if (!is_array($item))
+               $thelist.='' . $item . '';
+           else
+               $thelist.=$this->htmlList($item, $ordered);
+       }
+       
+       if ($ordered)
+           return '

' . $thelist . '';
+       else
+           return '
' . $thelist . '';
+   }
+}
\ No newline at end of file

Comments

Posted by Zend Framework (zend_framework) on 2006-06-20T00:45:29.000+0000

05/11/06 13:18:23: Modified by mike

* owner changed from zend to mike.

05/12/06 11:02:57: Modified by borjafp@vivirasturias.com

New things in this version. 1 - Support for $attribs 2 - Returns concatenated

//Now returns

<

ul>

Item 1 Item a Item b Item c Item 2 Item 3 Here is the new code

<pre class="highlight">
+     * @param Boolean $ordered Specifies ordered/unordered
+     * 
+     * @param mixed $attribs
+     *
+     * 
+     * @return string The list XHTML.
+     */
+   public function htmlList($items, $ordered = false, $attribs=false)
+   {
+       $thelist='';
+       foreach ($items as $item)
+       {
+           if (!is_array($item))
+               $thelist.='' . $item . '';
+           else
+               $thelist.=substr($thelist,0,len($thelist)-5) . $this->htmlList($item, $ordered) . '';
+       }
+       if ($attribs) 
+           $attribs = $this->_htmlAttribs($attribs);
+       else
+           $attribs = '';
+           
+       if ($ordered)
+           return '

' . $thelist . '';
+       else
+           return '
' . $thelist . '';
+   }
+   
+   /**
+    *  Clone of FormElement.php function
+    * 
+    */
+    protected function _htmlAttribs($attribs)
+    {
+        $xhtml = '';
+        foreach ((array) $attribs as $key => $val) {
+            $key = htmlspecialchars($key);
+            if (is_array($val)) {
+                $val = implode(' ', $val);
+            }
+            $val = htmlspecialchars($val);
+            $xhtml .= " $key=\"$val\"";
+        }
+        return $xhtml;
+    }  
+}
\ No newline at end of file

Posted by Borja Fernandez (borjafp) on 2006-06-22T07:31:39.000+0000

Patch to include support for lists

Posted by Jayson Minard (jayson) on 2006-07-09T01:05:32.000+0000

is this patch ready to be reviewed and applied? (htmlList.txt)

Posted by Borja Fernandez (borjafp) on 2006-07-10T15:59:19.000+0000

Yes, patch ready and working.

Posted by Matthew Weier O'Phinney (matthew) on 2006-11-06T22:56:55.000+0000

HtmlList helper added to incubator with revision 1478

Have you found an issue?

See the Overview section for more details.

Copyright

© 2006-2016 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.

Contacts