Re: MVCnPHP
| From: | Tony Bibbs | Date: | Tue, 08 Apr 2003 16:29:25 +0000 |
| Subject: | Re: MVCnPHP | ||
| References: | 1 | Groups: | php.pear.dev |
| Request: | Send a blank email to pear-dev+get-15044@lists.php.net to get a copy of this message | ||
On Tue, 8 Apr 2003, Jeroen Houben wrote:
>
> Second question is: how would I make good use of QuickForm in this
> example? Quickform deals with display (View), but also with validation
> (Model, right?), which is a seperate class in your example. I'm not too
> sure where an instance of Quickform would fit as it serves both
> displaying purposes and validation purposes. Would it make sense to have
> some sort of Contact base class, which has an instance of QuickForm as a
> property and then have a Contact_Validate and a Contact_view class that
> both extend the Contact base class? Simplified it would look a little
> like this:
>
> Class Contact {
> var $_form;
> }
>
> Class Contact_Validate extends Contact {
> function validate() {
> return $this->_form->validate();
> }
> }
>
> Class Contact_View {
> function getView() {
> return $this->_form->toHtml(); // or $this->_form->display();
> }
> }
>
Ok, keep in mind that the fundamental difference (which you've noticed) is
that this MVC separates the View (e.g. HTML forms) from the actual
validation. What you really need is a way to do multiple inheritance
effectively creating a new object extending both BaseView and Validator.
To get around that, you would simply need to create a new abstract class
using QuickForm as follows:
class QF_View extends BaseView {
$var _QForm;
function QF_View()
{
$this->_QForm = new HTML_QuickForm();
}
function getView()
{
// This is where you would output the form
}
function execute()
{
// This is where calls to Quick FOrm validation would go.
}
}
With this as your abstract class you can modify your XML config file as
follows:
<VIEW ID="editContact" NAME="ContactForm"></VIEW>
<MODEL ID="validate" NAME="ContactForm">
<FORWARD ID="showAgain" TYPE="view">editContact</FORWARD>
<FORWARD ID="saveIt" TYPE="model">saveContact</FORWARD>
</MODEL>
Note that both the view and the model reference ContactForm which is a
object extending QF_View as needed. To me that is a fairly clean way to
integrate QuickForm.
Does that make sense? I may create a new example highlighting this.
--Tony