This forum is in READ-ONLY mode.
You can look around, but if you want to ask a new question, please use Stack Overflow.

[Day 5] "url_for" question

Discussion around this tutorial for symfony 1.2-1.4

[Day 5] "url_for" question

by julien34 » Wed Jan 07, 2009 3:45 pm

Hi,

I'm trying to take the jobeet tutorial, and i'm stuck with a problem of url formating :

In the tutorial, the "pretty" url is "/job/sensio-labs/paris-france/1/web-developer" whereas in my case, I get "job/Sensio+Labs/Paris%2C+France/1/Web+Developer".

If I try to get each variable separately (getCompany(), getLocation()...) they are ok. But when they are formated by url_for(), spaces are replaced by plus signs and commas are replaced by '%2'

Here is my routing.yml :
Code: Select all
# default rules

job:
  url:   /job/:company/:location/:id/:position
  param: { module: job, action: show }

homepage:
  url:   /
  param: { module: job, action: index }

default_index:
  url:   /:module
  param: { action: index }

default:
  url:   /:module/:action/*

and my indexSuccess.php :
Code: Select all
<?php use_stylesheet('jobs.css') ?>
 
<div id="jobs">
  <table class="jobs">
    <?php foreach ($jobeet_job_list as $i => $job): ?>
      <tr class="<?php echo fmod($i, 2) ? 'even' : 'odd' ?>">
        <td class="location"><?php echo $job->getLocation() ?></td>
        <td class="position">
          <a href="<?php echo url_for('job/show?id='.$job->getId().'&company='.$job->getCompany().'&location='.$job->getLocation().'&position='.$job->getPosition()) ?>">
            <?php echo $job->getPosition() ?>
          </a>
        </td>
        <td class="company"><?php echo $job->getCompany() ?></td>
      </tr>
    <?php endforeach; ?>
  </table>
</div>


Maybe there is something I don't get.

Thank you
julien34
Junior Member
 
Posts: 2
Joined: Wed Jan 07, 2009 3:33 pm

Re: [Day 5] "url_for" question

by catchamonkey » Wed Jan 07, 2009 4:56 pm

Read on, the next part shows you how to slugify the route to remove those parts on the fly.
catchamonkey
Faithful Member
 
Posts: 250
Joined: Fri Aug 24, 2007 10:22 am

Re: [Day 5] "url_for" question

by highjo » Mon Jan 19, 2009 12:29 pm

Hi! it's not that i'm having the same problem.Mine works fine and shows the expected pretty url

only when i click on the link from the frontend_dev.php. But i have page not found errorno 404 if i click the link from the index.php frontend.it displays
.the error is the normal browser 404 not the symfony one.if i hit myself this url:
Can any one explain to me why i'm having this and if i have done something wrong.Thank you
highjo
Junior Member
 
Posts: 14
Joined: Sun Nov 30, 2008 4:21 pm

Re: [Day 5] "url_for" question

by upalom00 » Sun Apr 05, 2009 9:23 am

symfony cc
?
upalom00
Junior Member
 
Posts: 19
Joined: Thu Oct 16, 2008 8:34 am
Location: California

Re: [Day 5] "url_for" question

by Beginner88 » Tue Nov 08, 2011 7:36 pm

after i modify the indexSuccess.php
( i have the same as julien34)
i receive this errors:
Notice: Undefined variable: jobeet_job_list in F:\Proiecte\newproject\apps\frontend\modules\job\templates\indexSuccess.php on line 7

Warning: Invalid argument supplied for foreach() in F:\Proiecte\newproject\apps\frontend\modules\job\templates\indexSuccess.php on line 7

any ideea?thanks!
Beginner88
Junior Member
 
Posts: 2
Joined: Tue Nov 08, 2011 7:23 pm

Re: [Day 5] "url_for" question

by Beginner88 » Tue Nov 08, 2011 8:02 pm

i have resolved my idex now looks like:
<div id="jobs">
<table class="jobs">
<?php foreach ($jobeet_jobs as $i => $job): ?>
<tr class="<?php echo fmod($i, 2) ? 'even' : 'odd' ?>">
<td class="location"><?php echo $job->getLocation() ?></td>
<td class="position">
<a href="<?php echo url_for('job/show?id='.$job->getId().'&company='.$job->getCompany().
'&location='.$job->getLocation().'&position='.$job->getPosition()) ?>">
<?php echo $job->getPosition() ?>
</a>
</td>
<td class="company"><?php echo $job->getCompany() ?></td>
</tr>
<?php endforeach ?>
</table>
</div>
Beginner88
Junior Member
 
Posts: 2
Joined: Tue Nov 08, 2011 7:23 pm