What I'm trying to do is to break down c5 single page controllers and views to be closer to RESTful API.
Take for example a Classifieds package. It has a Dashboard controller called Classifieds in packages/classifieds/controllers/single_page/dashboard/classifieds.php and a corresponding single page view in packages/classifieds/single_pages/dashboard/classifieds.php. This page is templated and themed as any other Dashboard page.
The controller has many actions: view, add, edit, save, delete etc. All code is in the single kilometer long file. Same with the view, all action views are in that single kilometer long file. All is working - no problem. But it's a nightmare to find and edit.
What I want is the following. I want to be able to have a single Dashboard templated page (e.g. like a Laravel's layout app.blade.php) and a number of separate view files with content depending on the controller actions, e.g. index.php, create.php, edit.php, show.php etc. which would be inserted into the main template page. This way each file will be nice and short. Can this be done?
I've tried following this doc: https://documentation.concrete5.org/developers/framework/routing/views
but it doesn't work because all c5 themes need stylesheets and my content doesn't render. I tried this:
RouteList:
use Concrete\Core\Routing\RouteListInterface;
use Concrete\Core\Routing\Router;
class RouteList implements RouteListInterface
{
public function loadRoutes($router)
{
$api = $router->buildGroup()
->setPrefix('/dashboard')
->setNamespace('MyPackage\Controllers')
->routes(function($groupRouter) {
$groupRouter->get('/my_package', 'TestController::index');
});
}
}
Controller:
use Concrete\Core\Http\ResponseFactoryInterface;
use Concrete\Core\Controller\Controller;
use Concrete\Core\View\View;
class TestController extends Controller
{
protected $responseFactory;
public function __construct(ResponseFactoryInterface $responseFactory)
{
$this->responseFactory = $responseFactory;
}
public function index()
{
$view = new View('test');
$view->setPackageHandle('my_package');
$view->setController($this);
$view->setViewTheme('elemental');
$view->setViewTemplate('full');
$this->set('content', 'This is a test');
return $this->responseFactory->view($view);
}
}
View:
<?php defined('C5_EXECUTE') or die("Access Denied.");
echo $content;
?>