views:

129

answers:

2

I am trying to generate a url but I keep getting a strange warning even though it works. I am making an api xml page and I use the following call in the controller:

public function executeList(sfWebRequest $request)
{
    $this->users = array();
    foreach($this->getRoute()->getObjects() as $user)
    {
        $this->users[$this->generateUrl('user_show', $user, true)] = $user->asArray($request->getHost());
    }
}

The user_show route is as follows:

# api urls
user_show:
  url:   /user/:nickname
  param: { module: user, action: show }

And the xml outputs as follows:

<br />
<b>Warning</b>:  array_diff_key() [<a href='function.array-diff-key'>function.array-diff-key</a>]: Argument #1 is not an array in <b>/opt/local/lib/php/symfony/routing/sfRoute.class.php</b> on line <b>253</b><br />
<br />
<b>Warning</b>:  array_diff_key() [<a href='function.array-diff-key'>function.array-diff-key</a>]: Argument #1 is not an array in <b>/opt/local/lib/php/symfony/routing/sfRoute.class.php</b> on line <b>253</b><br />

<br />
<b>Warning</b>:  array_diff_key() [<a href='function.array-diff-key'>function.array-diff-key</a>]: Argument #1 is not an array in <b>/opt/local/lib/php/symfony/routing/sfRoute.class.php</b> on line <b>253</b><br />
<?xml version="1.0" encoding="utf-8"?>
<users>
  <user url="http://krowdd.dev/frontend_dev.php/user/danny"&gt;
    <name>Danny tz</name>
    <nickname>danny</nickname>
    <email>[email protected]</email>
    <image></image>
  </user>
  <user url="http://krowdd.dev/frontend_dev.php/user/adrian"&gt;
    <name>Adrian Sooian</name>
    <nickname>adrian</nickname>
  </user>
</users>

So it outputs the correct xml but I do not know why it throws thows warning when calling the generateurl method.

Thanks!

A: 

Well, the warning is pretty specific, the function array_diff_key is expecting an array as the first parameter, but its not getting one...

I don't know symfony, but has you can see on the error, it is happening at line 253 of file symfony/routing/sfRoute.class.php..

So, you are calling some function that is calling that line on that file.

I think you can use debug_backtrace to follow you code flow, and try to find were you are inserting the variable that should be an array but it isn't.

Gonçalo Queirós
+2  A: 

This is the signature of generateUrl:

public function generateUrl($route, $params = array(), $absolute = false)

Pay special attention to the second parameter. It should be an array in case of a regular route, however: if your route is an sfPropelRoute or its doctrine equivalent, it can be an object.
I believe you get those errors because the route is not defined as an sfPropelRoute (or doctrine).

Maerlyn
amazing! thanks!
Daniel Hertz