Pages

Showing posts with label codeigniter. Show all posts
Showing posts with label codeigniter. Show all posts

Wednesday, September 12, 2012

CodeIgniter time ago format achieved

http://tutorialsbay.com/codeigniter-time-ago/

I wrote one custom function to achieve this

function display_time($timestamp) {
  $date_array = explode(',', timespan($timestamp, time()));
  $date = $date_array[0] . ' AGO, ';
  return($date);
}

Monday, July 9, 2012

Facebook PHP SDK logout : resolved

Facebook sdk is creating one cookie in browser.
Which has to be cleared on logout.
Here is my Codeigniter code to do that.

Logout URL
$this->facebook->getLogoutUrl(array('next' => site_url('user/logout'));


Logout Function

 public function logout() {
    setcookie('PHPSESSID', '', time()-3600, "/");
    $this->session->sess_destroy();
    redirect('/user', 'refresh');
  }

Friday, June 8, 2012

Codeigniter template structure

class Pages extends CI_Controller {

  public function view($page = 'home') {

    if (!file_exists('application/views/pages/' . $page . '.php')) {
      // Whoops, we don't have a page for that!
      show_404();
    }

    $data['title'] = ucfirst($page); // Capitalize the first letter

    $data['header'] = $this->load->view('templates/header', $data, true);
    $data['body'] = $this->load->view('pages/' . $page, $data, true);
    $data['footer'] = $this->load->view('templates/footer', $data, true);

    $this->load->view('templates/page', $data);
  }

}

 ---------------------------------------------------------------------------------------------------------


And my page.php

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <base href="<?php echo $this->config->item('base_url') ?>public/" />
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>CONTINUOUS IMPRESSION</title>
    <link href="css/style.css" rel="stylesheet" type="text/css" />
  </head>

  <body>
    <div id="container">
      <div class="main-wrapper">

        <div class="header-wrapper">
          <?php echo $header; ?>
        </div>

        <div class="content-wrapper">

          <div class="content"><?php echo $body; ?></div>

          <div class="footer">
            <?php echo $footer; ?>
          </div>
         
        </div>
      </div>
    </div>
  </body>
</html>