-- Mark Steudel <[EMAIL PROTECTED]> wrote
(on Tuesday, 08 April 2008, 12:17 PM -0700):
> I’m just using components of the Zend Framework in my application, and one of
> those is Zend_Form which in my header file I’m loading like:
>
> Zend_Loader::loadClass('Zend_Form');
>
> But when I go to instantiate a text element like:
>
> $usrename = new Zend_Form_Element_Text( ‘username’);
>
> I got the Class 'Zend_Form_Element_Text' not found error. So I tried loading
> the Zend_Form_Element_Text class like so:
>
> Zend_Loader::loadClass('Zend_Form_Element_Text');
>
> My question is do I really need to load each element, I’m figuring there must
> be a cleaner way to do load each form element class.
Use Zend_Form as a factory for creating elements:
$username = $form->createElement('text', 'username');
// or, if you want it attached to the form immediately:
$form->addElement('text', 'username');
$username = $form->username;
This is actually the preferred way to create elements, as it allows you
to set plugin paths for your elements in your form object *once*, and
those will then be used for all elements created via your form object.
Finally, you might want to use autoloading if you don't want to use
Zend_Loader::loadClass() or require_once throughout your code. Add this
to the top of your bootstrap or script:
require_once 'Zend/Loader.php';
Zend_Loader::registerAutoload();
--
Matthew Weier O'Phinney
Software Architect | [EMAIL PROTECTED]
Zend - The PHP Company | http://www.zend.com/