Standard QPanels on every page

Login or register to post comments
8 replies [Last post]
mrherb's picture
Offline
Joined: 04/12/2009

Hi there,

I have a working login page for my app but I'm trying to figure out how to set-up my application so that I have standard login dialogue boxes in every page header (which will then become a qpanel of user's name etc. when logged in). What is the best way to do this so I can easily include that standard functionality on every new qcodo class/page + template I create for the rest of my site with minimal repetition of code in every new class/ page?

If you can clearly outline which bits of code to place in which files, as I am often really dumb ;o)
e.g.
header.inc.php
test_page.php
test_page.tpl.php
footer.inc.php
etc.
...I'd be very grateful!

Ben

mrherb's picture
Offline
Joined: 04/12/2009

Hey guys - is this a tricky one or am I just being daft? It's exactly the same system as this site uses - so I know it's possible!
Thanks
Ben

Offline
Joined: 03/31/2008

I think this is essentially the same question we address at http://qcu.be/content/extend-qform-create-master-page
Let me know if that helps. :)

MikeHostetler's picture
Offline
Joined: 01/09/2008

Ben-

This site uses Drupal, not QCubed, so we're taking a bit of a shortcut there.

To answer your question though, I typically will subclass the QForm class and build up controls I need on every page in that sub-class. Then, for each of my individual QForms, I'll just make a call to my parent::Form_Start() method, which instantiates my global controls.

Does that help?

mrherb's picture
Offline
Joined: 04/12/2009

Phew! I was really flailing there for a minute! Inheritance of course!

@Vexed - yep that did it, took me a few minutes but as always with Qcodo the penny dropped and it was really simple!

@Mike - Thanks - Drupal... yes now I recall someone saying something about not eating ones own dog food ;o) Tastes fine to me! Thanks for the tip - much the same (I think) but just using a different method name (Form_Start rather than Form_Create) in the parent class - makes sense.

I'm not the first to say this but Qcodo really rocks!

mrherb's picture
Offline
Joined: 04/12/2009

Darn! Spoke to soon - as usual! (still think Qcodo rocks of course ;o)

I got a Qpanel to call the render method on my test QLabel from inside my header.inc.php by extending a BasePage class like this:

BasePage.class.php

class BasePage extends QForm {
   
    protected $lblHeader;

    protected function Form_Start() {
        $this->lblHeader = new QLabel($this);
        $this->lblHeader->Text = "BADA-BING!";
    }
}

But when I include controls in my main page, index.php, like this

require('includes/prepend.inc.php');

class Index extends BasePage {
    protected $lblMessage;
    protected $btnButton;

    protected function Form_Create() {     
         parent::Form_Start();

        $this->lblMessage = new QLabel($this);
        $this->lblMessage->Text = 'Click the button to change my message.';

        $this->btnButton = new QButton($this);
        $this->btnButton->Text = 'Click Me';
        $this->btnButton->AddAction(new QClickEvent(), new QAjaxAction('btnButton_Click'));
    }

    protected function btnButton_Click($strFormId, $strControlId, $strParameter) {
        $this->lblMessage->Text = 'That tickles!';
    }
}

Index::Run('Index');

and click on btnButton, I get an exception from index.php: "Control passed by Qform__FormControl does not exist: c3"

My index.tpl.php looks like this:

<?php
    $this
->RenderBegin();
    require(
__INCLUDES__ . '/header.inc.php');
    <
p><?php $this->lblMessage->Render(); ?>
</p>
    <p><?php $this->btnButton->Render(); ?></p>

<?php
   
require(__INCLUDES__ .'/ooter.inc.php');
   
$this->RenderEnd(); ?>

and, for completeness, my header.tpl.php just contains my page header plus the render call

<?php $this->lblHeader->Render();?>

What gives guys? I though I had it there!

Offline
Joined: 03/31/2008

That sounds odd. Mind posting the raw HTML the browser receives? I'm wondering why you'd be getting an error about c3 (presumably c3 being either btnButton or lblMessage).

mrherb's picture
Offline
Joined: 04/12/2009

Wierd! I've restarted this evening and the error has gone!! All works fine ;O)
I have seen some odd caching of files & session data from Firefox lately - since I asked it to remember my tabs in fact, so maybe that had someting to do with it...
Anyway I'll report back if it recurs... many thanks to you both
Ben

MikeHostetler's picture
Offline
Joined: 01/09/2008

Great! Likely was a caching issue.