0

入力ボックスが1つあるフォームがあります。フォームを送信すると、次のエラーが発生します。

キャッチ可能な致命的なエラー:クラスApplication_Model_DbTable_Commentsのオブジェクトを228行目の/Users/Ric/Sites/MN/library/Zend/Db/Statement/Pdo.phpの文字列に変換できませんでした:0.0002 657600 1. {main}() /Users/Ric/Sites/MN/public/index.php:0 0.0323 6224344 2. Zend_Application-> run()/Users/Ric/Sites/MN/public/index.php:28 0.0323 6224344 3. Zend_Application_Bootstrap_Bootstrap-> run ()/Users/Ric/Sites/MN/library/Zend/Application.php:366 0.0324 6224480 4. Zend_Controller_Front-> dispatch()/Users/Ric/Sites/MN/library/Zend/Application/Bootstrap/Bootstrap.php :97 0.0420 7942648 5. Zend_Controller_Dispatcher_Standard-> dispatch()/Users/Ric/Sites/MN/library/Zend/Controller/Front.php:954 0.0474 8519528 6. Zend_Controller_Action-> dispatch()/ Users / Ric / Sites / MN /library/Zend/Controller/Dispatcher/Standard.php:295 0.047585282007。ClubDescriptionController-> indexAction()/Users/Ric/Sites/MN/library/Zend/Controller/Action.php:516 0.0760 12357968 8. Application_Model_DbTable_Comments-> addComment()/ Users / Ric / Sites / MN / application / controllers / ClubDescriptionController .php:33 0.0760 12358408 9. Zend_Db_Table_Abstract-> insert()/Users/Ric/Sites/MN/application/models/DbTable/Comments.php:25 0.0790 12371776 10. Zend_Db_Adapter_Abstract-> insert()/ Users / Ric / Sites /MN/library/Zend/Db/Table/Abstract.php:1075 0.0791 12373808 11. Zend_Db_Adapter_Pdo_Abstract-> query()/Users/Ric/Sites/MN/library/Zend/Db/Adapter/Abstract.php:575 0.0791 12373888 12. Zend_Db_Adapter_Abstract-> query()/Users/Ric/Sites/MN/library/Zend/Db/Adapter/Pdo/Abstract.php:238 0.0793 12379024 13. Zend_Db_Statement-> execute()/ Users / Ric / Sites / MN /library/Zend/Db/Adapter/Abstract.php:4790。0793 12379024 14. Zend_Db_Statement_Pdo-> _ execute()/Users/Ric/Sites/MN/library/Zend/Db/Statement.php:300 0.0793 12379104 15. PDOStatement-> execute()/ Users / Ric / Sites / MN / library /Zend/Db/Statement/Pdo.php:228

フォームは次のとおりです。

<?php

class Application_Form_Comment extends Zend_Form
{

public function init()
{
    $this->setName('comment');
    $id = new Zend_Form_Element_Hidden('id');
  $id->addFilter('Int');
        $comment = new Zend_Form_Element_Text('comment');
        $comment->setLabel('Comment:')
            ->setRequired(true)
            ->addFilter('StripTags')
            ->addFilter('StringTrim')
            ->addValidator('NotEmpty');
    $submit = new Zend_Form_Element_Submit('submit');
    $submit->setAttrib('id', 'submitbutton');
    $this->addElements(array($id, $comment, $submit));
        }
    }

コントローラは次のとおりです。

public function indexAction()
    {
       //action for the comments submission
       $form = new Application_Form_Comment();
       $form->submit->setLabel('Comment');
       $this->view->form = $form;
       if ($this->getRequest()->isPost()) {
        $formData = $this->getRequest()->getPost();
        if ($form->isValid($formData)) {
            $comment = $form->getValue('comment');
            $comment = new Application_Model_DbTable_Comments();
            $comment->addComment($comment);
            $this->_helper->redirector('index');
        } else {
            $form->populate($formData);
        }
    }
}

モデル:

class Application_Model_DbTable_Comments extends Zend_Db_Table_Abstract {

protected $_name = 'comments';

public function addComment($comment) {
    $data = array(
        'comment' => $comment,
        );
    $this->insert($data);
}   

}

景色:

<div id="comments">
    <?php echo $this->form; ?>
</div>

ありがとう

リック

4

1 に答える 1

2

あなたの問題はここにあります

$comment = $form->getValue('comment');
$comment = new Application_Model_DbTable_Comments();
$comment->addComment($comment);

に変更します

$comment = new Application_Model_DbTable_Comments();
$comment->addComment($form->getValue('comment'));
于 2012-04-17T22:56:15.580 に答える