/** * Search producttype based on current criteria */ public function searchAction() { $numberPage = 1; if ($this->request->isPost()) { $query = Criteria::fromInput($this->di, 'PhalconDemo\\Models\\ProductTypes', $this->request->getPost()); $this->persistent->set('searchParams', $query->getParams()); } else { $numberPage = $this->request->getQuery("page", "int"); } $parameters = $this->persistent->get('searchParams', []); /** @var \Phalcon\Mvc\Model\Resultset\Simple $productTypes */ $productTypes = ProductTypes::find($parameters); if (!$productTypes->count()) { $this->flash->notice("The search did not find any product types"); return $this->forward("producttypes/index"); } $paginator = new Paginator(['data' => $productTypes, 'limit' => 10, 'page' => $numberPage]); $this->view->setVars(['page' => $paginator->getPaginate(), 'productTypes' => $productTypes]); }
/** * Initialize the products form * * @param mixed $entity * @param array $options */ public function initialize($entity = null, array $options = null) { if (!isset($options['edit'])) { $element = new Text("id"); $this->add($element->setLabel("Id")); } else { $this->add(new Hidden("id")); } $name = new Text("name"); $name->setLabel("Name"); $name->setFilters(['striptags', 'string']); $name->addValidators([new PresenceOf(['message' => 'Name is required'])]); $this->add($name); $type = new Select('product_types_id', ProductTypes::find(), ['using' => ['id', 'name'], 'useEmpty' => true, 'emptyText' => '...', 'emptyValue' => '']); $type->setLabel('Type'); $this->add($type); $price = new Text("price"); $price->setLabel("Price"); $price->setFilters(['float']); $price->addValidators([new PresenceOf(['message' => 'Price is required']), new Numericality(['message' => 'Price is required'])]); $this->add($price); }