Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Weird behaviour when using controllers #69

Open
ghost opened this issue Sep 5, 2017 · 1 comment
Open

Weird behaviour when using controllers #69

ghost opened this issue Sep 5, 2017 · 1 comment

Comments

@ghost
Copy link

ghost commented Sep 5, 2017

Something that caught me off guard suddenly after many hours of programming:

Routes.php:
$router->controller('/term/config/forms', 'TERM\\FormConfigController');

The specific controller.php file:
`namespace TERM;

class FormConfigController extends \Controller {
public static function getIndex(){
//do something...
}
public static function getActivate($formID){
return A;
}
public static function getEditform($formID, $action = null, $actionValue = null){
return B;
}
`

If I now use the following URL:
some.domain/term/config/forms/editform/20
It results in the getActivate method being called. However, and this is quite peculiar, if I swap getActivate and getEditForm methods around, then it works as expected.

Could someone please explain if this is either a bug, a design flaw from my side, or just a strange way of how this system works?

@crichardson9
Copy link

I'd do it this way:

$router->get('/term/config/forms/editform/{id:i}', ['TERM\\FormConfigController, 'getEditForm']);

and:

public static function getEditForm($formId)
{
    return $formId;
}

If you want to continue using the controller method, I believe you must ensure that your function has the same parameters. For example:

public static function getEditform($formID)
{
    return B;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant