PHPackages                             di-just/e-sitemap-yii - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. di-just/e-sitemap-yii

ActiveYii-extension[Utility &amp; Helpers](/categories/utility)

di-just/e-sitemap-yii
=====================

Generate a sitemap based on configurable Active Records

027.9k↓32.7%PHP

Since Mar 18Pushed 4y agoCompare

[ Source](https://github.com/di-just/ESitemap)[ Packagist](https://packagist.org/packages/di-just/e-sitemap-yii)[ RSS](/packages/di-just-e-sitemap-yii/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (2)Used By (0)

```
Copy the /sitemap folder into the protected/extensions/ folder.

Move the files from the sitemap/views/ folder (sitemap.php and sitemapxml.php) into the views/site/ folder, or to whichever controller's view folder that you are going to attach the actions to.

Update your controller's actions to include the ESitemapAction and/or ESitemapXMLAction files, as follows:

public function actions()
{
    return array(
        'sitemap'=>array(
            'class'=>'ext.sitemap.ESitemapAction',
            'importListMethod'=>'getBaseSitePageList',
            'classConfig'=>array(
                array('baseModel'=>'Task',
                      'route'=>'/task/view',
                      'params'=>array('id'=>'taskId')),
                array('baseModel'=>'Post',
                	  'route'=>'/blog/post/view',
                	  'params'=>array('id'=>'post_id')),
            ),
            'import'=>array('blog.models.*')
        ),
        'sitemapxml'=>array(
            'class'=>'ext.sitemap.ESitemapXMLAction',
            'classConfig'=>array(
                array('baseModel'=>'Task',
                      'route'=>'/task/view',
                      'params'=>array('id'=>'taskId')),
                array('baseModel'=>'Post',
                	  'route'=>'/blog/post/view',
                	  'params'=>array('id'=>'post_id')),
            ),
            //'bypassLogs'=>true, // if using yii debug toolbar enable this line
            'importListMethod'=>'getBaseSitePageList',
            'import'=>array('blog.models.*'),
        ),
    );
}

And, update your URL rules to include a redirect for sitemap.xml:

'urlManager'=>array(
    ...
    'rules'=>array(
        ...
        'sitemap.xml'=>'site/sitemapxml'
    ),
),

The importListMethod allows you to use a custom method on your controller to import a list of non-dynamic page arrays which you wish to include in the sitemap, like so:

class SiteController extends Controller
{
    ....

    /**
     * Provide the static site pages which are not database generated
     *
     * Each array element represents a page and should be an array of
     * 'loc', 'frequency' and 'priority' keys
     *
     * @return array[]
     */
    public function getBaseSitePageList(){

        $list = array(
                    array(
                        'loc'=>Yii::app()->createAbsoluteUrl('/'),
                        'frequency'=>'weekly',
                        'priority'=>'1',
                        ),
                    array(
                        'loc'=>Yii::app()->createAbsoluteUrl('/site/contact'),
                        'frequency'=>'yearly',
                        'priority'=>'0.8',
                        ),
                    array(
                        'loc'=>Yii::app()->createAbsoluteUrl('/site/page', array('view'=>'about')),
                        'frequency'=>'monthly',
                        'priority'=>'0.8',
                        ),
                    array(
                        'loc'=>Yii::app()->createAbsoluteUrl('/site/page', array('view'=>'privacy')),
                        'frequency'=>'yearly',
                        'priority'=>'0.3',
                        ),
                );
        return $list;
    }
    ...
}

And finally, the heart of the matter, to include a list of model based links, provide a configuration array to the classConfig property of the action, like so:

'classConfig'=>array(
    array(
        'baseModel'=>'ModelNameOne',
        'route'=>'/route/to/controller',
        'params'=>array('property_key'=>'attribute_name')
        ),
    array(
        'baseModel'=>'Post',
        'route'=>'/post/view',
        'params'=>array('id'=>'postId')
        'scopeName'=>'sitemap'
    ),
)

To utilize the ActiveRecord, you need to have a scope named 'sitemap' which will select the proper criteria, or specify an alternate scopeName like so:

'classConfig'=>array(
    array(
        'baseModel'=>'Post',
        'route'=>'/post/view',
        'params'=>array('id'=>'postId')
        'scopeName'=>'approvedPosts'
    ),
)

Additional Class Configuration options: priority, frequency (see ESitemapModel)

Sample scope:

public function scopes()
{
    return array(
        'sitemap'=>array('select'=>'id', 'condition'=>'startDate
