TemKa_SD Posted October 23, 2018 Share Posted October 23, 2018 Здравствуйте. Пишу просто модуль, для добавления/редактирования/удаления записей из БД. Получилось следующее: <?php namespace IPS\sharedstats\modules\admin\stats; /* To prevent PHP errors (extending class does not exist) revealing path */ if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) ) { header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' ); exit; } /** * announce */ class _announce extends \IPS\Dispatcher\Controller { /** * Execute * * @return void */ public function execute() { \IPS\Dispatcher::i()->checkAcpPermission( 'Can change announce?' ); \IPS\sharedstats\DB::get(); parent::execute(); } /** * Manage * * @return void */ protected function manage() { /* Create the table */ $table = new \IPS\sharedstats\DbIntegration\Db( 'stats_announces', \IPS\Http\Url::internal( 'app=sharedstats&module=stats&controller=announce' ), NULL, NULL, NULL, 'stats' ); $table->langPrefix = 'sharedstats_stats_announce_'; /* Root buttons */ $table->rootButtons = array( 'add' => array( 'icon' => 'cross', 'title' => 'sharedstats_stats_announce_announce_add', 'link' => \IPS\Http\Url::internal( 'app=sharedstats&module=stats&controller=announce&do=add' ), ) ); /* Row buttons */ $table->rowButtons = function ( $row ) { $return['edit'] = array( 'icon' => 'pencil', 'title' => 'edit', 'link' => \IPS\Http\Url::internal( 'app=sharedstats&module=stats&controller=announce&do=edit&id=' . $row['id'] ), ); $return['del'] = array( 'icon' => 'times-circle', 'title' => 'sharedstats_stats_announce_announce_delete', 'link' => \IPS\Http\Url::internal( 'app=sharedstats&module=stats&controller=announce&do=delete&id=' . $row['id'] ), ); return $return; }; /* Display */ \IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('menu__sharedstats_stats_announce'); \IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'global', 'core' )->block( 'title', (string) $table ); } protected function add() { $form = new \IPS\Helpers\Form(); $form->addHeader( 'sharedstats_stats_announce_announce_add' ); $form->add( new \IPS\Helpers\Form\TextArea( 'sharedstats_stats_announce_announce_add', null, true)); if ( $values = $form->values() ) { $ann = new \IPS\sharedstats\Records\Announce; $ann->text = mb_strtolower($values['sharedstats_stats_announce_announce_add']); $ann->save(); \IPS\Output::i()->redirect(\IPS\Http\Url::internal( 'app=sharedstats&module=stats&controller=announce', 'admin' ), 'sharedstats_stats_announce_announce_added'); } \IPS\Output::i()->output = $form; } protected function edit() { $id = \IPS\Request::i()->id; $announce = \IPS\sharedstats\Records\Announce::load($id); $form = new \IPS\Helpers\Form(); $form->addHeader( 'sharedstats_stats_announce_announce_add' ); $form->add( new \IPS\Helpers\Form\TextArea( 'sharedstats_stats_announce_announce_add', null, true)); if ( $values = $form->values() ) { $announce->text = mb_strtolower($values['sharedstats_stats_announce_announce_add']); $announce->save(); \IPS\Output::i()->redirect(\IPS\Http\Url::internal( 'app=sharedstats&module=stats&controller=announce', 'admin' ), 'sharedstats_stats_announce_announce_added'); } \IPS\Output::i()->output = $form; } protected function delete() { $id = \IPS\Request::i()->id; $announce = \IPS\sharedstats\Records\Announce::load($id); $announce->delete(); \IPS\Output::i()->redirect(\IPS\Http\Url::internal( 'app=sharedstats&module=stats&controller=announce', 'admin' ), 'sharedstats_stats_announce_announce_deleted'); } } Не могу вывести форму редактирования, не отображается текст: http://prntscr.com/l9bo0h не обращайте внимание на названия, функционал взят из формы добавления. Link to comment Share on other sites More sharing options...
TemKa_SD Posted October 23, 2018 Author Share Posted October 23, 2018 Извиняюсь, сам сделал. $form->add( new \IPS\Helpers\Form\TextArea( 'sharedstats_stats_announce_announce_add', $announce->text, true)); Link to comment Share on other sites More sharing options...
TemKa_SD Posted October 23, 2018 Author Share Posted October 23, 2018 Скажите вот что, а то мне непонятно. $form->add( new \IPS\Helpers\Form\TextArea( 'sharedstats_stats_announce_announce_add', null, true)); if ( $values = $form->values() ) { $ann->text = mb_strtolower($values['sharedstats_stats_announce_announce_add']); Текст sharedstats_stats_announce_announce_add - это фраза из языкового файла, переводится она как Добавить объявление. По этой фразе идет инициализация переменной по котором заполняется форма, почему оно так работает, когда переменная на русском в двух словах? Link to comment Share on other sites More sharing options...
newbie Posted October 24, 2018 Share Posted October 24, 2018 По этой фразе идет инициализация переменной по котором заполняется форма, почему оно так работает, когда переменная на русском в двух словах? Не понятно, что не понятно.Ключ sharedstats_stats_announce_announce_add можно использовать где угодно{lang="sharedstats_stats_announce_announce_add"}{setting="sharedstats_stats_announce_announce_add"}и т.д. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now