我使用谷歌codeigniter,我想使用站点地图,但得到以下错误,如何解决它?致命错误:找不到类'google_sitemap'
我得到这个班从这里:http://codeigniter.com/wiki/Google_Sitemaps
错误:
Fatal error: Class 'google_sitemap' not found in D:\xampp\htdocs\application\controllers\sitemap_google.php on line 13
这是控制器完整的代码在这里:d:\ XAMPP \ htdocs中\程序\控制器\ sitemap_google.php:
<?php
class Sitemap_google extends CI_Controller
{
function My_controller()
{
parent::Controller();
$this->load->helper(array('text','url'));
$this->load->plugin('google_sitemap'); //Load Plugin
}
function index()
{
$sitemap = new google_sitemap; //This is line 13
$item = new google_sitemap_item(base_url()."MY_WEBSITE_URL",date("Y-m-d"), 'weekly', '0.8'); //Create a new Item
$sitemap->add_item($item); //Append the item to the sitemap object
$sitemap->build("./sitemap.xml"); //Build it...
//Let's compress it to gz
$data = implode("", file("./sitemap.xml"));
$gzdata = gzencode($data, 9);
$fp = fopen("./sitemap.xml.gz", "w");
fwrite($fp, $gzdata);
fclose($fp);
//Let's Ping google
$this->_pingGoogleSitemaps(base_url()."/sitemap.xml.gz");
}
function _pingGoogleSitemaps($url_xml)
{
$status = 0;
$google = 'www.google.com';
if([email protected]($google, 80))
{
$req = 'GET /webmasters/sitemaps/ping?sitemap=' .
urlencode($url_xml) . " HTTP/1.1\r\n" .
"Host: $google\r\n" .
"User-Agent: Mozilla/5.0 (compatible; " .
PHP_OS . ") PHP/" . PHP_VERSION . "\r\n" .
"Connection: Close\r\n\r\n";
fwrite($fp, $req);
while(!feof($fp))
{
if(@preg_match('~^HTTP/\d\.\d (\d+)~i', fgets($fp, 128), $m))
{
$status = intval($m[1]);
break;
}
}
fclose($fp);
}
return($status);
}
}
哪个笨的版本您使用的?你可以用'echo CI_VERSION'来检查。我问,因为“插件”已被删除了一段时间。 – 2012-03-09 18:01:10
我使用Codeigniter的最新版本。 – 2012-03-09 18:01:59
如果'My_controller'应该是构造函数,那么你做错了。我认为你已经混淆了库和你的正常控制器。调用'__construct()'而不是'MY_Controller()'。 – JohnP 2012-03-09 18:04:17