'CodeIgniter 3 - unable to load custom library in server
Maybe this question is duplicate, but i'm already try from others discussion still can't resolve my problem. this code is working fine in my local mac, but can't load this library in hosting.
application/libraries/Sitemap im also try the filename and classname MY_Sitemap
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Sitemap {
protected $ci;
public function __construct()
{
$this->ci =& get_instance();
$this->ci->load->database();
}
public function create()
{
$sitemap = "<\x3Fxml version=\"1.0\" encoding=\"UTF-8\"\x3F>\n<urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\">\n";
$blogs = $this->ci->db->select('*')->from('blog')->where('status', '1')->order_by('publish_date', 'DESC')->get()->result();
foreach($blogs as $blog)
{
$sitemap .= "\t<url>\n\t\t<loc>" . site_url('blog/' . $blog->alias_en) . "</loc>\n";
}
$sitemap .= "</urlset>\n";
$file = fopen('sitemap.xml', 'w');
fwrite($file, $sitemap);
fclose($file);
return;
}
}
and in my controller:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Blog extends Admin_Controller {
function __construct() {
parent::__construct();
$this->load->library('Sitemap');
}
//to add a new blog
public function add() {
// generate site map
$this->sitemap->create();
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
