We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 36885
    • 15 Posts
    Hi

    I have a slightly advanced way of working with CMP to load different panels depending on need, and passing information to panels.

    After doing a test upgrade from 2.1 to 2.2, I am looking at the new way that CMP uses controller-classes and I have figured our the core, but I am wondering how to turn my old 'mgr/index.php' (somewhat shortened):
    <?php
    	// Only show information according permissions
    	$userId = $modx->user->get('id');
    	$adminGroup = $liteauction->getCoreParam('security_administrators');
    	$seeAdminInfo = false;
    	
    	// Get variables to set correct active tab
    	$referrer = $_SERVER['HTTP_REFERER'];
    	$activeTab = 0;
    	if (preg_match("/type=auction&/i", $referrer)) $activeTab = 5; // Coming from auction page
    	if (preg_match("/type=object2&/i", $referrer)) $activeTab = 6; // Coming from object2 page
    
    	if ($userId == 1) $seeAdminInfo = true;	// Admin is always allowed to see everything
    	if ($modx->user->isMember($adminGroup)) $seeAdminInfo = true; // User must be in admin-group to see admin specific information
    	
    	// Get default information
    	$defaultFontInEditor = $liteauction->getCoreParam('font_in_editor');
    	$defaultCountryId = $liteauction->getCoreParam('country_id');
    	$defaultCurrencyId = $liteauction->getCoreParam('money_currency_id');
    	$currencyItem = $modx->getObject('laCurrency', $defaultCurrencyId);
    	$defaultCurrencyName = $currencyItem->get('name');
    	
    	// Register all JS files
    	$modx->regClientStartupScript($liteauction->config['jsUrl'].'mgr/widgets/stores.js');
    	$modx->regClientStartupScript($liteauction->config['jsUrl'].'mgr/widgets/object.js');
    	if ($seeAdminInfo) {
    		$modx->regClientStartupScript($liteauction->config['jsUrl'].'mgr/widgets/commission_user.js');
    	}
    	$modx->regClientStartupScript($liteauction->config['jsUrl'].'mgr/sections/index.js');
    
    	$modx->regClientStartupHTMLBlock('
    <script type="text/javascript">
    // <![CDATA[
    Ext.onReady(function() {
        MODx.load({
            xtype: "liteauction-page-home"
            ,activetab: "'.$activeTab.'"
            ,defaultcurrencyid: "'.$defaultCurrencyId.'"
            ,defaultcurrencyname: "'.$defaultCurrencyName.'"
            ,defaultfontineditor: "'.$defaultFontInEditor.'"
            ,defaultcountryid: "'.$defaultCountryId.'"
        });
    });
    // ]]>
    </script>');
    	return '<div id="liteauction-panel-home-div"></div>';


    To the new style 'index.class.php':
    <?php
    	class LiteAuctionIndexManagerController extends LiteAuctionManagerController {
    		public function process(array $scriptProperties = array()) {
    		}
    
    		public function getPageTitle() {
    			return $this->modx->lexicon('liteauction');
    		}
    
    		public function loadCustomCssJs() {
    			//$this->addJavascript($this->liteauction->config['jsUrl'].'mgr/widgets/liteauction.grid.js');
    			$this->addJavascript($this->liteauction->config['jsUrl'].'mgr/widgets/home.panel.js');
    			$this->addLastJavascript($this->liteauction->config['jsUrl'].'mgr/sections/index.js');
    		}
    
    		public function getTemplateFile() {
    			return $this->liteauction->config['templatesPath'].'home.tpl';
    		}
    	}
    


    Thus, how do I pass the values in 2.2-way that I previously did with 'regClientStartupHTMLBlock'.

    Also, since the old code is working in 2.2, how do the 2.2 core sense to use the new controller-class and new way of working? (thus, what to remove in the old code).

    Thanks in advance! smiley
      • 28215
      • 4,149 Posts
      1. Use $this->addHtml($html);
      2. It looks for a .class.php file rather than just a .php file; also it looks to see if the returned name in your .class.php file is an existing class; if not, it assumes it's old style.
        shaun mccormick | bigcommerce mgr of software engineering, former modx co-architect | github | splittingred.com
        • 36885
        • 15 Posts
        Thanks. Much appriciated. Will try during this weekend