New Extensions for Reports

twisted1919

Administrator
Staff member
@Mac - You can create your own controller in mailwizz, and simply place your logic there, so you can have a Jasper_reportsController.php file and put your login in it, like:
PHP:
class Jasper_reportsController extends Controller 
{
    public function init()
    {
        parent::init();
        // make sure we load the extension
        Yii::import('ext.YiiJasper.*');
    }
    public function actionIndex()  
    {
         $pages = '1-4';
         $re = new JasperReport('/reports/samples/AllAccounts');
         $re->exec();
          echo $re->toHTML($pages); //Page 1 to 4
    }
}
 

Mac

New Member
Hello Twisted,

Thanks for your reply and codes.

I created a controller file and put it "apps/backend/controllers" folder.

Now my problem is how can i access that file, how can i create a Menu Item to access that controller.

Thanks a lot!!!
 

twisted1919

Administrator
Staff member
@Mac - You should be able to access it at a url like: http://www.domain.com/backend/index.php/jasper_reports
As for putting it in menu, it's simple, inspired from: https://forum.mailwizz.com/threads/customer-area-menu-items.6/, (read that article too)
you can create and use an extension to accomplish this:
PHP:
<?php defined('MW_PATH') || exit('No direct script access allowed');

class CustomMenuItemsExt extends ExtensionInit
{
    // name of the extension as shown in the backend panel
    public $name = 'Custom menu items';
    // description of the extension as shown in backend panel
    public $description = 'Add new links in the menus';
    // current version of this extension
    public $version = '1.0';

    // the author name
    public $author = 'Your name';
    // author website
    public $website = 'http://www.website.com/';
    // contact email address
    public $email = 'your.email@domain.com';
    // in which apps this extension is allowed to run
    public $allowedApps = array('customer', 'backend');

    // can this extension be deleted? this only applies to core extensions.
    protected $_canBeDeleted = true;
    // can this extension be disabled? this only applies to core extensions.
    protected $_canBeDisabled = true;

    // run the extension, this is mandatory
    public function run()
    {
        if ($this->isAppName('backend')) {
            Yii::app()->hooks->addFilter('backend_left_navigation_menu_items', function($items){
                $items['jasper_reports']  = array(
                    'name'   => Yii::t('app', 'Jasper reports'),
                    'icon'   => 'glyphicon-book',
                    'active' => 'jasper_reports',
                    'route'  => array('jasper_reports/index'),
                );
                return $items;
            });
        }
    }
}
 

Mac

New Member
Hello Twisted,

Thanks for the codes, i am able to run the controller, but i have now more issue, the below code
PHP:
public function actionIndex()
    {
         $pages = '1-4';
         $re = new JasperReport('/reports/samples/AllAccounts');
         $re->exec();
          echo $re->toHTML($pages); //Page 1 to 4
        //echo 'hi';
    }
is not running but when i comment this code and just simple echo 'hi' its show 'hi' without layout.

I placed the 'YiiJasper' extension folder in "apps/extensions" and configured it like as per document.

Please check debug mode screenshot in attachment.

Whats wrong there, please guide.

Thanks!
 

Attachments

Last edited:

twisted1919

Administrator
Staff member
@Mac - seems Yii::import('ext.YiiJasper.*'); is not valid. Try Yii::import('root.apps.extensions.YiiJasper.*'); or simply require the JasperReport.php class directly using the absolute path.
 

Mac

New Member
Thanks for your inputs, Yes now its seams to working but its have another issue, please check screen shot.

I think its a "path" problem.

Thanks for all your help, really appreciated.
 

Attachments

twisted1919

Administrator
Staff member
It's a timeout issue, basically the report generating takes too much time.
Just increase your PHP timeout limit to a few minutes, by default it's 30 seconds i believe, then try again.
 
Top