Giter Site home page Giter Site logo

sitemap-2's Introduction

Site Map Extension for Yii 2 ============================ This extension provides support for site map and site map index files generating. For license information check the [LICENSE](LICENSE.md)-file. [![Latest Stable Version](https://poser.pugx.org/yii2tech/sitemap/v/stable.png)](https://packagist.org/packages/yii2tech/sitemap) [![Total Downloads](https://poser.pugx.org/yii2tech/sitemap/downloads.png)](https://packagist.org/packages/yii2tech/sitemap) [![Build Status](https://travis-ci.org/yii2tech/sitemap.svg?branch=master)](https://travis-ci.org/yii2tech/sitemap) Installation ------------ The preferred way to install this extension is through [composer](http://getcomposer.org/download/). Either run ``` php composer.phar require --prefer-dist yii2tech/sitemap ``` or add ```json "yii2tech/sitemap": "*" ``` to the require section of your composer.json. Usage ----- This extension provides support for site map and site map index files generating. You can use [[yii2tech\sitemap\File]] for site map file composition: ```php use yii2tech\sitemap\File; $siteMapFile = new File(); $siteMapFile->writeUrl(['site/index'], ['priority' => '0.9']); $siteMapFile->writeUrl(['site/about'], ['priority' => '0.8', 'changeFrequency' => File::CHECK_FREQUENCY_WEEKLY]); $siteMapFile->writeUrl(['site/signup'], ['priority' => '0.7', 'lastModified' => '2015-05-07']); $siteMapFile->writeUrl(['site/contact']); $siteMapFile->close(); ``` ## Creating site map index files There is a limitation on the site map maximum size. Such file can not contain more then 50000 entries and its actual size can not exceed 10MB. If you web application has more then 50000 pages and you need to generate site map for it, you'll have to split it between several files and then generate a site map index file. It is up to you how you split your URLs between different site map files, however you can use [[yii2tech\sitemap\File::getEntriesCount()]] or [[yii2tech\sitemap\File::getIsEntriesLimitReached()]] method to check count of already written entires. For example: assume we have an 'item' table, which holds several millions of records, each of which has a detail view page at web application. In this case generating site map files for such pages may look like following: ```php use yii2tech\sitemap\File; use app\models\Item; $query = Item::find()->select(['slug'])->asArray(); $siteMapFileCount = 0; foreach ($query->each() as $row) { if (empty($siteMapFile)) { $siteMapFile = new File(); $siteMapFileCount++; $siteMapFile->fileName = 'item_' . $siteMapFileCount . '.xml'; } $siteMapFile->writeUrl(['item/view', 'slug' => $row['slug']]); if ($siteMapFile->getIsEntriesLimitReached()) { unset($siteMapFile); } } ``` Once all site map files are generated, you can compose index file, using following code: ```php use yii2tech\sitemap\IndexFile; $siteMapIndexFile = new IndexFile(); $siteMapIndexFile->writeUp(); ``` > Note: by default site map files are stored under the path '@app/web/sitemap'. If you need a different file path you should adjust [[fileBasePath]] field accordingly.

sitemap-2's People

Contributors

klimov-paul avatar

Watchers

Nikolya avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.