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

New route group always return 404 #227

Open
kmergen opened this issue Jan 14, 2024 · 0 comments
Open

New route group always return 404 #227

kmergen opened this issue Jan 14, 2024 · 0 comments
Labels
status:to be verified Needs to be reproduced and validated.

Comments

@kmergen
Copy link

kmergen commented Jan 14, 2024

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
@xepozz xepozz added the status:to be verified Needs to be reproduced and validated. label Jan 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status:to be verified Needs to be reproduced and validated.
Projects
None yet
Development

No branches or pull requests

2 participants