Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Create a sitemap
  • Hi all,

    Sorry in advance if the question is stupid but what is the best way to create a sitemap using Fuel ?

    Thank you for your response.
  • Questions are never stupid, answers sometimes are... ;-)

    Creating a sitemap is very application dependent, so there is no clear cut answer for this, there is not an easy way to generate it, Fuel is so flexible in how you design your application that there is no mechanism to construct a sitemap, for example based on defined routes, existing controllers, etc.
  • Okey,

    So it must be done on a case by case if I understand.

    Is there a way to list all the actions of all my controllers ?
  • Not ready made.

    Run a glob(), construct the classnames from the files found, and use Reflection to get the list of methods?
  • Finally, I used my routes.php file, like that :

    public function action_sitemap()
    {
     $urls = array();
     $base = Uri::base(false);
     $i = 0;
     foreach (require(APPPATH.'config'.DS.'routes.php') as $key => $value)
     {
         // Routes to exclude
         if (    !Str::starts_with($key, '_root_') and
             !Str::starts_with($key, '_404_') and
             !Str::starts_with($key, 'admin') and
             !Str::starts_with($key, 'sitemap') )
         {
             // Dynamic routes
             if ( Str::ends_with($key, '(:any)') )
             {
                 // Theme
                 if (strpos($key, 'theme'))
                 {
                     foreach (Model_Theme::find('all') as $theme)
                     {
                         $urls[$i]['loc'] = $base.str_replace('(:any)', $theme->id, $key);
                         $urls[$i]['lastmod'] = date('Y-m-d', ($theme->updated_at === null ? $theme->created_at : $theme->updated_at));
                         $i++;
                     }
                 }
                 // Pass
                 else if (strpos($key, 'pass'))
                 {
                     foreach (Model_Pass::find('all') as $pass)
                     {
                         $urls[$i]['loc'] = $base.str_replace('(:any)', $pass->id, $key);
                         $urls[$i]['lastmod'] = date('Y-m-d', ($pass->updated_at === null ? $pass->created_at : $pass->updated_at));
                         $i++;
                     }
                 }
             }
             // Static routes
             else
             {
                 $urls[$i]['loc'] = $base.$key;
                 $i++;
             }
         }
     }
     $this->response = Response::forge();
     $this->response->set_header('Content-Type', 'application/xml');
     $this->response->body(View::forge(APPPATH.'themes'.DS.'biarritzbylocals'.DS.'public'.DS.'sitemap.twig', array('urls'=>$urls)));
     return $this->response;
    }

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion