- Совместимость с XenForo
- 2.1.x
- 2.2.x
Создаем свое приложение для Xenforo 2 командой:
Переходим по всем этапам что требует от вас команда, далее создается файл Setup.php с содержимым по умолчанию:
Далее в этот файл нужно дописать несколько строк с названием таблицы или таблиц и колонок в таблице:
После сохранения данных изменений удаляем наш плагин и снова устанавливаем и он создает 2 таблицы в нашем случае в базе данных.
Код:
php cmd.php xf-addon:create
PHP:
namespace XF\Games;
use XF\AddOn\AbstractSetup;
use XF\AddOn\StepRunnerInstallTrait;
use XF\AddOn\StepRunnerUninstallTrait;
use XF\AddOn\StepRunnerUpgradeTrait;
class Setup extends AbstractSetup
{
use StepRunnerInstallTrait;
use StepRunnerUpgradeTrait;
use StepRunnerUninstallTrait;
}
PHP:
namespace XF\Radio;
use XF\AddOn\AbstractSetup;
use XF\AddOn\StepRunnerInstallTrait;
use XF\AddOn\StepRunnerUninstallTrait;
use XF\AddOn\StepRunnerUpgradeTrait;
/*Добавляем данную строку для создания таблиц*/
use XF\Db\Schema\Create;
class Setup extends AbstractSetup
{
use StepRunnerInstallTrait;
use StepRunnerUpgradeTrait;
use StepRunnerUninstallTrait;
public function installStep1() {
$schemaManager = $this->schemaManager();
foreach ($this->getTables() AS $tableName => $closure) {
$schemaManager->createTable($tableName, $closure);
}
}
public function uninstallStep1() {
$schemaManager = $this->schemaManager();
foreach (array_keys($this->getTables()) AS $tableName) {
$schemaManager->dropTable($tableName);
}
}
/*Добавляем данный фрагмент кода где указываются таблицы и колонки*/
protected function getTables()
{
$tables = [];
$tables['xf_games']= function (Create $table)
{
$table->addColumn('games_id', 'int')->autoIncrement();
$table->addColumn('title', 'varchar', 100);
$table->addColumn('title_description', 'varchar', 100);
$table->addColumn('games_url', 'varchar', 500);
$table->addColumn('games_picture', 'varchar', 500);
$table->addColumn('games_date', 'int');
$table->addColumn('review_count', 'int')->setDefault(0);
};
$tables['xf_games_category'] = function (Create $table)
{
$table->addColumn('games_category_id', 'int')->autoIncrement();
$table->addColumn('title', 'varchar', 100);
$table->addColumn('title_description', 'varchar', 100);
$table->addColumn('display_order', 'int')->setDefault(0);
};
return $tables;
}
}