No problem here is the code.
src/
└── addons/
└── HolaMundo/
├── _data/
│ └── addon.json
├── Setup.php
├── XF/
│ ├── Pub/
│ │ └── Controller/
│ │ └── Hola.php
│ └── Template/
│ └── hola_mundo.html
addon.json.
{
"legacy_addon_id": "",
"title": "Hola Mundo",
"description": "Un addon que muestra 'Hola Mundo'.",
"version_id": 1000010,
"version_string": "1.0.0",
"dev": "TuNombre",
"dev_url": "
https://tusitio.com",
"support_url": "
https://tusitio.com/soporte",
"require": {
"XF": [2030000, "XenForo 2.3.0+"]
}
}
setup.php
<?php
namespace HolaMundo;
use XF\AddOn\AbstractSetup;
use XF\AddOn\StepRunnerInstallTrait;
use XF\AddOn\StepRunnerUninstallTrait;
use XF\AddOn\StepRunnerUpgradeTrait;
class Setup extends AbstractSetup
{
use StepRunnerInstallTrait;
use StepRunnerUninstallTrait;
use StepRunnerUpgradeTrait;
public function installStep1()
{
$this->createRoutePrefix();
}
public function uninstallStep1()
{
$this->deleteRoutePrefix();
}
public function upgrade(array $previousVersion, array &$stateChanges)
{
// Lógica de actualización
}
protected function createRoutePrefix()
{
$this->db()->insert('xf_route_prefix', [
'route_prefix' => 'hola',
'route_class' => 'HolaMundo\XF\Pub\Controller\Hola',
'context' => 'public',
'addon_id' => 'HolaMundo'
]);
}
protected function deleteRoutePrefix()
{
$this->db()->delete('xf_route_prefix', 'route_prefix = ?', 'hola');
}
}
Hola.php
<?php
namespace HolaMundo\XF\Pub\Controller;
use XF\Mvc\ParameterBag;
use XF\Pub\Controller\AbstractController;
class Hola extends AbstractController
{
public function actionIndex(ParameterBag $params)
{
$viewParams = [
'message' => 'Hola Mundo'
];
return $this->view('HolaMundo:Hola', 'hola_mundo', $viewParams);
}
}
hola_mundo.html
<h1>{$message}</h1>