ElggMenuItem::setData PHP Method

setData() public method

This method allows storage of arbitrary data with this menu item. The data can be used for sorting, custom rendering, or any other use.
public setData ( mixed $key, mixed $value = null ) : void
$key mixed String key or an associative array of key/value pairs
$value mixed The value if $key is a string
return void
    public function setData($key, $value = null)
    {
        if (is_array($key)) {
            $this->data = array_merge($this->data, $key);
        } else {
            $this->data[$key] = $value;
        }
    }

Usage Example

示例#1
0
 public function testSetDataWithArray()
 {
     $item = new \ElggMenuItem('name', 'text', 'url');
     $item->setData(array('priority' => 88, 'new' => 64));
     $this->assertEquals(88, $item->getData('priority'));
     $this->assertEquals(88, $item->getPriority());
     $this->assertEquals(64, $item->getData('new'));
 }
All Usage Examples Of ElggMenuItem::setData