0

我一直在关注 ZF2 网站的代码。

以下代码用于工作。当网站不起作用时,网站的输出很简单。其他控制器上的其他重定向正在工作。

提前感谢=)

public function addAction() {
    $form = new CustomerForm();
    $form->get('submit')->setValue('Add');

    $request = $this->getRequest();
    if ($request->isPost()) {

        //$form->setInputFilter($customer->getInputFilter());
        $form->setData($request->getPost());

        if ($form->isValid()) {
            //return $this->redirect()->toRoute('customer/sub', array('controller' => 'customer')); //<-- This line works
            $customer = new Customer();
            return $this->redirect()->toRoute('customer/sub', array('controller' => 'customer')); //<-- This line does not working

            $customer->exchangeArray($form->getData());
            $this->getCustomerTable()->saveCustomer($customer);
            // Redirect to list of albums
            //return $this->redirect()->toRoute('customer/sub', array('controller' => 'customer'));
        }
    }
    return array('form' => $form);
}

客户.php

namespace Customer\Model;

class Customer {
public $customerID;
public $name;
public $code;
public $address;
public $postalCode;
public $country;
public $city;
public $state;
public $contactPersonName;
public $contactEmail;
public $contactTel;
public $contactFax;
public $status;
public $credit;
protected $inputFilter;                       // <-- Add this variable

public function exchangeArray($data) {

    $this->customerID = (isset($data['customerID'])) ? $data['customerID'] : null;

    $this->name = (isset($data['name'])) ? $data['name'] : null;

    $this->code = (isset($data['code'])) ? $data['code'] : null;

    $this->address = (isset($data['address'])) ? $data['address'] : null;

    $this->postalCode = (isset($data['postalCode'])) ? $data['postalCode'] : null;

    $this->country = (isset($data['country'])) ? $data['country'] : null;

    $this->city = (isset($data['city'])) ? $data['city'] : null;

    $this->state = (isset($data['state'])) ? $data['state'] : null;

    $this->contactPersonName = (isset($data['contactPersonName'])) ? $data['contactPersonName'] : null;

    $this->contactEmail = (isset($data['contactEmail'])) ? $data['contactEmail'] : null;

    $this->contactTel = (isset($data['contactTel'])) ? $data['contactTel'] : null;

    $this->contactFax = (isset($data['contactFax'])) ? $data['contactFax'] : null;

    $this->status = (isset($data['status'])) ? $data['status'] : null;

    $this->credit = (isset($data['credit'])) ? $data['credit'] : null;
}

// Add content to this method:



}
?>
4

1 回答 1

0

听起来你的$customer = new Customer()电话快要死了。您是否有上面的 use 语句来注入客户/模型?

于 2013-09-23T22:05:56.103 回答