Jump to content

Blank Page in Plugin Admin Controller


Abdy

Recommended Posts

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. :(

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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. 

8837f024968a4800f6f7ad5c527c1420o.png

 

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 :(

Link to comment
Share on other sites

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");
    }
}

 

Link to comment
Share on other sites

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 :D Works fine.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...