Comment on page
Creating a custom controller for your extension
Learn how to write a custom admin page controller for your extension.
We are moving Blueprint's documentation to a brand new website within the following weeks. This documentation website will phase out in the future.
When doing advanced things with Blueprint, you can get extra freedom when creating a custom controller.
Begin by adding
<?php
at the top of your file, followed by your controller's namespace.<?php
namespace Pterodactyl\Http\Controllers\Admin\Extensions\__identifier__;
You don't need to change anything in the code above, Blueprint automatically replaces
__identifier__
with your extension's identifier.
Below that, import a couple libraries. If you want to import $blueprint as well, follow this guide after you finish with this one.
use Illuminate\View\View;
use Illuminate\View\Factory as ViewFactory;
use Pterodactyl\Http\Controllers\Controller;
Onto creating the controller's class.
class __identifier__ExtensionController extends Controller
{
}
Everything that we'll tell you happens within this class. So make sure you put your code inside the class and not under it.
Once again, Blueprint replaces
__identifier__
with your extension's identifier. If you want to learn more about this, read the placeholders documentation.
Here we construct some variables, so make sure you are paying attention.
public function __construct(
private ViewFactory $view,
) {}
Under that, create another function.
public function index(): View
{
}
Add the following code inside your
index()
function.return $this->view->make(
'admin.extensions.^#identifier#^.index', [
'root' => "/admin/extensions/^#identifier#^",
]
);
This will make the view and show it to the user. You can also add variables in here that you can show inside of your view.
return $this->view->make(
'admin.extensions.^#identifier#^.index', [
'root' => "/admin/extensions/^#identifier#^",
'placeholder' => "this is a placeholder",
]
);
Now inside of the view, you can use this variable by adding two curly brackets at the front and back:
{{ $variable }}
, or in this case {{ $placeholder }}
.
The finished result should look similar to the following code. Note that you should not copy paste this code by itself, as you might not know what everything does.
controller.php
1
<?php
2
3
namespace Pterodactyl\Http\Controllers\Admin\Extensions\__identifier__;
4
5
use Illuminate\View\View;
6
use Illuminate\View\Factory as ViewFactory;
7
use Pterodactyl\Http\Controllers\Controller;
8
9
class __identifier__ExtensionController extends Controller
10
{
11
public function __construct(
12
private ViewFactory $view,
13
) {}
14
15
public function index(): View
16
{
17
return $this->view->make(
18
'admin.extensions.^#identifier#^.index', [
19
'root' => "/admin/extensions/^#identifier#^",
20
]
21
);
22
}
23
}
That was everything. You have now coded a custom controller. Don't forget to add it to your conf.yml or Blueprint will keep using the default pre-made controller.
Last modified 27d ago