Extend QForm to Create a Master Page
I have a web application that contains the same QPanels on every page. For instance, on every web page, there is a header QPanel with some navigation buttons. There is also a footer QPanel with some more buttons. The only content that changes between pages is between the header and footer. Is there a way I can create a simple form that already contains these header and footer panels without having to call QPanel->Render() on every page? I was thinking I could create a custom Form that extended QForm, but I'm not sure how to start. Does anyone have any suggestions? Thanks in advance!

You can easily create a class that extends a QForm.
class MyBaseForm extends QForm {
public $lblHeader;
public $lblFooter;
public function Form_Create() {
$this->lblHeader = ...
}
}
You need to then hook up this class for auto-loading. Then, each of your regular pages would be
class PageA extends MyBaseForm {public function Form_Create() {
parent::Form_Create();
....
}
}
I must be doing something wrong. I extended a class from QForm.
class JForm extends QForm {
//Form Panels
protected $pnlHeader;
//Data Members
protected $objUser;
protected $objAccount;
protected function Form_Create() {
$this->pnlHeader = new HeaderPanel($this);
}
}
I have a regular page like this:
class LoginForm extends JForm {
protected function Form_Create() {
parent::Form_Create();
}
}
LoginForm::Run('LoginForm');
My Header Panel has the AutoRenderChildren set to true. Now, if I don't include pnlHeader->Render() in my HTML file, the header panel doesn't get rendered. Also, do I call RenderBegin from my JForm? And can I include a file like shown below inside of my JForm so I don't have to do this on every regular page?
<?phprequire_once(__INCLUDES__ . '/header.inc.php');
?>
Yes, that's exactly how the form drafts are set up. Having a render call within header.inc.php should not be an issue.
I originally was developing with Microsoft technologies under ASP.NET 3.0. I have been using QCodo/QCubed since last October. With Microsoft, I used to bulid a MasterPage that all of my web pages included. My MasterPage would contain some basic headers and footers that would be included on all of my web pages that used the MasterPage. I still have not had any luck trying to reproduce this same architecture with QCubed. I have a JForm that extends QForm as previously shown. I also have a Header QPanel on my JForm. The Header QPanel has AutoRenderChildren set to TRUE. All of my web pages extend from JForm so that the Header panel is already included on the Form. The only way I can get the Header panel to render is if I call HeaderPanel->Render() on every web page that uses JForm. I would prefer not to have to call HeaderPanel->Render() on every web page. I was hoping I could have the JForm handle the Rendering of the Header QPanel and the individual web pages wouldn't have to worry about it. Does anyone have any sample of what I am trying to accomplish here with the HTML files included so I can see what I'm doing wrong?
It's exactly what you said in your last post.
page1.tpl.php:
<?php$this->RederBegin();
require_once(__INCLUDES__ . '/header.inc.php');
$contentStuff->Render();
require_once(__INCLUDES__ . '/footer.inc.php');
$this->RederEnd();
?>
page1.php:
<?php
require('prepend.inc.php');
class SomeForm extends JForm {
protected $contentStuff;
protected function Form_Create() {
parent::Form_Create();
$this->contentStuff = new QLabel($this);
$this->contentStuff->Text = 'YAY';
}
}
?>
header.inc.php:
<?php$this->HeaderPanel->Render();
?>
Lunbox,
You could also try an MVC approach and have your front controller handle the static panels for you. Here is a link to the old Qcodo site that explains one way of doing so. I have succesfully used it in several sites. http://www.qcodo.com/downloads/item.php/230.
Vexed, I usually set up my pages a little differently. In may case, header.inc.php contains at the HTML header stuff, while footer contains site-wide JS. This, in my case, the format is...
page1.tpl.php:
<?php require_once(__INCLUDES__ . '/header.inc,php'); ?><!-- Page Content Here -->
<?php require_once(__INCLUDES__ . '/footer.inc,php'); ?>
header.inc.php:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en>
<head>
<!-- CSS Includes -->
</head>
<body>
<?php $this->RenderBegin(); ?>
<!-- Common Controls -->
<?php $this->HeaderPanel->Render(); ?>
footer.inc.php:
<?php $this->FooterPanel->Render(); ?><!-- JavaScript Includes -->
<?php $this->RenderEnd(); ?>
</body>
</html>
I totally got it now. Thank you so much everyone for your help!
LOL, well if you want to get fancy, this is what I use, derived from http://qcodo.com/forums/topic.php/1612/1/ (QHistoryNavigator is a breadcrumb type control, showing how to accomplish the original request):
layout.tpl.php:
<?php require(__INCLUDES__ . '/header.inc.php'); ?><?php $this->RenderBegin() ?>
<?php require(__INCLUDES__ . '/menu.inc.php');?>
<?php $this->historyNav->Render(); ?>
<?php require($this->ContentTemplate);?>
<?php require(__INCLUDES__ . '/footMenu.inc.php');?>
<?php $this->RenderEnd() ?>
<?php require(__INCLUDES__ . '/footer.inc.php'); ?>
page1.tpl.php
<p>Here's the page content</p>page1.php
<?php
class Page1 extends QHistoryForm {
protected function Form_Create() {
$this->ContentTemplate = __DRAFTS__.'/page1.tpl.php';
parent::Form_Create();
}
}
Page1::Run('Page1', __TEMPLATES__.'/layout.tpl.php');
?>
QHistoryForm.class.php
<?phpclass QHistoryForm extends QForm {
protected $historyNav;
protected function Form_Create() {
$this->historyNav = new QHistoryNavigator($this);
}
}
?>
I'm sure I don't have to show header, menu, footMenu or footer files, since those should be obvious, and/or app specific.
I just posted a topic that is very similar to this.
http://qcu.be/content/qpage-class
Hello VexedPanda,
I'm interested in your QHistoryNavigator class for implement my breadcrumbs.
Can you give my example and/or description of class QHistoryNavigator if possible.
Thanks a lot.