Yii 1.1: sitemapgenerator

sitemap.xml generator

Generates sitemap.xml file by docComment mark @sitemap for Yii controllers actions. Has lots of options, built-in URL-parsers for CActiveRecord and CViewAction, allows dynamic creation of urls.


  • Yii 1.1.8 (other versions not tested).
  • PHP 5.2 or later.
  • PHP Reflection extension.
  • PHP SimpleXML extension.


Adding URLs to sitemap.xml

Single URL

To add single url by action route just add @sitemap comment:

 * @sitemap
public function actionIndex() { ... }

For more functional adding of URLs please see adding URLs wiki page.


2011/10/25 - v0.81a

  • Small bugfixes: php5.2 support for custom models URLs parser by name, and strict mode errors.

2011/10/17 - v0.8a

  • Warning: NO backward compatibility for previous versions. Lots of changes in code. If you want to upgrade from previous version, please reinstall extension. See Installation wiki page. Already added @sitemap marks will work fine with new version.
  • All configuration moved to config/main.php. Sitemap files are now rendered through own separate controller (no need for code in other controllers except for adding URLs).
  • Added caching support. wiki
  • Added flexible pre-import support. wiki
  • Added support of multiple @sitemap marks in single method doc-comment.
  • Added built-in parsers for adding CActiveRecord models and CActionView files. Wiki pages: CActiveRecord-based URLs and CViewAction view files.
  • Added support for 'yiic messages' and russian messages file (mostly contains exception messages).

2011/10/09 - v0.7a

  • Added to google code. Most of description (which became to large for single extension page) moved to wiki pages. See links section.
  • Added CBaseUrlRule class file for handling routes and CAction class file for handling sitemap action. New installation and configuration became even more easily, especially for multiple sitemap files.
  • Aliases now can be specified as comma-separated string.
  • Added configuration option for route structure. Before that it was by default 'application,modules,controllers'.
  • lastmod attribute now can be specified by unix timestamp integer(!) value. Can be useful while using PHPs time(), filemtime() and other functions.
  • Small bugfixes.
  • Full backward compatibility.

2011/10/04 - v0.6a

  • Aliases now can be specified to directories of controllers and also to exact controllers files. Example: $aliases=array('application.controllers.SiteController');

  • Added support for multiple sitemap.xml files. See description for examples. Protocol details: sitemap index file.

  • Max urls limited to 50000 per single sitemap.xml file. Link: sitemap size Filesize are not checked due to different php settings of data compressing (zlib extension and etc.). If there is serious probability that file size will exceed 10mb, then you will need to create several sitemap files with sitemap index.

  • Forced conversion datetime's ('lastmod' attribute) to W3C datetime format. Source datetime must be specified in valid datetime format. Timezone must be set in given datetime. If it's not, then will be used default timezone (or you can set it with php function date_default_timezone_set()). Details.

  • Fixed: Urls with GET params are now escaped. Link: Sitemap url escaping

  • Added SitemapGenerator::renderAsGz() If by any reason zlib doesn't make buffer output auto-gz-encoding, you can use SitemapGenerator::renderAsGz() method, which is clone of SitemapGenerator::render(), but with forced gzencoding.

  • To render() methods added headers for browser caching disabling and error exception handling.

2011/10/03 - v0.51a

  • fixed PHP 5.2 support.

Total 20 comments

#19099 report it
dmapes123 at 2015/03/14 03:59pm
moved to github

with the original author's permission I have moved this over to github and will be helping to maintain from here on. please find it at: https://github.com/duncanmapes/yii-sitemapgenerator

#13348 report it
Tpoxa at 2013/05/23 03:24pm

It won't work without any parameters

You have to write anything. Example

/** * @sitemap some=param */

#10477 report it
bipin000 at 2012/10/30 10:10pm
Sitemap For Static Pages

How can i set sitemap for the static pages

#10107 report it
dmapes123 at 2012/10/04 11:56am
@chifliiiii multiple maps for one controller

I had to resort to creating extra controllers around the same model, then configuring them to only send a range of the urls.

    public function getModelsUrls()
    $criteria = new CDbCriteria();
    $criteria->limit = 49999;
    $criteria->offset = 199997;
    $criteria->order = "id ASC";

    foreach($models as $model)
                // Optional parameters

   return $data;

 * @sitemap dataSource=getModelsUrls 
#10085 report it
chifliiiii at 2012/10/03 06:14pm
How to split into multiple sitemaps from one controller?

Im generating urls from a model with +25k records and i would like to split it in 2 sitemaps. How can i do that? Its possible?

#7690 report it
jcny at 2012/04/09 10:31pm
Having trouble getting it to work

I put the files in extensions/sitemapgenerator, and have the following in my main.php config file:



                                    'route'=>'/sitemap', // Optional. Default: '/sitemap'


I have 10 controllers in my controllers folder, and nothing shows up under localhost/sitemap.xml

If I add @sitemap to a controller action, I get "Undefined offset: 1". and it refers to SiteMapGenerator line 438L


Any idea what I am doing wrong here? Thanks.

#6790 report it
sobit at 2012/02/05 07:17am

Sorry, first var_dump worked but showed nothing because of ".xml". In the source code I found following:


string(1) " "


Option &#039;<br />
&#039; cannot be empty.
#6789 report it
Evgeny L at 2012/02/05 07:08am

Then looks like you have to move upper by the code execution and debug method parseController

SitemapGenerator.php, line 223

How it happens that this errors pass to parser.

#6788 report it
sobit at 2012/02/05 07:01am

It was the output of var_dump placed exactly where you said.

#6787 report it
Evgeny L at 2012/02/05 06:59am

This error doesn't tells anything about sitemapgenerator. Please debug exactly where is appears. Or what outputs var_dump wich i recommend you to debug in previous comment.

#6786 report it
sobit at 2012/02/05 06:54am

here's the output :(

This page contains the following errors:
error on line 1 at column 1: Document is empty
Below is a rendering of the page up to the first error.
#6785 report it
Evgeny L at 2012/02/05 06:45am

Khm. Can't tell you anything more about what is the problem. Try to debug through file SitemapGenerator.php, line 444 (methos parseParamsString), insert code var_dump($string); and see yourself wich string parser cannot process.

#6784 report it
sobit at 2012/02/05 06:39am

I deleted all phpdocs and still getting the error. :(

There is about 8-9 controllers in the folder and error appears only when I add at least 1 @sitemap in it. However, it works perfect with controllers that are not in the module.

The module I'm testing it with is yii-user

Do you think it is the module's problem?

#6783 report it
Evgeny L at 2012/02/05 06:26am

Thanks, glad to help.

About your problem, maybe somewhere in doccomments you paste wrong configuration wich cannot be parsed. Search for strings with sign equal '=' and empty string near it, like:

@sitemap = @sitemap route=

or something like this.

#6781 report it
sobit at 2012/02/05 06:12am
help with modules generating

Hi, firstly I would like to thank you for this extension.

My problem is when I add @sitemap to module controllers I'm getting the error "Option ' ' cannot be empty."

What might be the problem?

#5971 report it
dmapes123 at 2011/12/01 01:15pm

I am using the cache for now, thanks. Is there a way to break up a specific controllers links into multiple files?

#5910 report it
Evgeny L at 2011/11/24 01:22am
File storing

Why not to use just Yii file caching? This way you can also add dependency for validating sitemap file. Caching support for component

                                'cache'=>array('Some_CFileCache_Component', 99999999, SOME_DEPENDENCY_COMPONENT),

This may solve your issue.

#5906 report it
dmapes123 at 2011/11/23 05:11pm
generate file

love the extension, has some trouble wrapping my head around it at first, but now its working great. My only question is, do you have a way to actually generate a file that sits on the server to be downloaded, so that the server doesn't have to run it every time the file is called? My sitemap(s) will have 100k+ urls and i'd prefer to have the file sitting as opposed to having it generated dynamically.


#5482 report it
Evgeny L at 2011/10/15 08:34am

Try to do the following:

 * @sitemap dataSource=sitemapActions route=/feedback

Where /feedback is your route. This should do the work.

And may be there is a small error (single quote missing after about):

#5481 report it
Yeti at 2011/10/15 08:17am
Re: Issue with CController::actions() URL creation

This is the function I have for generating the sitemap data for the actions() method; I have only show the settings for properties.

public function sitemapActions() {
  $data = array();
  foreach (array('about','by','index') as $id) {
    switch ($id) {
      case 'about':
        foreach (Property::model()->visible()->findAll() as $property) {
          $data[] = array(
      case 'by':
        // similar to properties, except for users
      case 'index':
        $data[] = array('params'=>array($id=>''));
  return $data;

The change I made in previous comment allows me to just specify the action id and parameters and sitemapGenerator generates the URL for me.

Leave a comment

Please to leave your comment.

Create extension