public function cadastrarAction()
 {
     $form = new Application_Form_Categoria();
     $var = $this->getAllParams();
     if ($this->getRequest()->isPost()) {
         if ($form->isValid($var)) {
             $dados = $form->getValues();
             $inserir = array('categoria' => $dados['categoria']);
             $tb = new Application_Model_DbTable_Categoria();
             $tb->insert($inserir);
             $this->_helper->redirector->gotoSimpleAndExit('index');
         }
     }
     $this->view->form = $form;
 }
 public function indexAction()
 {
     $this->assecoAction();
     $this->_helper->layout->setLayout('administrator');
     // Página que a paginação irá iniciar
     $pagina = intval($this->_getParam('pagina', 1));
     $categoria = new Application_Model_DbTable_Categoria();
     $dados = $categoria->fetchAll();
     $paginator = Zend_Paginator::factory($dados);
     // Seta a quantidade de registros por página
     $paginator->setItemCountPerPage(10);
     // numero de paginas que serão exibidas
     $paginator->setPageRange(10);
     // Seta a página atual
     $paginator->setCurrentPageNumber($pagina);
     // Passa o paginator para a view
     $this->view->categoria = $paginator;
 }
 public function init()
 {
     $naoVazio = new Zend_Validate_NotEmpty();
     $categoriaTB = new Application_Model_DbTable_Categoria();
     $categorias = $categoriaTB->fetchAll(null, 'categoria');
     $array = array(0 => 'Selecione uma categoria');
     foreach ($categorias as $categoria) {
         $array[$categoria->idcategoria] = $categoria->categoria;
     }
     $idcategoria = new Zend_Form_Element_Select('idcategoria', array('label' => 'Categoria:', 'required' => true, 'multioptions' => $array));
     $idcategoria->addValidator($naoVazio);
     $filter = new Zend_Filter_Null();
     $idcategoria->addFilter($filter);
     $this->addElement($idcategoria);
     $titulo = new Zend_Form_Element_Text('titulo', array('label' => 'Titulo:', 'required' => true));
     $titulo->addValidator($naoVazio);
     $this->addElement($titulo);
     $texto = new Zend_Form_Element_Textarea('texto', array('label' => 'Texto:', 'required' => true));
     $texto->addValidator($naoVazio);
     $this->addElement($texto);
     $botao = new Zend_Form_Element_Submit('botao', array('label' => 'Salvar'));
     $this->addElement($botao);
 }
 public function init()
 {
     $this->decoradores = array('ViewHelper', array('Errors', array('tag' => 'div', 'style' => 'color:red;')), 'HtmlTag', 'Label');
     // Categoría
     $dbCategoria = new Application_Model_DbTable_Categoria();
     $categorias = $dbCategoria->getCategoriasList();
     $this->addElement('select', 'categoria', array('label' => ' ', 'required' => false, 'filters' => array('stringTrim')));
     /*   foreach($municipios as $key => $value){
             $this->municipio->addMultiOption($key,$value);
          }*/
     $this->categoria->addMultiOptions($categorias);
     //$this->municipio->removeDecorator('Errors');
     $this->categoria->setAttrib('class', 'form_select_medium');
     $this->categoria->removeDecorator('HtmlTag');
     $this->categoria->removeDecorator('Label');
     //Precio / Mes
     $this->addElement('text', 'precio', array('label' => 'Precio / Mes (*)', 'required' => true, 'filters' => array('stringTrim')));
     $this->precio->addValidator('NotEmpty', true, array('messages' => array(Zend_Validate_NotEmpty::IS_EMPTY => 'Ingresar el precio.')));
     $this->precio->addValidator('digits', true, array('messages' => array(Zend_Validate_Digits::NOT_DIGITS => 'Ingresar cantidad entera')));
     $this->precio->setDecorators($this->decoradores);
     $this->precio->setAttrib('class', 'form_input_contact_small');
     //$this->precio->removeDecorator('Errors');
     $this->precio->removeDecorator('HtmlTag');
     $this->precio->removeDecorator('Label');
     // Titulo anuncio
     $this->addElement('text', 'titulo', array('label' => 'Titulo (*)', 'required' => true, 'filters' => array('stringTrim')));
     $this->titulo->addValidator('NotEmpty', true, array('messages' => array(Zend_Validate_NotEmpty::IS_EMPTY => 'Ingresar titulo del anuncio.')));
     $this->titulo->setDecorators($this->decoradores);
     $this->titulo->setAttrib('class', 'form_input_contactx');
     //_motor
     //$this->titulo->removeDecorator('Errors');
     $this->titulo->removeDecorator('HtmlTag');
     $this->titulo->removeDecorator('Label');
     // Descripcion completa
     $this->addElement('textarea', 'descripcion', array('label' => 'Descripción completa', 'required' => false, 'filters' => array('stringTrim')));
     //$this->descripcion->setDecorators($this->decoradores);
     $this->descripcion->setAttrib('class', 'textarea');
     $this->descripcion->removeDecorator('Errors');
     $this->descripcion->removeDecorator('HtmlTag');
     $this->descripcion->removeDecorator('Label');
     // Provincia
     $this->addElement('text', 'provincia', array('label' => 'Provincia (*)', 'required' => false, 'filters' => array('stringTrim'), 'value' => 'Barcelona'));
     $this->provincia->setAttrib('disabled', 'disabled');
     $this->provincia->setAttrib('class', 'form_input_contact_small');
     $this->provincia->removeDecorator('Errors');
     $this->provincia->removeDecorator('HtmlTag');
     $this->provincia->removeDecorator('Label');
     // Municipio
     $dbMunicipio = new Application_Model_DbTable_Municipio();
     $municipios = $dbMunicipio->getMunicipiosList();
     $this->addElement('select', 'municipio', array('label' => ' ', 'required' => false, 'filters' => array('stringTrim')));
     /*   foreach($municipios as $key => $value){
             $this->municipio->addMultiOption($key,$value);
          }*/
     $this->municipio->addMultiOptions($municipios);
     //$this->municipio->removeDecorator('Errors');
     $this->municipio->setAttrib('class', 'form_select_medium');
     $this->municipio->removeDecorator('HtmlTag');
     $this->municipio->removeDecorator('Label');
     // Submit "GRABAR"
     $this->addElement('Submit', 'Grabar');
 }