使用Codeigniter生成Sitemap [英] Sitemap generation with Codeigniter
本文介绍了使用Codeigniter生成Sitemap的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要在codeigniter应用程序中生成站点地图。我发现了一些库,但所有的都是过时的,有bug。我真的需要一个单独的库吗?
I need to generate a sitemap in a codeigniter application. I found a few libraries but all of them are outdated and have bug. Do I really need a separate library for this?
我想知道在codeigniter中生成站点地图的最佳方法。
I want to know the best way to generate the sitemap in codeigniter.
推荐答案
您可以使用我的代码:
controllers / seo.php
controllers/seo.php
Class Seo extends CI_Controller {
function sitemap()
{
$data = "";//select urls from DB to Array
header("Content-Type: text/xml;charset=iso-8859-1");
$this->load->view("sitemap",$data);
}
}
views / sitemap.php
views/sitemap.php
<?= '<?xml version="1.0" encoding="UTF-8" ?>' ?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<url>
<loc><?= base_url();?></loc>
<priority>1.0</priority>
</url>
<!-- My code is looking quite different, but the principle is similar -->
<?php foreach($data as $url) { ?>
<url>
<loc><?= base_url().$url ?></loc>
<priority>0.5</priority>
</url>
<?php } ?>
</urlset>
添加行到config / routes.php
add line to config/routes.php
$route['seo/sitemap\.xml'] = "seo/sitemap";
对不起,如果代码中有一些错误,我特别为你。
如果有错误,您可以通过理解原则轻松地修复它们。
Sorry if there are some errors in the code, I made it especially for you. If there are errors, you can fix them easily by understanding the principle.
这篇关于使用Codeigniter生成Sitemap的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文