Skip to content

Instantly share code, notes, and snippets.

@gurkanoluc
Created January 7, 2011 19:53
Embed
What would you like to do?
<?php
class MY_Controller extends Controller
{
/**
* Data to send view
* @var array
*/
protected $data = array();
public function __construct() {
parent::Controller();
$this->load->library('Facebook_Client');
$this->load->library('Layout');
$this->load->model('User_model');
$this->_fetchFlashData();
}
/**
* Render template file
* @param string $view
* @param bool $renderInLayout
*/
public function render($view, $renderInLayout = true)
{
if($renderInLayout)
$this->layout->view($view, $this->data);
else
$this->load->view($view, $this->data);
}
/**
* Fetches flash data from session and creates variables for view layer
*/
private function _fetchFlashData()
{
$this->data['flash'] = array();
$notice = $this->session->flashdata('notice');
$success = $this->session->flashdata('success');
$error = $this->session->flashdata('error');
if($notice)
$this->data['flash']['notice'] = $notice;
if($success)
$this->data['flash']['success'] = $success;
if($error)
$this->data['flash']['error'] = $error;
}
/**
* Checks user is logged in or not
* If it is logged in returns it's user id
*/
public function isLogin()
{
$userId = $this->session->userdata('user_id');
return $userId;
}
/**
* Makes current user logged in
*/
public function beLoggedIn($userId)
{
$this->session->set_userdata('user_id', $userId);
// Fetch facebook user information
$fbUid = $this->facebook_client->getUid();
$accessToken = $this->facebook_client->getAccessToken();
$this->session->set_userdata('fb_uid', $fbUid);
$this->session->set_userdata('access_token', $accessToken);
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment