public function addAction() { $formCategory = new CategoryForm(); // On récupère l'objet Request $request = $this->getRequest(); // On vérifie si le formulaire a été posté if ($request->isPost()) { // On instancie notre modèle Category $category = new Category(); // Et on passe l'InputFilter de Category au formulaire $formCategory->setInputFilter($category->getInputFilter()); $formCategory->setData($request->getPost()); // Si le formulaire est valide if ($formCategory->isValid()) { // On prend les données du formulaire qui sont converti pour correspondre à notre modèle Category $category->exchangeArray($formCategory->getData()); // On enregistre ces données dans la table Category $this->categoryTable->saveCategory($category); // Puis on redirige sur la page d'accueil. return $this->redirect()->toRoute('home'); } // Si le formulaire n'est pas valide, on reste sur la page et les erreurs apparaissent } $this->getServiceLocator()->get('Zend\\Log')->info('Une catégorie a été créée !'); return new ViewModel(array('form' => $formCategory)); }
public function install() { $post = new Post(); $user = new User(); $category = new Category(); $postcategory = new PostCategory(); Model::execute($category->install()); Model::execute($user->install()); Model::execute($post->install()); Model::execute($postcategory->install()); }
/** * @param Category $category The category object to add. */ protected function doAddCategory($category) { $this->collCategorys[] = $category; $category->setUser($this); }
/** * Gets paged posts from a category * * @param Category $category * @param int $page * @return Zend\Paginator\Paginator **/ public function getPagedFromCategory(Category $category, $page) { $qb = $this->em->createQueryBuilder(); $qb->select('partial p.{id, title}')->from(self::ENTITY_POST, 'p')->join('p.category', 'c')->orderBy('p.dateAdded', 'DESC')->where('c.id = :id')->andWhere('p.isPublished = :published')->setParameters(array('id' => $category->getId(), 'published' => 1)); $paginator = PaginatorFactory::create($qb, $page); return $paginator; }
/** * Filter the query by a related Category object * * @param Category|PropelCollection $category The related object(s) to use as filter * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL * * @return PostQuery The current query, for fluid interface */ public function filterByCategory($category, $comparison = null) { if ($category instanceof Category) { return $this->addUsingAlias(PostPeer::CATEGORY_ID, $category->getId(), $comparison); } elseif ($category instanceof PropelCollection) { if (null === $comparison) { $comparison = Criteria::IN; } return $this->addUsingAlias(PostPeer::CATEGORY_ID, $category->toKeyValue('PrimaryKey', 'Id'), $comparison); } else { throw new PropelException('filterByCategory() only accepts arguments of type Category or PropelCollection'); } }
/** * Filter the query by a related Category object * * @param Category $category the related object to use as filter * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL * * @return UserQuery The current query, for fluid interface */ public function filterByCategory($category, $comparison = null) { if ($category instanceof Category) { return $this->addUsingAlias(UserPeer::ID, $category->getUserId(), $comparison); } elseif ($category instanceof PropelCollection) { return $this->useCategoryQuery()->filterByPrimaryKeys($category->getPrimaryKeys())->endUse(); } else { throw new PropelException('filterByCategory() only accepts arguments of type Category or PropelCollection'); } }
$provider = new DataResolverProvider(); $provider->addDataResolver(new UserResolver()); $provider->addDataResolver(new PostResolver()); $provider->addDataResolver(new CategoryResolver()); // create action manager instance $actionManager = new ActionManager($provider); // create fixtures foreach (array('john', 'tobi', 'adam') as $id => $username) { $user = new User(); $user->setUsername($username); // save user $user->save(); writeln($user); } foreach (array('Web', 'Life', 'Open Source', 'PHP') as $value) { $category = new Category(); $category->setName($value); $user = UserQuery::create()->findPk(rand(1, 3)); $category->setUser($user); // save category $category->save(); // create action $actionManager->createAction($category->getUser(), Category::CREATE_CATEGORY, $category); writeln($category); } for ($i = 0; $i <= 20; $i++) { $post = new Post(); $post->setTitle('Post title ' . $i); $post->setBody('Post body ' . $i); $user = UserQuery::create()->findPk(rand(1, 3)); $post->setUser($user);
/** * Declares an association between this object and a Category object. * * @param Category $v * @return Post The current object (for fluent API support) * @throws PropelException */ public function setCategory(Category $v = null) { if ($v === null) { $this->setCategoryId(NULL); } else { $this->setCategoryId($v->getId()); } $this->aCategory = $v; // Add binding for other direction of this n:n relationship. // If this object has already been added to the Category object, it will not be re-added. if ($v !== null) { $v->addPost($this); } return $this; }
/** * Exclude object from result * * @param Category $category Object to remove from the list of results * * @return CategoryQuery The current query, for fluid interface */ public function prune($category = null) { if ($category) { $this->addUsingAlias(CategoryPeer::ID, $category->getId(), Criteria::NOT_EQUAL); } return $this; }