Concat Router Parameters

Hi,

I want to concat router parameters but i couldnt find how to.

My URLs like that:

/settings/users

/settings/users/add

/settings/users/edit/47

/settings/users/delete/47

My Controller like that:

class Settings extends Controller
{
    public function users() {}
    public function usersAdd() {}
    public function usersEdit() {}
    public function usersDelete() {}
}

My router like that:

$router->add('/settings/users/:action', array(
    'controller' => 'settings',
    'action' => 'users' // Should be with action name with ucfirst like usersAdd
));

I want to create once route for multiple action. For ex: users + add so usersAdd

Just change action to 1, but it won't work like this anyway, you would need to use some logic in beforeExecuteRoute anyway. Also it's really bad having /add /edit/ delete routes. You should use POST, PUT, DELETE queries and just have only /settings/users



2.8k
edited 3d ago

Save the future headache from coming and set your routes up properly.

https://docs.phalconphp.com/en/3.0.2/reference/routing.html#http-method-restrictions

$objRouter->add(
    "/settings/users",
    array(
        "controller" => "settings",
        "action"  => "users"
    )
)->via("GET");

//Add a user
$objRouter->add(
    "/settings/users",
    array(
        "controller" => "settings",
        "action"  => "usersAdd"
    )
)->via("POST");

//Edit a user
$objRouter->add(
    "/settings/users/([0-9]+)",
    array(
        "controller" => "settings",
        "action"  => "usersEdit",
        "userid" => 1
    )
)->via("PUT");

//Remove a user
$objRouter->add(
    "/settings/users/([0-9]+)",
    array(
        "controller" => "settings",
        "action"  => "usersDelete",
        "userid" => 1
    )
)->via("DELETE");