Introduction to CodeIgniter April 1, 2012

Wow, I was suprised by the freedom of this framework. CI does not require the strict structure that Cakephp requires. There is no automagic here, you have to write a little more code and you have a few less helpers. Ci also has less of a community than Cake, but for me...I needed the community for the frameworks I grew up on which was Cake. It's all good, though. Ci is supposedly faster, but what's a few hundredths of a millisecond between friends? Have fun!
Okay, so it took me 2 days to recreate this site in CI. This is a first time for me to have 1 database feeding 2 frameworks. Some feature code is soon to follow.
Sitemap for SEO February 15, 2012
So you have been relying on webcrawlers to get your sites up and running? Well, if you used a framework like Cakephp or CodeIgniter, you can generate an xml sitemap and ping google, yahoo, bing or babylon and within an hour your site is recognized. I noticed that the webcrawler thing takes a couple of weeks and I refused to accept that any longer. Here is just a snippet of code which does the work. I installed the methods in a library and called them from my controller. Come on now, you are a programmer so break out of the caveman days when cavemen used to let their site sit there until it gets noticed. You can also put social media links on your site to get it noticed!
-
function index()
-
{
-
$sitemap = new google_sitemap; //Create a new Sitemap Object
-
date_default_timezone_set('UTC');
-
$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);
Pagination with CI June 9, 2012
Pagination with CI is so easy. Here is my controller function
-
public function hits(){
-
$this->load->library('session');
-
if( $this->session->userdata('login_state') !== TRUE ){
-
redirect('admin/');
-
}
-
$this->load->library('pagination');
-
$config['base_url'] = base_url().'index.php?/admin/hits/';
-
$query_str2 = "SELECT * FROM track";
-
$query2 = $this->db->query($query_str2);
-
$config['total_rows'] = $query2->num_rows();
-
$config['per_page'] = '10';
-
$config['num_links'] = '10';
-
$config['full_tag_open'] = '
-
$config['full_tag_close'] = '';
-
$this->load->library('table');
-
$this->table->set_heading('ID', 'Address', 'Date');
-
$this->load->model('Homey');
-
$query = $this->db->order_by('date', desc);
-
$query = $this->db->get('track', $config['per_page'], $this->uri->segment(3));
-
$data['hits'] = $query->result_array();
-
$data['stats'] = $this->Homey->get_hit_stats();
-
$this->pagination->initialize($config);
-
$this->load->view('admin_head');
-
$this->load->view('hit_view', $data);
-
-
}
|
|