Guide
As previously mentioned, Devflow
is not a plug-and-play content management system (cms). Devflow
was created to give php programmers a tool to build bespoke websites, applications, and websites that may have complex domain business logic. It is a headless content management framework (CMF). You have the option to build out a frontend, or consume the REST api. Don't like REST, well it is a framework, and you are free to implement graphql
.
It is not a perfect tool, and it may not be to everyone's liking, and that's ok. It has taken a few years to get the system to this point; it is still an infant and definitely needs improvement.
It does includes helpful tools, but does not include everything and the kitchen sink. It is more of a repository for your data. For example, you can add products, but it is not a full featured store. This is something you will need to build out.
Devflow
is built on top of the CodefyPHP framework, which is a DDD framework with CQRS, and event sourcing. If you are not familiar with domain-driven development (DDD), I suggest you make yourself familiar with Aggregates and Service Bus
Custom Development
If you are wanting to build a frontend or add custom functionality, you can add your custom Controllers
and Routes
to the Cms
namespace and your custom views to resources/views/
. If you are building views for a frontend, then your views can go into resources/views/frontend/
. It is not mandatory that they go into that directory. You can change the name of put them into another directory. You just need to tell the system where to find it.
So, lets say that you want to build a frontend for example.com
. This is what you will need:
- A frontend controller or controllers depending on how you segment your code
- A route to serve your different requests
- And a view (presentation layer)
Controller
Our custom controller will go into Cms\Http\Controllers
, and will be named MyFrontendController.php
(Cms\Http\Controllers\MyFrontendController
):
<?php
declare(strict_types=1);
namespace Cms\Http\Controllers;
use Codefy\Framework\Http\BaseController;
use Psr\Http\Message\ResponseInterface;
final class MyFrontendController extends BaseController
{
public function index(): string|ResponseInterface
{
return $this->view->render(
template: 'cms::frontend/index',
data: [
'title' => 'Site Frontend',
'body' => '<h3>This is my frontend page.</h3>
]
);
}
}
Route
Next, we need to add our route. We will create a new route class in Cms\Http\Routes
called MyFrontendRoute
:
<?php
declare(strict_types=1);
namespace Cms\Http\Routes;
use Qubus\Routing\Router;
final class MyFrontendRoute
{
public function handle(Router $router): void
{
$router->get('/frontend/', 'MyFrontendController@index');
}
}
The handle
method has a Router
dependency which is taken care of by the system's Dependency Injector. Our route is frontend
which converts to example.com/frontend/
, and we use our controller as the callback along with the method. The system will automatically parse and run MyFrontendController@index
. The @
is important, so don't forget to add it between the class
and the method
. Lastly, the system has been setup to look for custom controllers in the Cms/Http/Controllers
directory, so this is where all your controllers must go.
To learn more about controllers, check out Creating Controllers and Creating Service Providers.
View
We need to create two views, one for the layout
and one for frontend
which will go into the resources/views/frontend/
folder:
layout.phtml
<!DOCTYPE html>
<html lang="en">
<head>
<base href="<?=site_url();?>">
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title><?=$this->esc($title ?? '');?></title>
<!-- Tell the browser to be responsive to screen width -->
<meta content="width=device-width, initial-scale=1, maximum-scale=6, user-scalable=yes" name="viewport">
</head>
<body>
<?php $this->block('frontend'); ?>
</body>
</html>
index.phtml
<?php
declare(strict_types=1);
$this->parent('cms::frontend/layout');
$this->block('frontend', function ($params) {
echo 'Page Title: ' . $params['title'];
echo 'Page Content: ' . $params['body'];
});
To learn more about views and namespacing views, check out Creating Views
Putting it together
Now that we have our controller, route and views, it is time to put it together to make it work.
First, open config/routes.php
to add your route. It should look similar to this:
<?php
use Cms\Http\Routes\MyFrontendRoute;
return [
'example.com' => MyFrontendRoute::class,
];
The key for your route is the hostname
. Why, you ask? Well, Devflow
supports multisite. It is disabled by default because it is an experimental feature and should not be used in production. Therefore, when the site is loaded, the correct route will be loaded based on the hostname.
And that is it. The system will automatically load the controller and execute the handle
method, our views are in place, and the route has been set in config/routes.php
. All that's left now is to visit http://example.com/frontend/
and you should see the title
and the content
.