throw new Exception(_t('Permission denied')); fora do Try Pessoal, na aplicação changeman - StatusFormList, tem throw new Exception(_t('Permission denied')); fora do Try e funciona perfeitamente, estou tentando usar este mesmo form em outro app, está dando um erro como mostra o anexo. Desde já muito obrigado....
AR
throw new Exception(_t('Permission denied')); fora do Try  
Fechado
Pessoal, na aplicação changeman - StatusFormList, tem throw new Exception(_t('Permission denied')); fora do Try e funciona perfeitamente, estou tentando usar este mesmo form em outro app, está dando um erro como mostra o anexo. Desde já muito obrigado.

Curso Dominando o Adianti Framework

O material mais completo de treinamento do Framework.
Curso em vídeo aulas + Livro completo + Códigos fontes do projeto ERPHouse.
Conteúdo Atualizado!


Dominando o Adianti Framework Quero me inscrever agora!

Comentários (5)


NR

Adriano, você definiu essa mensagem de email já cadastrado? O throw new Exception funciona pois a classe do framework responsável por executar os controls tem um try antes de chamá-las.
AR

Olá Nataniel, muito grato.

Olhe esse código do do app changeman do Pablo.

Repara que ele usa " throw new Exception(_t('Not logged'));" fora do try e funciona perfeitamente.

 
  1. <?php
  2. /**
  3. * StatusFormList Registration
  4. * @author <your name here>
  5. */
  6. class StatusFormList extends TStandardFormList
  7. {
  8. protected $form; // form
  9. protected $datagrid; // datagrid
  10. protected $pageNavigation;
  11. /**
  12. * Class constructor
  13. * Creates the page and the registration form
  14. */
  15. function __construct()
  16. {
  17. parent::__construct();
  18. // security check
  19. if (TSession::getValue('logged') !== TRUE)
  20. {
  21. throw new Exception(_t('Not logged'));
  22. }
  23. // security check
  24. TTransaction::open('changeman');
  25. if (Member::newFromLogin(TSession::getValue('login'))-> role_mnemonic !== 'ADMINISTRATOR')
  26. {
  27. throw new Exception(_t('Permission denied'));
  28. }
  29. TTransaction::close();
  30. // defines the database
  31. parent::setDatabase('changeman');
  32. // defines the active record
  33. parent::setActiveRecord('Status');
  34. // creates the form
  35. $this->form = new TQuickForm('form_Status');
  36. $this->form->class = 'tform';
  37. $this->form->setFormTitle(_t('Status'));
  38. $options = array('Y'=>_t('Yes'), 'N'=>_t('No'));
  39. // create the form fields
  40. $id = new TEntry('id');
  41. $description = new TEntry('description');
  42. $final_state = new TRadioGroup('final_state');
  43. $color = new TColor('color');
  44. $id->setEditable(FALSE);
  45. $final_state->addItems($options);
  46. $final_state->setLayout('horizontal');
  47. // define the sizes
  48. $this->form->addQuickField('ID', $id, 100);
  49. $this->form->addQuickField(_t('Description').': ', $description, 200);
  50. $this->form->addQuickField(_t('Final state').': ', $final_state, 200);
  51. $this->form->addQuickField(_t('Color').': ', $color, 100);
  52. // define the form action
  53. $this->form->addQuickAction(_t('Save'), new TAction(array($this, 'onSave')), 'fa:floppy-o');
  54. $this->form->addQuickAction(_t('New'), new TAction(array($this, 'onEdit')), 'fa:plus-square green');
  55. // creates a DataGrid
  56. $this->datagrid = new TQuickGrid;
  57. $this->datagrid->width = '100%';
  58. $this->datagrid->setHeight(320);
  59. // creates the datagrid columns
  60. $this->datagrid->addQuickColumn('ID', 'id', 'left', NULL, new TAction(array($this, 'onReload')), array('order', 'id'));
  61. $this->datagrid->addQuickColumn(_t('Description'), 'description', 'left', NULL, new TAction(array($this, 'onReload')), array('order', 'description'));
  62. $this->datagrid->addQuickColumn(_t('Final state'), 'final_state', 'left', NULL, new TAction(array($this, 'onReload')), array('order', 'final_state'));
  63. $this->datagrid->addQuickColumn(_t('Color'), 'color', 'left', NULL);
  64. // add the actions to the datagrid
  65. $this->datagrid->addQuickAction(_t('Edit'), new TDataGridAction(array($this, 'onEdit')), 'id', 'fa:pencil-square-o blue fa-lg');
  66. $this->datagrid->addQuickAction(_t('Delete'), new TDataGridAction(array($this, 'onDelete')), 'id', 'fa:trash-o red fa-lg');
  67. // create the datagrid model
  68. $this->datagrid->createModel();
  69. // creates the page navigation
  70. $this->pageNavigation = new TPageNavigation;
  71. $this->pageNavigation->setAction(new TAction(array($this, 'onReload')));
  72. $this->pageNavigation->setWidth($this->datagrid->getWidth());
  73. // creates the page structure using a vbox
  74. $container = new TVBox;
  75. $container->style = 'width: 100%';
  76. $container->add($this->form);
  77. $container->add($this->datagrid);
  78. $container->add($this->pageNavigation);
  79. // add the container inside the page
  80. parent::add($container);
  81. }
  82. }
  83. ?>
</your>
NR

Adriano, o throw funciona porque o código do framework que executa os controls que criamos é o seguinte:
 
  1. <?php
  2. try
  3. {
  4. $page = new $class($_GET);
  5. ob_start();
  6. $page->show( $_GET );
  7. $content = ob_get_contents();
  8. ob_end_clean();
  9. }
  10. catch(Exception $e)
  11. {
  12. ob_start();
  13. ....
  14. ?>

Onde $page seria o control executado. Pode ver que há um try antes de executá-lo.
No erro que você anexou o throw também está sendo executado. Essa mensagem de email cadastrado é algum IF que você criou?
AR

 
  1. <?php
  2. /**
  3. * StatusFormList Registration
  4. * @author <your name here>
  5. */
  6. class StatusFormList extends TStandardFormList
  7. {
  8. protected $form; // form
  9. protected $datagrid; // datagrid
  10. protected $pageNavigation;
  11. /**
  12. * Class constructor
  13. * Creates the page and the registration form
  14. */
  15. function __construct()
  16. {
  17. parent::__construct();
  18. // security check
  19. if (TSession::getValue('logged') !== TRUE)
  20. {
  21. throw new Exception(_t('Not logged'));
  22. }
  23. ?>


Nataniel, a mensagem do email foi só um teste que fiz, o meu problema está exatamente na linha 24 " throw new Exception(_t('Not logged'));" se coloco o try, funciona, exibi a mensagem mas não para a execução, a tela é aberta. Será que o problema não é porque estou trabalhando em cima do app Blog back-end que baixei do Adianti ?</your>
NR

Pode ser sim, tente colocar um try/catch no index.php, aquele que fica fora da pasta admin.