Invision Community 4: SEO, prepare for v5 and dormant account notifications By Matt Monday at 02:04 PM
Adriano Faria Posted August 24, 2022 Posted August 24, 2022 Would you please consider change the - (skeleton) from: class _{controller} extends \IPS\Dispatcher\Controller { /** * Execute * * @return void */ public function execute() { {restriction} parent::execute(); } /** * Manage * * @return void */ protected function manage() { /* Create the table */ $table = new \IPS\Helpers\Table\Db( '{table_name}', \IPS\Http\Url::internal( 'app={app}&module={module}&controller={controller}' ) ); /* Display */ \IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'global', 'core' )->block( 'title', (string) $table ); } } to: class _{controller} extends \IPS\Dispatcher\Controller { /** * Execute * * @return void */ public function execute() { {restriction} parent::execute(); } /** * Manage * * @return void */ protected function manage() { /* Create the table */ $table = new \IPS\Helpers\Table\Db( '{table_name}', $this->url() ); /* Display */ \IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'global', 'core' )->block( 'title', (string) $table ); } public function url() { return \IPS\Http\Url::internal( 'app={app}&module={module}&controller={controller}' ); } } This is basically to avoid use several times \IPS\Http\Url::internal( 'app=...' ) in same file. That would make things easier/faster when using the URLs in Admin table controllers. A few examples: - Row buttons: $table->rowButtons = function( $row ) { $return = array( 'edit' => array( 'title' => 'edit', 'icon' => 'pencil', 'link' => $this->url()->setQueryString( 'id', $row['id'] ), 'data' => array( 'ipsDialog' => '', 'ipsDialog-title' => \IPS\Member::loggedIn()->language()->addToStack('group_editing') ) ), ); $return['delete'] = array( 'title' => 'sign_out', 'icon' => 'times', 'link' => $this->url()->setQueryString( array( 'id' => $row['id'] ) )->csrf(), 'data' => array( 'delete' => '' ) ); return $return; }; - Action buttons: \IPS\Output::i()->sidebar['actions']['add'] = array( 'primary' => true, 'title' => 'add', 'icon' => 'plus', 'link' => $this->url()->setQueryString( array( 'do' => 'form' ) ), 'data' => array( 'ipsDialog' => '', 'ipsDialog-title' => \IPS\Member::loggedIn()->language()->addToStack('add') ) ); - Redirects: \IPS\Output::i()->redirect( $this->url(), 'saved' ); - Links: $link = ' <a href="' . $this->url() . '">' . \IPS\Member::loggedIn()->language()->addToStack( 'member_view_full_list' ) . '</a>'; Of course this can be handled by devs if they wish to optimize their code but again, this is just a suggestion for an enhancement in the skeleton. Nathan Explosion 1
Solution Daniel F Posted August 24, 2022 Solution Posted August 24, 2022 Not sure if I'm missing here something, but couldn't you just use $this->url? SeNioR- and Adriano Faria 1 1
Adriano Faria Posted August 24, 2022 Author Posted August 24, 2022 It seems so! I wasn't aware. Tks. 👍
Recommended Posts