5

I have the following code, which works fine on live site, but not on localhost.

$status = $this->getRequest()->getQuery('status');

I have a URL like this:

http://localhost:888//questions/ask?status=10

I printed the value of status, which is always nil. I am new to Zend framework and could not find a solution to this on net, looks strange to me. Any thoughts? Thanks.

[FIXED]

I had wrong RewriteRule that caused the problem. There was an unwanted '?' after index.php in RewriteRule line. It was my mistake I added this, because other frameworks like CodeIgniter user '?' in RewriteRules. The corrected RewriteRule line is:

RewriteRule ^(.*)$ /index.php/$1 [L]

I wonder if I can choose this as accepted answer.. :-)

pMan
  • 8,808
  • 11
  • 32
  • 35
  • you get to the action controller? .htaccess is working? just the parameter is null? – Elzo Valugi Sep 17 '10 at 08:16
  • ZF2 it works `$post = $this->getRequest(); $productid = mysql_real_escape_string($post->getQuery('productid'));` –  Feb 22 '17 at 11:27

2 Answers2

6

I usually use this

$status = $this->getRequest()->getParam('status');

// or
$status = $this->getRequest()->getParams();

I assume that you have a Questions Controller Ask Action.
Here is the documentation about Zend's request

Anthony
  • 2,014
  • 2
  • 19
  • 29
Elzo Valugi
  • 27,240
  • 15
  • 95
  • 114
  • Elzo, I tried that, I always get module, controller, action, etc, but not query strings. This works as it should be on live, only localhost has problems. Am I missing any of framework's config? – pMan Sep 17 '10 at 08:59
  • have any strange routing in place? or other settings that are ENVIRONMENT dependent? – Elzo Valugi Sep 17 '10 at 09:48
  • var_dump the request object. if the status variable is in the url it should appear there as well. – Elzo Valugi Sep 17 '10 at 09:52
  • My request object never had 'status'. The only problem I had was wrong RewriteRule, I update my question. Thanks Elzo. – pMan Sep 28 '10 at 07:21
  • using zend 3, getting error after using your solution: Call to undefined method Zend\Http\PhpEnvironment\Request::getParams() – Kamlesh Sep 12 '19 at 06:19
  • this response was valid for ZF1 @Kamlesh – Elzo Valugi Sep 12 '19 at 11:50
2

For those looking for the solution to ZF2 - look at this post, helped me out dramatically. It even includes the reference to a phenomenal plugin to make this easier (as the very least, in understanding the routes/requests/params, etc...)

Getting $_GET parameters from route in Zend Framework 2

Also, in this post SO post

How to access route, post, get etc. parameters in Zend Framework 2

In short, tho -

    $this->getRequest()->getRequest('name', 'default');
    $this->getEvent()->getRouteMatch()->getParam('name', 'default');
Community
  • 1
  • 1
Bill Ortell
  • 837
  • 8
  • 12