@@ -440,6 +440,60 @@ of ``connect()``::
440440 // Set lang to be a persistent parameter
441441 ->setPersist(['lang']);
442442
443+ Setting Default Options for Routes in a Scope
444+ ----------------------------------------------
445+
446+ You can set default options that will be applied to all routes within a scope
447+ using the ``setOptions() `` method. This is useful when you want to apply the
448+ same options (like ``_host ``, ``_https ``, or ``_port ``) to multiple routes
449+ without repeating them::
450+
451+ $routes->scope('/api', function (RouteBuilder $routes) {
452+ // Set default options for all routes in this scope
453+ $routes->setOptions([
454+ '_host' => 'api.example.com',
455+ '_https' => true
456+ ]);
457+
458+ // These routes will automatically have _host and _https set
459+ $routes->get('/users', ['controller' => 'Users', 'action' => 'index']);
460+ $routes->get('/posts', ['controller' => 'Posts', 'action' => 'index']);
461+ });
462+
463+ Options set via ``setOptions() `` are:
464+
465+ - **Inherited by nested scopes ** - Child scopes automatically receive the parent's default options
466+ - **Overridable on individual routes ** - Options passed to ``connect() `` or HTTP verb methods take precedence over defaults
467+ - **Merged with route-specific options ** - Default options are combined with any options you specify on individual routes
468+
469+ Example with nested scopes and overrides::
470+
471+ $routes->scope('/api', function (RouteBuilder $routes) {
472+ $routes->setOptions(['_host' => 'api.example.com']);
473+
474+ // This route uses the default host
475+ $routes->get('/public', ['controller' => 'Public', 'action' => 'index']);
476+
477+ // This route overrides the default host
478+ $routes->get('/internal', [
479+ 'controller' => 'Internal',
480+ 'action' => 'index',
481+ '_host' => 'internal.example.com'
482+ ]);
483+
484+ // Nested scope inherits the default host
485+ $routes->scope('/v2', function (RouteBuilder $routes) {
486+ // This also uses api.example.com
487+ $routes->get('/users', ['controller' => 'Users', 'action' => 'index']);
488+ });
489+ });
490+
491+ The ``setOptions() `` method is particularly useful for:
492+
493+ - Setting the same ``_host `` for an entire API scope
494+ - Enforcing ``_https => true `` for secure sections of your application
495+ - Configuring ``_port `` for routes that should use non-standard ports
496+
443497Passing Parameters to Action
444498----------------------------
445499
0 commit comments