请求中的php + zend..pass参数

时间:2010-10-24 17:39:40

标签: php model-view-controller smarty

我想传递参数以及我的添加操作。即如果单击菜单项中的所有者,则默认情况下应设置“is_owner”,否则重置...另外使用“添加”想要再发送一个参数并访问它在视图中。这是请求调度程序..

$ router-> map('Company','Company',array('controller'=>'companies','action'=>'add'));

  $router->map('people', 'people', array('controller' => 'people', 'action' => 'index'));
  $router->map('people_archive', 'people/archive', array('controller' => 'people', 'action' => 'archive'));

这是在控制器类

中添加操作
 function add() {
  if($this->request->isApiCall() && !$this->request->isSubmitted()) {
    $this->httpError(HTTP_ERR_BAD_REQUEST, null, true, true);
  } // if

  if(!Company::canAdd($this->logged_user)) {
    $this->httpError(HTTP_ERR_FORBIDDEN, null, true, $this->request->isApiCall());
  } // if

  $company = new Company();
  $options = array('office_address', 'office_phone', 'office_fax', 'office_homepage','office_is_owner');

  $company_data = $this->request->post('company');
  $this->smarty->assign(array(
    'company_data' => $company_data,
    'active_company' => $company,
  ));

  if ($this->request->isSubmitted()) {
   db_begin_work();

   $company = new Company();
   $company->setAttributes($company_data);
   $company->setIsOwner(false);

    $save = $company->save();

    if($save && !is_error($save)){
      foreach($options as $option) {
        $value = trim(array_var($company_data, $option));

        if($option == 'office_homepage' && $value && strpos($value, '://') === false) {
          $value = 'http://' . $value;
        } // if

        if($value != '') {
          CompanyConfigOptions::setValue($option, $value, $company);
        } // if
      } // foreach

      db_commit();

      if($this->request->getFormat() == FORMAT_HTML) {
       flash_success("Company ':name' has been created", array('name' => $company->getName()));
       $this->redirectToUrl($company->getViewUrl());
      } else {
       $this->serveData($company, 'company');
      } // if
    } else {
      db_rollback();

     if($this->request->getFormat() == FORMAT_HTML) {
      $this->smarty->assign('errors', $save);
     } else {
      $this->serveData($save);
     } // if
    } // if
  } // if
} // add

plz plz plz帮帮我

1 个答案:

答案 0 :(得分:0)

你不能只通过控制器和动作传递附加参数吗?:

$router->map('Company', 'Company', array(
     'controller' => 'companies',
     'action' => 'add',
     'paramkey' => 'paramvalue',
     'anotherparam' => 'anothervalue'));

然后这些会显示在请求中,但可能不会发布。在传递这些参数时,请尝试查看控制器的$ this->请求。