Page 1 of 1

Zend Request object issue

Posted: Thu May 07, 2009 10:05 am
by alex.barylski
I have custom routes setup and so long as I indicate in the route which directory maps to which parameter name all is well.

However I have a situation where I want a dynamic URL in addition to the route given.

Code: Select all

business/showmap?pkid=123&city=test
EDIT | Basically I need the custom route to invoke the business controller and it's action showmap (which maps to a method called showLargeScaleGoogleMapAction -- so default routing won't work)

When I make a request like this -- the $request object does not contain the GET variables as expected. It does contain those mapped in the route however.

How do I access standard GPC variables? I'm wondering whether or not Apache .htaccess is responsible for this?

Code: Select all

 
RewriteEngine On
 
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
 
RewriteRule ^.*$ - [QSA,NC,L]
 
RewriteRule ^.*$ index.php [QSA,NC,L]
 
I made sure to add QSA flags but still no dice -- how do I access the GET parameters passed via URI but in addition to those mapped via routes???

Cheers,
Alex

Re: Zend Request object issue

Posted: Thu May 07, 2009 11:04 am
by Eran
Use '*' to indicate extra parameters after the route:

Code: Select all

/:controller/:action/*

Re: Zend Request object issue

Posted: Thu May 07, 2009 11:36 am
by alex.barylski
Awesome I'll try that...thanks man...I was kind of thinking you'd be the one to answer me -- again thanks for the speedy reply :)

Re: Zend Request object issue

Posted: Thu May 07, 2009 11:44 am
by alex.barylski
Still didn't do the trick, here is the output from my request object:

Code: Select all

Zend_Controller_Request_Http Object
(
    [_paramSources:protected] => Array
        (
            [0] => _GET
            [1] => _POST
        )
 
    [_requestUri:protected] => /business/showmap?pkid=2344
    [_baseUrl:protected] => 
    [_basePath:protected] => 
    [_pathInfo:protected] => /business/showmap
    [_params:protected] => Array
        (
            [controller] => business
            [action] => show-large-map-display
        )
 
    [_aliases:protected] => Array
        (
        )
 
    [_dispatched:protected] => 1
    [_module:protected] => default
    [_moduleKey:protected] => module
    [_controller:protected] => business
    [_controllerKey:protected] => controller
    [_action:protected] => show-large-map-display
    [_actionKey:protected] => action
)

Here is the XML route:

Code: Select all

  <business2>    <route>/business/showmap/*</route>    <defaults>      <controller>business</controller>      <action>show-large-map-display</action>    </defaults>  </business2>
Here is what the method looks like:

Code: Select all

public function showLargeMapDisplayAction()
{
  $response = $this->getResponse();
  $request = $this->getRequest();
 
  echo '<pre>';
  print_r($request);
  exit;
}
Here is the request URI:

Code: Select all

http://www.domain.com/business/showmap?pkid=2344
I'm not sure what I'm missing but should I not be able to access 'pkid' from $request->getParam('pkid')

Re: Zend Request object issue

Posted: Thu May 07, 2009 2:27 pm
by alex.barylski
Ok now I cannot even get the POST data -- when I submit a form using method="post" and I print_r() the $request object fetched like so:

Code: Select all

     
$request = $this->getRequest();
 
      echo '<pre>';
      print_r($request);
      exit;
 
I don't understand how such a simple object would even fail...GET I can see being contingent on routing/routes/etc but POST?

What is it I am doing wrong that Zend won't work for something so trivial?

Cheers,
Alex

Re: Zend Request object issue

Posted: Thu May 07, 2009 2:35 pm
by John Cartwright
To have to request object return the $_POST array, you can use getPost(), i.e,

Code: Select all

$this->_request->getPost();
or try accessing the specifc var with

Code: Select all

$this->_request->getParam('email')

Re: Zend Request object issue

Posted: Thu May 07, 2009 2:40 pm
by alex.barylski
The second I did try and no dice...oddly when I access the POST data as properties it works

Code: Select all

$request->user_name;  // Works
 
$request->getParam('user_name'); // Doesn't work

Re: Zend Request object issue

Posted: Thu May 07, 2009 4:30 pm
by Eran
What type of zend router are you using?

Re: Zend Request object issue

Posted: Thu May 07, 2009 4:49 pm
by alex.barylski
The default router I believe...

Re: Zend Request object issue

Posted: Thu May 07, 2009 6:18 pm
by Eran
What does the output of the following look like:

Code: Select all

var_dump( $request -> getParams() );