Skip to content

Commit

Permalink
#244 Implemented passing route parameters to controller methods
Browse files Browse the repository at this point in the history
  • Loading branch information
danon committed Nov 29, 2016
1 parent a92505d commit f1d9fe6
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/Ouzo/Core/FrontController.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,9 @@ private function _invokeAfterMethods()

private function _invokeAction()
{
$currentAction = $this->currentControllerObject->currentAction;
$this->currentControllerObject->$currentAction();
$controller = $this->currentControllerObject;
$currentAction = $controller->currentAction;
call_user_func_array(array($controller, $currentAction), $controller->params);

This comment has been minimized.

Copy link
@bbankowski

bbankowski Nov 30, 2016

Member

Only route parameters should be passed, not all params! (i.e. POST).

$this->_logRequestIfDebugEnabled();
}

Expand Down
21 changes: 21 additions & 0 deletions test/src/Ouzo/Core/ControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,12 @@ public function string_output()
$this->layout->renderAjax('ONLY OUTPUT');
$this->layout->unsetLayout();
}

public function receive_params($user, $page)

This comment has been minimized.

Copy link
@bbankowski

bbankowski Nov 30, 2016

Member

Method should be renamed to camel case.

{
$this->layout->renderAjax("Param1: $user Param2: $page");
$this->layout->unsetLayout();
}
}

class ControllerTest extends ControllerTestCase
Expand Down Expand Up @@ -169,6 +175,21 @@ public function shouldDownloadFile()
$this->assertDownloadsFile('file.txt');
}

/**
* @test
*/
public function shouldPassUrlParametersToControllerAction()
{
// given
Route::get('/simple_test/receive_params/:user/:page', 'simple_test#receive_params');

// when
$this->get('/simple_test/receive_params/Cersei/about-us');

// then
$this->assertRenderedContent()->isEqualTo('Param1: Cersei Param2: about-us');
}

/**
* @test
*/
Expand Down

0 comments on commit f1d9fe6

Please sign in to comment.