Question

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");
Was it helpful?

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");

OTHER TIPS

Initial answer was the same as your attempt, as it turns out.

If you don't want the id in the address bar (bear in mind anyone can see post data if they have the right tools anyway) then your other option is using POST with a form -

<form action="<?php echo $this->url.'/login/calllogs/id';?>" method="post">
<input type="hidden" name="id" value="<?php echo $record->phone_service_id; ?>" />
<input type="submit" name="submit" value="Control Panel" />
</form>

You'd then need to use getPost rather than getParam in the controller to get the variable.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top