API15

Difference between revisions of "JMenu/getItems"

From Joomla! Documentation

< API15:JMenu
(New page: ===Description=== Gets menu items by attribute <span class="editsection" style="font-size:76%;"> <nowiki>[</nowiki>Edit Descripton<nowiki>]</nowiki> </...)
 
Line 27: Line 27:
 
| $firstonly
 
| $firstonly
 
| false
 
| false
|  If true, only returns the first item found
+
|  If true, only returns the first item found  
 
|}
 
|}
  
Line 40: Line 40:
 
===Source Body===
 
===Source Body===
 
<source lang="php">
 
<source lang="php">
public function getItems($attribute, $value, $firstonly = false)
+
function getItems($attribute, $value, $firstonly = false)
 
{
 
{
 
         $items = null;
 
         $items = null;
  
         foreach ($this->_items as $item) {
+
         foreach ($this->_items as $item)
                 if (!is_object($item)) {
+
        {
 +
                 if ( ! is_object($item) )
 
                         continue;
 
                         continue;
                }
 
  
                 if ($item->$attribute == $value) {
+
                 if ($item->$attribute == $value)
                         if ($firstonly) {
+
                {
 +
                         if($firstonly) {
 
                                 return $item;
 
                                 return $item;
 
                         }
 
                         }
  
                         $items[] = &$item;
+
                         $items[] = $item;
 
                 }
 
                 }
 
         }
 
         }

Revision as of 17:10, 22 March 2010

The "API15" namespace is an archived namespace. This page contains information for a Joomla! version which is no longer supported. It exists only as a historical reference, it will not be improved and its content may be incomplete and/or contain broken links.

Description[edit]

Gets menu items by attribute

[Edit Descripton]

Template:Description:JMenu/getItems

Syntax[edit]

getItems($attribute, $value, $firstonly=false)
Parameter Name Default Value Description
$attribute The field name
$value The value of the field
$firstonly false If true, only returns the first item found

Returns[edit]

array

Defined in[edit]

libraries/joomla/application/menu.php

Importing[edit]

jimport( 'joomla.application.menu' );

Source Body[edit]

function getItems($attribute, $value, $firstonly = false)
{
        $items = null;

        foreach ($this->_items as  $item)
        {
                if ( ! is_object($item) )
                        continue;

                if ($item->$attribute == $value)
                {
                        if($firstonly) {
                                return $item;
                        }

                        $items[] = $item;
                }
        }

        return $items;
}

[Edit See Also] Template:SeeAlso:JMenu/getItems

Examples[edit]

<CodeExamplesForm />