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");
5
  • Why can you not do this? It looks to be the correct method. Commented Jan 31, 2012 at 9: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? Commented Jan 31, 2012 at 9:55
  • localhost/phoggi/web_root/index.php/login/calllogs/id/439 i dont want to show it in address bar Commented Jan 31, 2012 at 9: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 Commented Jan 31, 2012 at 9: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. Commented Jan 31, 2012 at 10:04

2 Answers 2

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");
Sign up to request clarification or add additional context in comments.

4 Comments

i dont want to use POST here and also i dont want to show it in address bar is it possible ??
@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 how can i call the ajax request to that action in my controller
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.
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.

4 Comments

@Hecksa /controller/action/id/123 is equivalent to /controller/action/?id=123
@Matthieu interesting, never come across that one before. Thanks.
@xaineekhan updated the answer to use POST with a form. Obviously you can style the submit button to look like a link if you wish.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.