Commits

Vasiliy Toporov  committed c08bd6b

Better routes for Job.

  • Participants
  • Parent commits 8a4c422

Comments (0)

Files changed (7)

File app/config/routing_dev.yml

-_welcome:
-    pattern:  /
-    defaults: { _controller: AcmeDemoBundle:Welcome:index }
-
-_demo_secured:
-    resource: "@AcmeDemoBundle/Controller/SecuredController.php"
-    type:     annotation
-
-_demo:
-    resource: "@AcmeDemoBundle/Controller/DemoController.php"
-    type:     annotation
-    prefix:   /demo
+_assetic:
+    resource: .
+    type:     assetic
 
 _wdt:
     resource: "@WebProfilerBundle/Resources/config/routing/wdt.xml"

File src/Ens/JobeetBundle/Entity/Job.php

 namespace Ens\JobeetBundle\Entity;
 
 use Doctrine\ORM\Mapping as ORM;
+use Ens\JobeetBundle\Utils\Jobeet as Jobeet;
 
 /**
  * Ens\JobeetBundle\Entity\Job
     {
         $this->updated_at = new \DateTime();
     }
+    
+    public function getCompanySlug()
+    {
+        return Jobeet::slugify($this->getCompany());
+    }
+ 
+    public function getPositionSlug()
+    {
+        return Jobeet::slugify($this->getPosition());
+    }
+ 
+    public function getLocationSlug()
+    {
+        return Jobeet::slugify($this->getLocation());
+    }
 }

File src/Ens/JobeetBundle/Resources/config/routing.yml

 EnsJobeetBundle_job:
     resource: "@EnsJobeetBundle/Resources/config/routing/job.yml"
     prefix: /job
-
-ens_jobeet_homepage:
-    pattern:  /hello/{name}
-    defaults: { _controller: EnsJobeetBundle:Default:index }
+    
+EnsJobeetBundle_homepage:
+    pattern:  /
+    defaults: { _controller: EnsJobeetBundle:Job:index }

File src/Ens/JobeetBundle/Resources/config/routing/job.yml

     defaults: { _controller: "EnsJobeetBundle:Job:index" }
 
 ens_job_show:
-    pattern:  /{id}/show
+    pattern:  /{company}/{location}/{id}/{position}
     defaults: { _controller: "EnsJobeetBundle:Job:show" }
+    requirements:
+        id:  \d+
 
 ens_job_new:
     pattern:  /new

File src/Ens/JobeetBundle/Resources/views/Job/index.html.twig

           <tr class="{{ cycle(['even', 'odd'], loop.index) }}">
             <td class="location">{{ entity.location }}</td>
             <td class="position">
-              <a href="{{ path('ens_job_show', { 'id': entity.id }) }}">
+              <a href="{{ path('ens_job_show', { 'id': entity.id, 'company': entity.companyslug, 'location': entity.locationslug, 'position': entity.positionslug}) }}">
                 {{ entity.position }}
               </a>
             </td>

File src/Ens/JobeetBundle/Resources/views/layout.html.twig

   <body>
     <div id="container">
       <div id="header">
-        <div class="content">
-          <h1><a href="{{ path('ens_job') }}">
+        <div class="content">     
+          <h1><a href="{{ path('EnsJobeetBundle_homepage') }}">
             <img src="{{ asset('bundles/ensjobeet/images/logo.jpg') }}" alt="Jobeet Job Board" />
           </a></h1>
  

File src/Ens/JobeetBundle/Utils/Jobeet.php

+<?php
+// src/Ens/JobeetBundle/Utils/Jobeet.php
+namespace Ens\JobeetBundle\Utils;
+
+class Jobeet
+{
+    static public function slugify($text)
+    {
+        // replace all non letters or digits by -
+        $text = preg_replace('/\W+/', '-', $text);
+ 
+        // trim and lowercase
+        $text = strtolower(trim($text, '-'));
+ 
+        return $text;
+    }
+}