TAGS :Viewed: 10 - Published at: a few seconds ago

[ Zend Framework Insert Into ]

I've supposed to use the element to submit the contents of the input's within the form . I need to have insert into in Zend Frameork. I've tried this but it's not working.

Controller:

   $uri = Zend_Controller_Front::getInstance()->getRequest()->getRequestUri();
    $part = basename($uri);
    $this->view->form_insert = $form_insert;
    if ($request->isPost())
    {

        if ($form_insert->isValid($this->_request->getPost()))
        {
            $insert=$form_insert->getValue('message');;
            $messageModel = new Model_NewMsg();
            $select_msg = $messageModel->insert(
                    array('insert_date' => 'NOW()',

                    'from_user' => 'SUPPORT',

                    'message' => '$insert',

                    'send_date' => '0000-00-00 00:00:00',

                    'to_user' => '$part'

            ));
       }
    }

Model:

<?php
class Model_NewMsg extends Zend_Db_Table_Abstract
{
    protected $_name = 'name_of_table';
    protected $_schema = 'name_of_database';
}

Answer 1


It seems that there is some problem with your array.

Try to use it in this way:

$messageModel = new Model_NewMsg();
$data = array(
            'insert_date'   => date('Y-m-d H:i:s'),
            'from_user'     => 'SUPPORT',
            'message'       => $insert,
            'send_date'     => '0000-00-00 00:00:00',
            'to_user'       => $part
        );
$select_msg = $messageModel->insert($data);

Answer 2


Use this:

                $select_msg = $messageModel->insert(
                        array('insert_date' => new Zend_Db_Expr('NOW()'),

                        'from_user' => 'support',

                        'message' => $insert,

                        'send_date' => '0000-00-00 00:00:00',

                        'to_user' =>    $part               
                ));