When I navigate to /cart on my Thelia site, it renders the custom 404 view in templates/frontOffice/myproject/404.html. I suspect this has something to do with my page-based routing scheme, which is supposed to route arbitrary top-level URLs like /some-page to PageController, part of MyProject module, which finds a matching Content record and displays it.
The routing.xml config is supposed make exceptions for special Thelia routes and default to the core's behavior. It seems to be picking up the 404.html view but not via PageController, because any edits to the controller code do not seem to affect what's rendered, even having cleared the cache and viewed the page in dev mode.
What's going on?
Here's my custom module's routing.xml:
<?xml version="1.0" encoding="UTF-8"?>
<routes xmlns="http://symfony.com/schema/routing"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/routing http://symfony.com/schema/routing/routing-1.0.xsd">
<route id="myproject.home" path="/" methods="get">
<default key="_controller">MyProject\Controller\PageController::homeAction</default>
</route>
<route id="myproject.rentals" path="/rentals" methods="get">
<default key="_controller">MyProject\Controller\RentalController::indexAction</default>
</route>
<route id="myproject.rentals.show" path="/rentals/{slug}" methods="get">
<default key="_controller">MyProject\Controller\RentalController::showAction</default>
</route>
...
<route id="myproject.page" path="/{slug}" methods="get">
<default key="_controller">MyProject\Controller\PageController::showAction</default>
<!-- treat arbitrary top-level routes as pages, except a few special cases that should honor Thelia defaults -->
<requirement key="slug">^(?!admin|cart|register|login|password|password-sent|logout|account|sitemap|empty)[^/]+</requirement>
</route>
</routes>
Here's my controller code:
<?php
namespace MyProject\Controller;
use Thelia\Controller\Front\BaseFrontController;
use MyProject\Model\ContentQuery;
use MyProject\ServicesTrait;
/**
* Controller for displaying arbitrary pages
*/
class PageController extends BaseFrontController
{
use ServicesTrait;
public function homeAction() {
$query = $this->getQueryFactory()->createContentQuery();
return $this->render('index', ['page' => $query->findHomePage()]);
}
public function showAction($slug) {
$query = $this->getQueryFactory()->createContentQuery();
if ($page = $query->findOneBySlug($slug)) {
$rendered = $this->render('interior', ['page' => $page]);
} else {
die('reached 404 code'); // this doesn't seem to run???
$rendered = $this->render('404', []);
}
return $rendered;
}
}
Last edited by ctamayo (13-09-2017 00:40:06)