开发者

php+zend..pass parameter in request

i want to pass parameter along with my add action.that is if owner in menu item is clicked then "is_owner" should by default get set otherwise reset..along with "add" want to send one more parameter and access it in view.this is request dispatcher..

$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'));

this is Add action in controller class

 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
  } 开发者_JAVA技巧// if
} // add

plz plz plz help me


can't you just pass the additional parameter with the controller and action?:

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

These then show up in the request, though probably not as post. Try seeing what your controller's $this->request looks like when you pass those parameters.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜