how to open presenter in browser address

Notice: This thread is very old.
navotera
Member | 4
+
0
-
  1. 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

  2. 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..

Oli
Member | 1215
+
+1
-

It should be Homepage/default. In case you use actionOut It is homepage/out. Homepage/default is default so It is samé as nothing.

Diferent is in love cycle. Action is called before render.

pata.kusik111
Member | 78
+
+1
-

With the default Nette web-project:

  1. 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.
  2. 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.
Šaman
Member | 2659
+
+1
-

For action/render/handler see documentation.

navotera
Member | 4
+
0
-

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
+
0
-

Even if you dont write renderXxx() method, Nette try find template with name taken from route.
Nette is MVC framefork, there is no simple support for direct output.

If you need it, you must write output in action method and terminate next processing by $this->terminate().

navotera
Member | 4
+
0
-

i just wandering what if i just want to view json format in the webpage… or simple echo or print_r for debugging.. your advice $this->terminate() seem work but the variable is in the <body> tag.
so nette is not support restful by default by the way ? thank Saman.

Šaman
Member | 2659
+
+1
-

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
+
+1
-

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
}
navotera
Member | 4
+
0
-

great thanks case closed ;)