This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class AlunoForm extends PessoaForm { | |
public function __construct($options = null) { | |
parent::__construct($options); | |
$this->generate(); | |
} | |
private function generate() { | |
$matricula = new Zend_Form_Element_Text('matricula'); | |
$matricula->setLabel('Matrícula')->setRequired(true)->addFilter('StripTags')->addValidator('NotEmpty'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class ProfessorForm extends PessoaForm { | |
public function __construct($options = null) { | |
parent::__construct($options); | |
$this->generate(); | |
} | |
private function generate() { | |
$disciplina = new Zend_Form_Element_Text('disciplina'); | |
$disciplina->setLabel('Disciplina')->setRequired(true)->addFilter('StripTags')->addValidator('NotEmpty'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$endereco = new Zend_Form_SubForm(); | |
$endereco->addElements(array( | |
new Zend_Form_Element_Text('cidade', array( | |
'required' => true, | |
'label' => 'Cidade:', | |
'filters' => array('StringTrim', 'StringToLower'), | |
'validators' => array( | |
'Alnum', | |
array('Regex', | |
false, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public function indexAction() { | |
//busca os posts | |
$posts = new Posts; //cria um novo objeto Posts | |
$this->view->data = $posts->fetchAll(); | |
//adiciona o formulario | |
$form = new LoginForm(); | |
//verifica se tem dados enviados | |
if ($this->_request->isPost()) { | |
$formData = $this->_request->getPost(); | |
//se o formulário está válido |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Admin_AdminController extends Zend_Controller_Action { | |
public function indexAction() { | |
//recupera a instancia | |
$auth = Zend_Auth::getInstance(); | |
//se não possui uma credencial válida | |
if (!$auth->hasIdentity()) { | |
$session = Zend_Registry::get('session'); | |
$session->erro = 'Não logado'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//cria o formulário de inclusão de posts | |
$form = new PostForm; | |
//foi feito post de dados | |
if ($this->_request->isPost()) { | |
//pega os dados postados | |
$formData = $this->_request->getPost(); | |
//o form está valido? | |
if ($form->isValid($formData)) { | |
$dados = array( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
foreach($this->data as $d) { | |
?> | |
<h2><?php echo $d['title']; ?></h2> | |
<p><?php echo $d['description']; ?></p> | |
<p><a href="<?php echo BASE_URL;?>/admin/admin/edit/id/<?php echo $d['id']; ?>">Editar</a></p> | |
<p><a href="<?php echo BASE_URL;?>/admin/admin/del/id/<?php echo $d['id']; ?>">Excluir</a></p> | |
<?php | |
} | |
?> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//faz a edição de um post | |
public function editAction() { | |
$session = Zend_Registry::get('session'); | |
$form = new PostForm(); | |
//muda o label do submit | |
$form->submit->setLabel('Alterar'); | |
//muda a action | |
$form->setAction(BASE_URL.'/admin/admin/edit')->setMethod('post'); | |
//busca o id do post que vai ser alterado |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//faz a exclusão de um post | |
public function delAction() { | |
$session = Zend_Registry::get('session'); | |
$id = $this->_getParam('id'); | |
if(!$id) { //não foi passado um id | |
$session->erro = 'Não foi selecionado ID'; | |
$this->_redirect('/admin/admin'); //redireciona para a página inicial | |
exit; | |
} | |
$posts = new Posts(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Zend_Acl | |
*/ | |
$acl = new Zend_Acl; | |
//roles | |
$acl->addRole(new Zend_Acl_Role('visitante')); | |
//as roles redator e admin herdam a role de visitante | |
$acl->addRole(new Zend_Acl_Role('redator'), 'visitante'); | |
$acl->addRole(new Zend_Acl_Role('admin'), 'visitante'); |