0

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");
Matthieu Napoli
  • 48,448
  • 45
  • 173
  • 261
Fawad Ghafoor
  • 6,039
  • 7
  • 41
  • 53
  • Why can you not do this? It looks to be the correct method. – Richard Parnaby-King Jan 31 '12 at 09:43
  • What do you mean by "I am not submitting"? You are not clicking the link? Do you want to pass the variable from view to controller in the same request? – bububaba Jan 31 '12 at 09:55
  • http://localhost/phoggi/web_root/index.php/login/calllogs/id/439 i dont want to show it in address bar – Fawad Ghafoor Jan 31 '12 at 09:58
  • @bububaba its just a link i meant.certainly i want clcik.yes when user click the link i want the programe to go to action which is going but the id is showing in address bar i dont want this – Fawad Ghafoor Jan 31 '12 at 09:59
  • @xaineekhan Your question is not clear. And what do you "don't want to show in the address bar"? Can you explain a bit more. – Matthieu Napoli Jan 31 '12 at 10:04

2 Answers2

1

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.

Hecksa
  • 2,762
  • 22
  • 34
1

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");
bububaba
  • 2,840
  • 6
  • 25
  • 29
  • i dont want to use POST here and also i dont want to show it in address bar is it possible ?? – Fawad Ghafoor Jan 31 '12 at 10:10
  • 1
    @xainee Khan If you won't use post or get use ajax. use a javascript. PHP needs some way to get the info from the client to the server and you don't like either of the methods appropriate to this context. That leaves javascript. You could actually hash the id before putting it in the url. ;) – RockyFord Jan 31 '12 at 11:54
  • @RockyFord how can i call the ajax request to that action in my controller – Fawad Ghafoor Jan 31 '12 at 12:46
  • Of course, ajax ultimately uses http anyway (ie post or get) - there's no getting around the simple fact that you're going to have to use one or the other. – Hecksa Jan 31 '12 at 13:37