Redirect v try cache vyvola vynimku – nevolana funckia terminate
Upozornění: Tohle vlákno je hodně staré a informace nemusí být platné pro současné Nette.
- japlavaren
- Člen | 404
Zdravim,
uplne cisty kod vyvola vynimku funkcie terminate z presenteru.
nechapem
<?php
public function createComponentTest($name) {
$form = new NAppForm($this, $name);
$form->addSubmit("save", "Uložiť");
$form->onSuccess[] = callback($this, "testSubmitted");
return $form;
}
public function testSubmitted(NAppForm $form)
{
try {
$this->redirect("default"); # ked ho zakomentujem je to ok
}
catch(Exception $e) {
NDebugger::dump($e);
$form->addError($e->getMessage());
}
}
?>
prikladam aj celu vynimku
<?php
NAbortException(8) {
message protected => ""
string private => ""
code protected => 0
file protected => "C:\wamp\www\simpleCms\libs\Nette\Application\UI\Presenter.php" (61)
line protected => 612
trace private => array(16) [
0 => array(6) {
file => "C:\wamp\www\simpleCms\libs\Nette\Application\UI\Presenter.php" (61)
line => 596
function => "terminate" (9)
class => "NPresenter" (10)
type => "->" (2)
args => array(0)
}
1 => array(6) {
file => "C:\wamp\www\simpleCms\libs\Nette\Application\UI\Presenter.php" (61)
line => 658
function => "sendResponse" (12)
class => "NPresenter" (10)
type => "->" (2)
args => array(1) [ ... ]
}
2 => array(6) {
file => "C:\wamp\www\simpleCms\libs\Nette\Application\UI\PresenterComponent.php" (70)
line => 376
function => "redirectUrl" (11)
class => "NPresenter" (10)
type => "->" (2)
args => array(2) [ ... ]
}
3 => array(6) {
file => "C:\wamp\www\simpleCms\app\AdminModule\presenters\HomepagePresenter.php" (70)
line => 14
function => "redirect" (8)
class => "NPresenterComponent" (19)
type => "->" (2)
args => array(1) [ ... ]
}
4 => array(4) {
function => "testSubmitted" (13)
class => "Admin_HomepagePresenter" (23)
type => "->" (2)
args => array(1) [ ... ]
}
5 => array(4) {
file => "C:\wamp\www\simpleCms\libs\Nette\common\Callback.php" (52)
line => 103
function => "call_user_func_array" (20)
args => array(2) [ ... ]
}
6 => array(6) {
file => "C:\wamp\www\simpleCms\libs\Nette\common\ObjectMixin.php" (55)
line => 57
function => "invokeArgs" (10)
class => "NCallback" (9)
type => "->" (2)
args => array(1) [ ... ]
}
7 => array(6) {
file => "C:\wamp\www\simpleCms\libs\Nette\common\Object.php" (50)
line => 79
function => "call" (4)
class => "NObjectMixin" (12)
type => "::" (2)
args => array(3) [ ... ]
}
8 => array(6) {
file => "C:\wamp\www\simpleCms\libs\Nette\Forms\Form.php" (47)
line => 418
function => "__call" (6)
class => "NObject" (7)
type => "->" (2)
args => array(2) [ ... ]
}
9 => array(6) {
file => "C:\wamp\www\simpleCms\libs\Nette\Forms\Form.php" (47)
line => 418
function => "onSuccess" (9)
class => "NAppForm" (8)
type => "->" (2)
args => array(1) [ ... ]
}
10 => array(6) {
file => "C:\wamp\www\simpleCms\libs\Nette\Application\UI\Form.php" (56)
line => 133
function => "fireEvents" (10)
class => "NForm" (5)
type => "->" (2)
args => array(0)
}
11 => array(6) {
file => "C:\wamp\www\simpleCms\libs\Nette\Application\UI\Presenter.php" (61)
line => 297
function => "signalReceived" (14)
class => "NAppForm" (8)
type => "->" (2)
args => array(1) [ ... ]
}
12 => array(6) {
file => "C:\wamp\www\simpleCms\libs\Nette\Application\UI\Presenter.php" (61)
line => 176
function => "processSignal" (13)
class => "NPresenter" (10)
type => "->" (2)
args => array(0)
}
13 => array(6) {
file => "C:\wamp\www\simpleCms\libs\Nette\Application\Application.php" (60)
line => 132
function => "run" (3)
class => "NPresenter" (10)
type => "->" (2)
args => array(1) [ ... ]
}
14 => array(6) {
file => "C:\wamp\www\simpleCms\app\bootstrap.php" (39)
line => 33
function => "run" (3)
class => "NApplication" (12)
type => "->" (2)
args => array(0)
}
15 => array(4) {
file => "C:\wamp\www\simpleCms\www\index.php" (35)
line => 22
args => array(1) [ ... ]
function => "require" (7)
}
]
previous private => NULL
xdebug_message => "
NAbortException: in C:\wamp\www\simpleCms\libs\Nette\Application\UI\Presenter.php on line 612
Call Stack:
0.0003 678224 1. {main}() C:\wa ... " (1988)
}
?>
Editoval japlavaren (1. 7. 2011 16:34)
- japlavaren
- Člen | 404
potom nechapem preco je to tak
<?php
public function newPageFormSubmitted(NAppForm $form) {
try {
if($form["save"]->isSubmittedBy()) {
$values = $form->values;
try {
$this->model->addPage($values);
}
catch(PDOException $e) {
if($e->errorInfo[1] === 1062)
throw new Exception("Stránka s názvom '$values[name]' už exituje");
else
throw new Exception("Stránku sa nepodarilo uložiť. Skúste to prosím znovu");
}
}
$this->redirect("default");
}
catch(Exception $e) {
$form->addError($e->getMessage());
}
}
?>
v tomto pripade by to moc pomohlo, ak by to nic nehadzalo (prave rozmyslam ako to prepisat aby to bolo funkcne a nemusel si to ukladat do premennej)
- Honza Marek
- Člen | 1664
catch (NAbortException $e) {
throw $e;
} catch (Exception $e) {
$form->addError($e->getMessage());
}
Nebo lépe odchytávat jen konkrétní výjimky, který můžou nastat. Nemluvě o tom, že cpaní jakékoliv výjimky do chybové hlášky formuláře je blbost. Co když příště bude textem výjimky, že se nemůže připojit do databáze aaa s heslem xxx?