public function initialize($entity = null, $options = null) { $select = new Select('parentId'); $category = new Models\Category(); $categories = $category->find(array("order" => "id DESC", "limit" => 100)); $categoryArray = array('None'); foreach ($categories as $key => $item) { $categoryArray[$item->id] = $item->categoryName; } $select->setOptions($categoryArray); $this->add($select); }
public function addCid() { if ($this->cid) { return $this->cid; } $category = new Models\Category(); $categories = $category->find(array("order" => "id DESC", "limit" => 100)); if ($categories) { $options = array('All Categories'); foreach ($categories as $categoryitem) { $options[$categoryitem->id] = $categoryitem->categoryName; } $element = new Select('cid', $options); } $this->add($element); return $this->cid = $element; }
public function getCategories() { if ($this->categories) { return $this->categories; } $category = new Models\Category(); $categories = $category->find(array("order" => "id DESC", "limit" => 100)); $post = $this->getModel(); $values = array(); if ($post && $post->categories) { foreach ($post->categories as $categoryitem) { $values[] = $categoryitem->id; } } foreach ($categories as $key => $item) { $check = new Check('categories[]', array('value' => $item->id)); if (in_array($item->id, $values)) { $check->setDefault($item->id); } $check->setLabel($item->categoryName); $this->categories[] = $check; } return $this->categories; }