Zend Request object issue

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

Zend Request object issue

Post 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
User avatar
Eran
DevNet Master
Posts: 3549
Joined: Fri Jan 18, 2008 12:36 am
Location: Israel, ME

Re: Zend Request object issue

Post by Eran »

Use '*' to indicate extra parameters after the route:

Code: Select all

/:controller/:action/*
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

Re: Zend Request object issue

Post 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 :)
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

Re: Zend Request object issue

Post 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')
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

Re: Zend Request object issue

Post 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
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: Zend Request object issue

Post 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')
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

Re: Zend Request object issue

Post 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
User avatar
Eran
DevNet Master
Posts: 3549
Joined: Fri Jan 18, 2008 12:36 am
Location: Israel, ME

Re: Zend Request object issue

Post by Eran »

What type of zend router are you using?
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

Re: Zend Request object issue

Post by alex.barylski »

The default router I believe...
User avatar
Eran
DevNet Master
Posts: 3549
Joined: Fri Jan 18, 2008 12:36 am
Location: Israel, ME

Re: Zend Request object issue

Post by Eran »

What does the output of the following look like:

Code: Select all

var_dump( $request -> getParams() );
Post Reply