Zend Form instantiation failing silently in white screen of death
Zend newbie trying to configure and use Zend_Form.
Just for the record I'm on Zend Framework Version: 1.11.1 on Win XP running Apache 2.something. I'm working on a site which for the most part works just fine. (Somebody else started it. I have to extend it).
开发者_JS百科I am having trouble in the area of forms and am trying to introduce Zend_Form in the hope that this will somehow simplify matters. But trying to use Zend_Form is presenting problems of it's own.
When I try to instantiate the first test form, I'm getting the white screen of death -- without even an error message.
Data as follows:
Dir Structure:
MYAPPNAME
....controllers
....forms
....models
....services
....views
Bootstrap.php contains:
protected function _initAutoLoading()
{
$loader = new Zend_Loader_Autoloader_Resource(array(
'namespace' => 'MYAPPNAME',
'basePath' => APPLICATION_PATH . '/modules/MYAPPNAME',
));
$loader->addResourceTypes(array(
'model' => array(
'path' => 'models',
'namespace' => 'Model'),
'form' => array(
'path' => 'forms',
'namespace' => 'Form'),
'service' => array(
'path' => 'services',
'namespace' => 'Service')));
}
This works fine for models with names like:
class MYAPPNAME_Model_DataRecordName extends Doctrine_Record
{
etc...
But it seems to be failing miserably for forms ... although mind you, this is my first pass at using Zend_Form.
My form is defined in file MYAPPNAME/forms/Formtest.php:
<?php
class MYAPPNAME_Form_Formtest extends Zend_Form
{
public function init($action){
$this->setAction($action)
->setMethod('post')
->setAttrib('id', 'formtestForm');
$email = $this->addElement( 'text', 'email',
array('label', => 'EMail'));
)
$submit = $this->addElement('submit', 'Submit and Be Free!');
}// End init
} // End class def
The form is being displayed in a view defined as:
<div class=""testForm">
<p style="margin-top:20px; margin-bottom:10px"">Explanatory Text</p>
<h2>This is a Form Test</h2>
<?php echo $this->formResponse; ?>
<?php echo $this->form; ?>
<hr>
<p>FORM ABOVE THIS BAR</p>
</div>
The view works just fine.
It is being managed by an action (in a working controller) defined as:
public function formtestAction(){
echo "formtestAction: ENTERED";
$form = new MYAPPNAME_Form_Formtest('ThisController/formtest2');
//$form = "<p>GARBAGE DATA</p>";
if(!empty($form)){$this->view->form = $form;}
else{
$form = "<p>THE FORM VAR IS EMPTY</p>";
$this->view->form = $form;
$formResponse = "<p>INSTANTIATION FAILED</p>";
$this->view->formResponse = $formResponse;
}
}
public function formtest2Action(){
echo "formtest2Action: ENTERED";
}
If I comment out both the form instantiation and the garbage data lines, I get valid output in the view. If I set $form to "GARBAGE DATA" I also get valid predictable output.
However when I try to instantiate the form object I get the white screen of death containing only "formtestAction: ENTERED" (from the echo statement at the top.)
I am going slowly mad.
I can't figure out if this is an autoloader problem, a routing problem, an object instantiation problem, or what.
I'd be very much obliged for any advice.
Thanks for reading.
With Zends, I've run into that several times, and it usually is something annoying as a superflous comma. In
... 'basePath' => APPLICATION_PATH . '/modules/MYAPPNAME',));
it looks just like on of those. Only a quick look, but you might check it anyway.
HTH, Marcus
mtoepper: Very close. Good catch!
It was indeed an extra comma, only it was in the Form class definition -- preventing successful object instantiation.
These silent failures are VERY annoying.
精彩评论