how to open presenter in browser address
- navotera
- Member | 4
- i have Homepage presenter i want to view what inside it in homepage. how
can i open it in webaddress ?
with this http://localhost/…epage/action it wont open
- what the different between method action and render.. forexample i have
this two method…
actionOut() and renderOut() in the Homepage Presenter when i route it it nette cannot make any different between two..
- pata.kusik111
- Member | 78
With the default Nette web-project:
- http://localhost/homepage/{something} will use the
“Homepage” presenter and the “{something}” action name in it. So
“http://localhost/homepage/action” will use “Homepage” presenter and the
“action” action (
actionAction
) and “action” render (renderAction
) method in it. - The difference is in what are they used for. Both of them will be run, if you are at “http://localhost/homepage/out”. The action method will run first, the render method second. The action method is usually used for thing, that may cause redirect (for example in action method you can find that you don't have the data you want to display and redirect elsewhere), since you cannot redirect in render method. And the render method is usually used to fill the template with the data you want to be displayed.
- navotera
- Member | 4
thanks for all your response.. it seem this community is helpful for beginner
like me..
although firstly im afraid nette is not US or English Based community… :)
i try to use this method
//in HomepagePresenter
public function actionOut() {
echo ‘anything’;
}
my purpose is just to echo simple string but nette keep looking for the out.latte template/layout.. anything i miss ?
Last edited by navotera (2016-03-08 12:17)
- Šaman
- Member | 2659
For JSON there are
<?php
$this->sendResponse( new Nette\Application\Responses\JsonResponse($json) );
?>
For debugging is
<?php
dump($var); # or any type of variable
?>
Render methods are common for MVC pattern. If you need something special, use sendResponse() instead. Or shortcut for send json.
Last edited by Šaman (2016-03-08 21:24)
- Jan Mikeš
- Member | 771
Well it is supported, it is possible to NOT use the View component of MVC
model.
Use sendJson()
method in presenter, this allows you to build REST api application with nette,
without need of using templates.
public function actionDefault()
{
$data = $this->myModel->fetchData(); // etc.., contains array
$this->sendJson($data); // not need to use $this->terminate() anymore, because this sends the response directly
}