/** * Add a Subcategory * * @param int $category_id internal category id * @param string $subcategory_name subcategory name */ public function addSubcategory($category_id, $subcategory_name) { // get category $category = $this->getCategoryById($category_id); // create subcategory $subcategory = new Subcategory(); $subcategory->setName($subcategory_name); $subcategory->setOwner($this->owner); // assign subcategory to category $subcategory->setCategory($category); // update $this->update($subcategory); }
/** * @param Subcategory $subcategory */ public function addSubcategory(Subcategory $subcategory) { $subcategory->setCategory($this); $subcategory->setOwner($this->owner); $this->subcategories->add($subcategory); }