Welcome Guest, Not a member yet? Register   Sign In
Colin William template library facebook_connect quirk
#1

[eluser]joeizang[/eluser]
hi guys,

SORRY FOR THE LONG POST. I JUST WANT TO BE CLEAR!! :cheese:

I am using the stated template library in my ci setup and everything works great except for when i use Mr. Haughin's facebook_connect!
facebook_connect works beautifully if I call anything in a separate view file in my controller like so:

Code:
function facebookconnect()
    {
      $this->load->library('facebook_connect');
        $data = array(
            'user'        => $this->facebook_connect->user,
            'user_id'    => $this->facebook_connect->user_id
            );
      
      
      $this->template->write_view('content','fbtest',$data);
      $this->template->render();
    }
this works no problem calling it from it's own page and everyone is happy. But when I try to put my facebook interactivity into a div on my homepage with this code:

Code:
function index()
    {
        $this->load->library('facebook_connect');
        
        $data = array(
            'user' => $this->facebook_connect->user,
            'user_id' => $this->facebook_connect->user_id
            );
        $this->template->write_view('content','indexpage',$data);
        $this->template->render();
    }
My homepage loads fine but I have this error:
Code:
A PHP Error was encountered

Severity: Notice

Message: Undefined variable: user_id
Filename: views/indexpage.php
Line Number: 32
This i think is strange as it works with code above. My variables are passed so I don't get it.
What I want to achieve is that on the homepage a list of facebook friends should appear when page loads. Is there anything i should know about this library? I went through the userguide looking for to see if i could write a separate view to the div that should carry the facebook connect results. Here is my view code just incase it will help:

Code:
<div class="entry">
<p>
&lt;?php if ( !$user_id ): ?&gt;
<fb:login-button></fb:login-button>
&lt;?php else: ?&gt;
<img class="profile_square" src="&lt;?=$user['pic_square']?&gt;" />
Hi &lt;?=$user['first_name']?&gt;!<br />
<a href="#">(Logout)</a>
&lt;?php endif; ?&gt;
            
    <h2 class="title">Here's some comments!</h2>
    <fb:comments title="Facebook Connect Test" width="520px"></fb:comments>
[removed]
    FB.init("&lt;?=$this->config->item('facebook_api_key')?&gt;", "/xd_receiver.htm");
[removed]
</p>
</div>
#2

[eluser]joeizang[/eluser]
just as an update, i changed the index function to look like this:

Code:
function index()
    {
       $this->load->library('facebook_connect');
            
    $data = array(
            'user'        => $this->facebook_connect->user,
            'user_id'    => $this->facebook_connect->user_id
        );
      
    $this->load->vars($data);
    $this->template->write_view('content','indexpage');
        $this->template->render();
    }

This eliminates the error on my homepage, but nothing from facebook comes through! will still look further into this, any ideas are welcome.
#3

[eluser]easylancer[/eluser]
Remove those short tag php code from the view file, so change &lt;?= to be &lt;?php echo




Theme © iAndrew 2016 - Forum software by © MyBB