Zend Form 实例化在白屏死机中默默失败

发布于 2024-10-06 06:07:11 字数 2762 浏览 0 评论 0原文

Zend 新手尝试配置和使用 Zend_Form。

仅供记录,我使用的是 Zend Framework 版本:1.11.1,在 Win XP 上运行 Apache 2.something。我正在开发一个网站,该网站大部分工作都很好。 (其他人开始了它。我必须扩展它)。

我在表单领域遇到了麻烦,正在尝试引入 Zend_Form,希望这能以某种方式简化问题。但尝试使用 Zend_Form 会带来它自己的问题。

当我尝试实例化第一个测试表单时,我遇到了死机白屏——甚至没有错误消息。

数据如下:

Dir Structure:  
MYAPPNAME  
....controllers  
....forms  
....models  
....services  
....views  

Bootstrap.php 包含:

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')));
}

这对于名称如下的模型来说效果很好:

class MYAPPNAME_Model_DataRecordName extends Doctrine_Record
{
 etc...

但对于表单来说,它似乎严重失败......尽管请注意,这是我第一次使用 Zend_Form。

我的表单在文件 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

该表单显示在定义为的视图中:

<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>

该视图工作正常。

它由一个操作(在工作控制器中)管理,定义为:

 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";
 }

如果我注释掉表单实例化和垃圾数据行,我会在视图中获得有效的输出。如果我将 $form 设置为“垃圾数据”,我也会得到有效的可预测输出。

然而,当我尝试实例化表单对象时,我得到了仅包含“formtestAction:ENTERED”(来自顶部的 echo 语句)的死亡白屏。

我慢慢地发疯了。

我无法弄清楚这是一个自动加载器问题、一个路由问题、一个对象实例化问题还是什么。

我非常感谢任何建议。

感谢您的阅读。

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).

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

南冥有猫 2024-10-13 06:07:11

在使用 Zends 时,我已经多次遇到过这种情况,而且通常是多余的逗号,这很烦人。在

... 'basePath' =>应用程序路径。 '/modules/MYAPPNAME',));

它看起来就像其中一个。只是快速浏览一下,但无论如何您都可以检查一下。

哈特哈,
马库斯

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

少钕鈤記 2024-10-13 06:07:11

mtoepper:非常接近。好捕获!

这确实是一个额外的逗号,只是它出现在 Form 类定义中——阻止了成功的对象实例化。

这些无声的失败非常烦人。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文