router
router copied to clipboard
New route group always return 404
What steps will reproduce the problem?
New route group.
What is the expected result?
Rendered view
What do you get instead?
404 not found error
Additional info
// config/common/routes.php
use App\Controller\SiteController;
use App\Backend\Controller\SiteController as BackendController;
use App\Controller\AccomodationController;
use Yiisoft\Router\Group;
use Yiisoft\Router\Route;
return [
Group::create('/{_language}')
->routes(
Route::get('/')->action([SiteController::class, 'index'])->name('home'),
Route::get('/kontakt')->action([SiteController::class, 'contact'])->name('kontaktformular'),
Route::get('/publikation')->action([SiteController::class, 'publication'])->name('publikation'),
Route::get('/test1')->action([SiteController::class, 'test1'])->name('test1'),
Route::get('/accomodation')->action([AccomodationController::class, 'index'])->name('overview'),
Route::get('/unterkunft/{slug}')->action([AccomodationController::class, 'show'])->name('showaccomodation'),
),
Group::create('/backend')
->routes(
Route::get('/')->action([BackendController::class, 'index'])->name('dashboard'),
),
];
// backend/Controller/SiteController.php
namespace App\Backend\Controller;
use Psr\Http\Message\ResponseInterface;
use Yiisoft\Yii\View\ViewRenderer;
use Yiisoft\Db\Connection\ConnectionInterface;
final class SiteController
{
public function __construct(private ViewRenderer $viewRenderer)
{
$this->viewRenderer = $viewRenderer
->withLayout('@resources/backend/views/layout/main')
->withViewPath('@resources/backend/views');
}
public function index(): ResponseInterface
{
/** @var ConnectionInterface $db */
// $rassen = $this->db->createCommand('SELECT * FROM {{%vdh_rassen}}')->queryAll();
// $rows = (new Query($this->db))
// ->select(['name', 'ursprungsland'])
// ->from('{{%vdh_rassen}}')
// ->where(['ursprungsland' => 'Japan'])
// ->limit(10)
// ->all();
return $this->viewRenderer->render('index');
}
}
if i do something like this it works:
Group::create('/{kk}')
->routes(
Route::get('/backend')->action([BackendController::class, 'index'])->name('dashboard'),
),
| Q | A |
|---|---|
| Version | 1.0.? |
| PHP version | 8.1 |
| Operating system | Windows 11 |