How to Render a QControl in the header.inc.php?

Login or register to post comments
6 replies [Last post]
nleung's picture
Offline
Joined: 04/25/2008

Does anyone know how I would render a QButton or QTextbox in my header.inc.php?

Offline
Joined: 07/07/2008

I have done that one time, but I do not have the code here. I am using a different approach form the standard way that Qcubed works. Usually, in any template,, you include a header and a footer, the QForm is in the middle. Using a front controller, the index.php page can load QPanels and, for instance, a QPanel can be a different page. My index.php is:

<?php
   
// Load the Qcubed Development Framework
   
require_once('includes/prepend.inc.php');
    require_once
__ADMIN_DIR__.'/AdminInfo.php';
   
// load the modules and panels
   
$arrModule = Module::LoadAll();
   
    foreach(
$arrModule as $objModule) {
        require_once(
'modules/'.$objModule->Name.'/'.$objModule->Name.'Module.php');
    }

   
$arrPanel = Panel::GetActivePanels();
   
    foreach(
$arrPanel as $objPanel) {
        require_once(
'panels/'.$objPanel->Path);
    }

   
/**
     * This is the front controller of the CMS
     *
     * @package My Application
     * @subpackage Drafts
     */
   
class Index extends QForm {
       
// Local instance of Index

        // Other ListBoxes (if applicable) via Unique ReverseReferences and ManyToMany References
       
protected $lstDepts;
        protected
$lstFiles;

       
// Other Controls
       
protected $btnSave;
        protected
$btnDelete;
        protected
$btnCancel;
        protected
$pnlQuickPoll;
        protected
$strModule;
        protected
$objCurrentModule;
        protected
$pnlLiveShare;
        protected
$arrActivePanel;
        protected
$arrLeftPanel;
        protected
$arrRightPanel;
        protected
$arrUser1Panel;
        protected
$objModule;
        public
$objAdminInfo;

       
// Create QForm Event Handlers as Needed

//        protected function Form_Exit() {}
//        protected function Form_Load() {}
//        protected function Form_PreRender() {}

       
protected function Form_Run() {
           
// Security check for ALLOW_REMOTE_ADMIN
            // To allow access REGARDLESS of ALLOW_REMOTE_ADMIN, simply remove the line below
           
QApplication::CheckRemoteAdmin();
        }

        protected function
Form_Create() {
            new
Registration;
           
$this->objAdminInfo = new AdminInfo();
           
$this->strModule = QApplication::PathInfo(0);
           
$this->objModule = Module::LoadByName($this->strModule);
            if(!
$this->objModule) {
               
$this->objModule = Module::LoadByName('Index');
            }           
           
$this->arrActivePanel = Panel::GetActivePanels();
           

            for(
$i=0; $i<count($this->arrActivePanel); $i++) {
                if(
$this->arrActivePanel[$i]->IsModuleAsBindAssociated($this->objModule)){
                    if(
$this->arrActivePanel[$i]->Position === 'left') {
                       
$strClass = $this->arrActivePanel[$i]->ClassName;
                       
$strCssClass = $this->arrActivePanel[$i]->CssClass;
                       
$this->arrLeftPanel[$i] = new $strClass($this);
                       
$this->arrLeftPanel[$i]->CssClass = $strCssClass;
                    }
                   
                    if(
$this->arrActivePanel[$i]->Position === 'right') {
                       
$strClass = $this->arrActivePanel[$i]->ClassName;
                       
$strCssClass = $this->arrActivePanel[$i]->CssClass;
                       
$this->arrRightPanel[$i] = new $strClass($this);
                       
$this->arrRightPanel[$i]->CssClass = $strCssClass;
                    }       
   
                    if(
$this->arrActivePanel[$i]->Position === 'user1') {
                       
$strClass = $this->arrActivePanel[$i]->ClassName;
                       
$strCssClass = $this->arrActivePanel[$i]->CssClass;
                       
$this->arrUser1Panel[$i] = new $strClass($this);
                       
$this->arrUser1Panel[$i]->CssClass = $strCssClass;
                    }       
                }       
            }
        }
       
        protected function
ModuleRender() {                       
           
$srtClassName = $this->objModule->Name.'Module';
           
$this->objCurrentModule = new $srtClassName($this);
           
            return
$this->objCurrentModule->Render();
        }
       
        protected function
RenderLeft() {
           
$out = '';
            if(
$this->arrLeftPanel) {
                foreach(
$this->arrLeftPanel as $objPanel) {
                   
$out .= $objPanel->Render();
                }
            }
           
            return
$out;
        }
       
        protected function
RenderRight() {
           
$out = '';
            if(
$this->arrRightPanel) {
                foreach(
$this->arrRightPanel as $objPanel) {
                   
$out .= $objPanel->Render();
                }
            }
           
            return
$out;           
        }
       
        protected function
RenderUser1() {
           
$out = '';
            if(
count($this->arrUser1Panel) > 0) {
                foreach(
$this->arrUser1Panel as $objPanel) {
                   
$out .= $objPanel->Render();
                }
            }
           
            return
$out;           
        }       
       
        protected function
RenderHeader() {
           
        }
       
        protected function
Renderfooter() {
           
        }   
    }

   
// Load the template. If the module cannot be found, load the standard template.
   
$objModule = Module::LoadByName(QApplication::PathInfo(0));
    if(
$objModule) {
       
$intTemplateId = $objModule->TemplateId;
    }
    else {
       
$intTemplateId = 1;
    }
   
Index::Run('Index', 'templates/'.Template::Load($intTemplateId)->Path);
?>

I include the QPanel by loading them from the module table, than I create them in the From_Create. The template is loaded from a template system, so to each QPanel you can bind a specific template. In few word this is a CMS. The template is:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Wolseley UK Intranet</title>
<script type="text/javascript" src="/assets/js/standard.js"></script>
<script type="text/javascript" src="/assets/js/rounded.js"></script>
<script type="text/javascript" src="/assets/js/jaketest.js"></script>
<link rel="stylesheet" type="text/css" href="<?php _p(__TEMPLATES__) ?>/standard/css/styles.css" media="screen" />
<link rel="stylesheet" type="text/css" href="<?php _p(__TEMPLATES__) ?>/standard/css/main.css" media="screen" />
<style type="text/css" media="screen">
@import "<?php _p(__TEMPLATES__) ?>/standard/css/Menu.css";
</style>
<!--[if IE 7]>
<style type="text/css" media="screen">
  @import "<?php _p(__TEMPLATES__) ?>/standard/css/ieSeven.css";
</style>
<![endif]-->
<!--[if lt IE 7]>
<style type="text/css" media="screen">
@import "<?php _p(__TEMPLATES__) ?>/standard/css/iefixer.css";
@import "<?php _p(__TEMPLATES__) ?>/standard/css/Menu4IE.css";
</style>
<script language="javascript" src="/assets/js/ADxMenu.js" type="text/javascript"></script>
<script language="javascript" type="text/javascript">
try
{
  document.execCommand("BackgroundImageCache", false, true);
}
catch(err)
{}
</script>
<![endif]-->
<!--[if lt IE 6]>
<style type="text/css" media="screen">
  @import "<?php _p(__TEMPLATES__) ?>/standard/css/ie55.css";
</style>
<![endif]-->

</head>
<body>
<? $this->RenderBegin(); ?>
<div id="header">
<div class="container">
<div id="mainSearch_ctl">
<div id="mainSearch" >
<?php $this->RenderUser1() ?>
</div><!-- end mainSearch -->
</div><!-- mainSearch_ctl -->

<div id="peopleHeader"></div>
<img src="<?php _p(__TEMPLATES__) ?>/standard/images/header_logo.gif" alt="Wolseley UK" id="logo" />
<img src="<?php _p(__TEMPLATES__) ?>/standard/images/header_text.gif" alt="The intranet for Wolseley UK people" id="strapline" />
<div id="mainNav_ctl">
<ul id="mainNav" >
<li id="navHome_ctl" ><div id="navHome" class="rounded" ><a href="/">Home</a></div></li>
<li id="navSupplyChain_ctl" ><div id="navSupplyChain" class="rounded" ><a href="/index.php/Department/2">Supply Chain</a></div></li>
<li id="navCentServ_ctl" ><div id="navCentServ" class="rounded" ><a href="/index.php/CentralServices">Central Services</a></div></li>
<li id="navBrands_ctl" ><div id="navBrands" class="rounded" ><a href="/index.php/Businesses">Businesses</a></div></li>
<li id="navInfo_ctl" ><div id="navInfo" class="rounded" ><a href="/index.php/InfoCenter">Info Center</a></div></li>
<li id="navNews_ctl" ><div id="navNews" class="rounded" ><a href="/index.php/News">News</a></div></li>
<li id="navHelp_ctl" ><div id="navHelp" class="rounded" ><a href="/index.php/Help">Help</a></div></li>
</ul>
</div>
</div><!-- #header .container END -->

<div id="subnav_ctl"><div id="subnav" >
<div class="container">
<ul class="adxm menu">
<li id="myIntranet"><a href="/index.php/Profile">Profile</a></li>
<li id="admin"><a href="/admin/index.php">Admin</a></li>
</ul>
</div><!-- #submenu .container END -->

<div id="FavouriteDialog_ctl" style="position:absolute;display:none;"></div></div></div>
</div><!-- #header END -->

<div id="content">
<div class="container">

<div id="leftCol">
<?php $this->RenderLeft() ?>
</div><!-- #leftCol END -->

<div id="mainCol"><!-- #mainCol -->
<?php $this->ModuleRender(); ?>
</div><!-- #mainCol END -->

<div id="rightCol">
<?php $this->RenderRight() ?>
</div><!-- #rightCol END -->

</div><!-- .container END -->
<p class="clear">&nbsp;</p>
</div><!-- #content END -->

<?php $this->RenderEnd(); ?>
<div id="footer">
<div class="container">
<p><a href="mailto:intranet@wolseley.co.uk">Report a problem</a></p>
</div>
</div>
</body>
</html>

If you look at

<?php
$this
->RenderUser1()
?>
in the template, it renders a search box in the header, but header, body and footer are all together in a single template.

Offline
Joined: 03/31/2008

Your easiest bet may be to extend QForm with a class that creates the QControl in the Form_Create function, then have any pages using that header.inc.php inherit from that extended QForm.

nleung's picture
Offline
Joined: 04/25/2008

For example,
If have pages
Index.php
ListResults.php
ViewResult.php
which all already extend from a class like BusinessFormBase.php
I would have to create that QControl for each page if I wanted a textbox control in my header.

Isn't there an easier way to create one global control?

OOPMan's picture
Offline
Joined: 11/07/2008

Yes. Creation of global controls is actually quite easy. In order to do so, make the following changes in QFormBase:

Line 8: protected $objControlArray; becomes protected $objControlArray = array();
Line 10: protected $objGroupingArray; becomes protected $objGroupingArray = array();

Now, in your own QForms you can override the __construct() method and create controls during QForm instantiation.

If you want global controls then simply add a constructor for QForm which creates the required controls.

profnotime's picture
Offline
Joined: 01/13/2009

Y do we always have to edit QCubed core files to achieve functionalities? This does not happen in CakePHP. How easy will it be to later upgrade after all this editing here and there?

Offline
Joined: 04/24/2008

Sorry, but they are two possible ways suggested here. One Quick & Dirty Core-hack, that will most probably work and will 100% break update compatibility and there possibility to achieve the same with derivation of the QForm and some custom code, which will most probably work (i did not test one way or the other) and break absolutely nothing. Choose whatever you want!

But I'm perfect sure, these kind of things are not different for whatever framework you use. If you decide to hack the framework, you are able too. If you do not, you will most probably find a way without.
Me for myself has never done any patches to the QForm-core classes. It's not neccassary as for the most common ones there are overridable classes in "includes/qcubed/classes". And if that's not enough you simple can create your own controls.