Abdy Posted March 22, 2017 Report Posted March 22, 2017 Hi I'm developing a plugin, but when I try to make a controller on the admin side, I only get a blank page, I tried almost everything and I can fix it. I'm using Blesta v4.0 beta 5 My code is: <?php class AdminPages extends AppController { private function init() { // Require Login $this->parent->requireLogin(); // Load Language Language::loadLang('plugin_dir', null, PLUGINDIR.'plugin_dir'.DS.'language'.DS); } public function index() { $this->init(); } } Thanks. Quote
Blesta Addons Posted March 22, 2017 Report Posted March 22, 2017 what is the content of the pdt file . use this code and see what you will have public function index() { $this->init(); die("admin page"); } Quote
Tyson Posted March 22, 2017 Report Posted March 22, 2017 I don't know what "$this->parent" is. You can use "$this->requireLogin()" You should be extending your plugin's parent controller that extends AppController and implements the preAction method. The dispatcher throws an exception when attempting to load controllers that do not implement the preAction. Blesta Addons and Michael 2 Quote
Blesta Addons Posted March 23, 2017 Report Posted March 23, 2017 use the debugger plugin, it will help you identifying the error line . Quote
Abdy Posted March 24, 2017 Author Report Posted March 24, 2017 On 3/22/2017 at 2:29 PM, Blesta Addons said: what is the content of the pdt file . use this code and see what you will have public function index() { $this->init(); die("admin page"); } The content of the pdt file (admin_pages.pdt) is: <div class="title_row first"> <h3>Hello World</h3> </div> On 3/22/2017 at 5:33 PM, Tyson said: I don't know what "$this->parent" is. You can use "$this->requireLogin()" You should be extending your plugin's parent controller that extends AppController and implements the preAction method. The dispatcher throws an exception when attempting to load controllers that do not implement the preAction. I updated the code to: <?php class AdminPages extends BlestaCmsController { public function preAction() { // Parent pre-action parent::preAction(); // Require login $this->requireLogin(); // Load language Language::loadLang('blesta_cms', null, PLUGINDIR.'blesta_cms'.DS.'language'.DS); $this->company_id = Configure::get('Blesta.company_id'); $this->structure->set('page_title', Language::_('blesta_cms.page_title', true)); $this->view->setView(null, 'BlestaCms.default'); } public function index() { //die("admin page"); } } and now shows the pdt, but without the structure. 19 hours ago, Blesta Addons said: use the debugger plugin, it will help you identifying the error line . I have enabled the debugger plugin with Tracy but not shows anything Quote
Blesta Addons Posted March 24, 2017 Report Posted March 24, 2017 you will not recieve any error , the probleme is only you are not set the correct view dir . what you should do is the fallowing : 1 - create a file called blesta_cms_controller.php in the main root plugin directory with the fallowing content <?php /** * Blesta Cms Plugin * */ class BlestaCmsController extends AppController { /** * Setup */ public function preAction() { $this->structure->setDefaultView(APPDIR); parent::preAction(); $this->company_id = Configure::get("Blesta.company_id"); // Override default view directory $this->view->view = "default"; $this->orig_structure_view = $this->structure->view; $this->structure->view = "default"; } } in your admin_page.php change the code to fallowing : <?php class AdminPages extends BlestaCmsController { public function preAction() { // Parent pre-action parent::preAction(); // Require login $this->requireLogin(); // Load language Language::loadLang('blesta_cms', null, PLUGINDIR.'blesta_cms'.DS.'language'.DS); // Restore structure view location of the admin portal $this->structure->setDefaultView(APPDIR); $this->structure->setView(null, $this->orig_structure_view); } public function index() { //die("admin page"); } } Abdy and Michael 2 Quote
Abdy Posted March 24, 2017 Author Report Posted March 24, 2017 7 hours ago, Blesta Addons said: you will not recieve any error , the probleme is only you are not set the correct view dir . what you should do is the fallowing : 1 - create a file called blesta_cms_controller.php in the main root plugin directory with the fallowing content <?php /** * Blesta Cms Plugin * */ class BlestaCmsController extends AppController { /** * Setup */ public function preAction() { $this->structure->setDefaultView(APPDIR); parent::preAction(); $this->company_id = Configure::get("Blesta.company_id"); // Override default view directory $this->view->view = "default"; $this->orig_structure_view = $this->structure->view; $this->structure->view = "default"; } } in your admin_page.php change the code to fallowing : <?php class AdminPages extends BlestaCmsController { public function preAction() { // Parent pre-action parent::preAction(); // Require login $this->requireLogin(); // Load language Language::loadLang('blesta_cms', null, PLUGINDIR.'blesta_cms'.DS.'language'.DS); // Restore structure view location of the admin portal $this->structure->setDefaultView(APPDIR); $this->structure->setView(null, $this->orig_structure_view); } public function index() { //die("admin page"); } } Thanks Works fine. Michael and Blesta Addons 2 Quote
Blesta Addons Posted March 25, 2017 Report Posted March 25, 2017 19 hours ago, cyandark said: Thanks Works fine. you are welcome Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.