Skip to content

Route naming and Groups #612

Description

@daylightstudio

I'm experiencing an issue with routing where the options in the route group (e.g. 'namespace') are being overwritten. For example, the following I would expect the URI admin/user/create to work:

$routes->group('admin', ['namespace' => 'Admin\Controllers'], function($routes)
{
	$routes->get('user/create', 'UserController::create', ['as' => 'user_create']);
}

However, because I added the ['as' => 'user_create'], it overwrites the default options and loses the 'namespace' option. I'd like to propose replacing the lines around 1120 in the RouteCollection::create method (https://github.com/bcit-ci/CodeIgniter4/blob/develop/system/Router/RouteCollection.php#L1120):

if (is_null($options))
{
	$options = $this->currentOptions;
}

with something like the following so that the current group options get merged with the passed options:

$options = array_merge((array)$this->currentOptions, (array)$options);

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions