Please wait for 15 seconds...

Thursday 26 July 2012

Sometimes you need to have some data in every HTML page, like user is logged in or not, some header info or anything necessary for user interface.

Suppose you have facebook like, login buttons or Twitter follow us button at many places in your site, then you have to pass APP_KEY to every page or hardcode it in every HTML page. But you can have third way. Just pass it once in MY_Controller and echo wherever you want.

Create My_Controller in application/core. You can also change prefix(MY_) to anything you want.

class MY_Controller extends CI_Controller{
    public function __construct(){
        $uiData['fb_app_id'] = 1125225022520202;
        $this->load->view('home.htm', $uiData, true);

*Here third parameter must be true else everything will be messed up.

Now extend MY_Controller and create custom class as you want into controller folder

class Home extends My_Controller{
        public function index(){

Now echo Fabebook APP_ID into html page:

<title>Main Home</title>

<div id="fb-root"></div>
<script>(function(d, s, id) {
  var js, fjs = d.getElementsByTagName(s)[0];
  if (d.getElementById(id)) return;
  js = d.createElement(s); = id;
  js.src = "//<?=$fb_app_id?>";
  fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));</script>

     <div class="fb-login-button" data-show-faces="true" data-width="200" data-max-rows="1"></div>

and that is it. If you have any question please post your comment below.

Posted by Atul


Post a Comment

Techsirius on Facebook