声明新实体 ZF2 后无法重定向



我一直在关注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 CustomerModel;
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:

}
?>

听起来它正在你的$customer = new Customer()电话中消亡。您是否有上述使用语句来注入客户/型号?

相关内容

  • 没有找到相关文章

最新更新