Knowledge Base   /   Customize   /   v6.0

How to create a new page?

Posted on 05 December 2021 12:16 pm

This is an example to create a new page called development and the url to access will be http://yoursite.com/pages/development

First, it's necessary to create a class page in directory /includes/controllers like Development.php, we'll create a method called "show" like this:

<?php
namespace
Evolution\Controllers;


class Development extends BaseController
{
public function show()
{
view('development');
}
}

This example will call the template file development.tpl, template files are located in /includes/template

Second, we'll create a route to call this class when user visit the url http://yoursite.com/pages/development
We are creating a file called developmentRoute.php and it will be saved in /includes/routing, here is the example code:

<?php
return
[
'developer_route' => [
'path' => '/pages/development',
'controller' => [
\Evolution\Controllers\Development::class,
'show'
]
]
];

If you want to add a link to this page, then you can generate the url using route_to('developer_route'), so in your template you can add the line:

<a href="{route_to('developer_route')}">My Link</a>

If you want to create a page where only logged members can access, then the controller page should be like this:

<?php
namespace
Evolution\Controllers;


use Evolution\Components\Services;

class Development extends BaseController
{
public function show()
{
$user = Services::user();
if($user->isOnline()){
redirect(route_to('login'));
}
view('development');
}
}