Search code examples
zend-frameworkzend-viewzend-controller

how to pass variable from View To Controller Action In Zend Framework


In my view i have this line of code

<a href="<?php echo $this->url.'/login/calllogs/id/'.$record->phone_service_id;?>">Control Panel</a>

in my Login Controller I have this action

public function calllogsAction(){
    if(!Zend_Auth::getInstance()->hasIdentity()){
        $this->_redirect('login/login');
    } else{
        $request = $this->getRequest();
        $this->view->assign('url', $request->getBaseURL());
    }
}

How can i get my view variable ($record->phone_service_id;) in my action (calllogsAction)? I am not submitting , this is just a link. I think i cant do it it like this in my action calllogsAction

$request = $this->getRequest();
$phone_service_id =  $request->getParam("id");

Solution

  • If you don't want the id to show in the address bar, then you will have to use POST. Use

    <form method="post" action="<?php /*your URL here*/ ?>">
    

    instead of a plain link, inside the form:

    <input type="hidden" name="id" value="<?php /*your id here*/ ?>"/>
    

    and in the controller use

    $id = $this->getRequest()->getPost("id");