数据不是从数据库中形成的

时间:2013-12-20 11:09:02

标签: php zend-framework

我正在尝试进行插入更新删除网格但是当我点击更新链接数据时没有形成。这是我的代码。

<?php
public function editAction() {

    $form = new Application_Form_user();
    $this->view->form = $form;

    if ($this->getRequest()->isPost()) {

        $formData = $this->getRequest()->getPost();
        if ($form->isvalid($formData)) {
            $client = new Application_Model_DbTable_Client();
            $firstname = $form->getvalue('firstname');
            $lastname = $form->getvalue('lastname');
            $email = $form->getvalue('email');
            $client->updateclient($id, $firstname, $lastname, $email);
            $this->_helper->redirector('index');
        } else {
            $this->populate($formData);
        }
    } else {

        $id = $this->getRequest()->getparam('id');
        if ($id > 0) {

            $client = new Application_Model_DbTable_Client();
            $clients = $client->getClient($id);

            $this->populate($clients);
        }
    }
}

我的型号代码: -

<?php

class Application_Model_DbTable_Client extends Zend_Db_Table_Abstract {

    protected $_name = 'client';

    public function getClient($id) {
        global $db;
        $query = $db->select()->from('client');
        if ($id > 0) {
            $query->where('Id=?', $id);
        }
        $data = $db->fetchAll($query);
        return $data;
    }

    public function addClient() {
        print_r($data);
        die;
        $data = array('fisrtname' => 'firstname',
            'lastname' => 'lastname',
            'email' => 'email');
        $this->insert($data);
    }

    public function updateClient() {
        $data = array('fisrtname' => 'firstname',
            'lastname' => 'lastname',
            'email' => 'email');
        $this->update($data, 'Id=' . $id);
    }

1 个答案:

答案 0 :(得分:1)

  

为什么你没有在模型中捕获任何参数?

如果你没有抓住它们,它将如何获得价值!!

使用此,

 public function updateclient($id, $firstname, $lastname, $email) {
        $data = array('fisrtname' => $firstname,
            'lastname' => $lastname,
            'email' => $email);
        $this->update($data, 'Id=' . $id);
    }

也用于将数据填充到表单使用中,

$form->populate不是$this->populate ..