Welcome Guest, Not a member yet? Register   Sign In
Undefined variable: MyBBI + Call to a member function login() on a non-object
#1

[eluser]Evollution[/eluser]
Call to a member function isLoggedIn() on a non-object in in/application/controllers/welcome.php on line 14





line 14 : echo ($MyBBI->isLoggedIn()) ? 'You are logged in' : 'You are not logged in';


if i echo this code on index.php it works :\
#2

[eluser]Evollution[/eluser]
+ i get the same error if i post :

if($mybb->user['uid'])
{
// If the user if logged in, display a welcoming message.
echo "Welcome back ".$mybb->user['username']."!<br />";
echo "Thanks for logging in.";
}

"Message: Undefined variable: mybb"
#3

[eluser]BrianJM[/eluser]
Post more of your controller and model.
#4

[eluser]Evollution[/eluser]
on index.php
Code:
&lt;?php
define('IN_MYBB', NULL);
require_once '/home/fifagoc1/public_html/go/forum/global.php';
require_once '/home/fifagoc1/public_html/go/application/libraries/MyBBIntegrator.php';
$MyBBI = new MyBBIntegrator($mybb, $db, $cache, $plugins, $lang, $config);

        echo ($MyBBI->isLoggedIn()) ? 'You are logged in ' : 'You are not logged in';
$login_status = $MyBBI->login($MyBBI->mybb->input['name'], $MyBBI->mybb->input['password']);
$data = $MyBBI->getUser();
echo $data['username'];
{i dont get errors }


on welcome.php:
Code:
&lt;?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Welcome extends CI_Controller {

    function __construct()
    {
        parent::__construct();
    }

    function index()
    {
        $this->load->view('welcome_message');
        

if($mybb->user['uid'])
{
    // If the user if logged in, display a welcoming message.
    echo "Welcome back ".$mybb->user['username']."!<br />";
    echo "Thanks for logging in.";
}
else
{
    // If the user is not logged in, display the login form.
    echo "&lt;form action='forums/member.php' method='post'&gt;";
    echo "&lt;input type='hidden' name='action' value='do_login' /&gt;";
    echo "&lt;input type='hidden' name='url' value='../index.php' /&gt;";
    echo "Username: &lt;input type='text' name='username' maxlength='30' /&gt;&lt;br />";
    echo "Password: &lt;input type='password' name='password' /&gt;&lt;br />";
    echo "&lt;input type='submit' name='submit' value='Login' /&gt;";
    echo "&lt;/form&gt;";
}        
    }
}

/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */

im using http://phpdave.com/MyBBIntegrator/Start to integrate mybb with CI

the problem i think is becouse of globals .
#5

[eluser]Twisted1919[/eluser]
Why the heck would you instantiate the class in your index.php file ?
You do realize that if you're doing so you are losing all of the benefits of using oop programming right ?

Go on the right way, have something like:
Code:
class MY_Controller extends CI_Controller{
  
   public $mybb;

   public function __construct()
   {
       require_once '/home/fifagoc1/public_html/go/forum/global.php';
       require_once '/home/fifagoc1/public_html/go/application/libraries/MyBBIntegrator.php';
       $this->mybb = new MyBBIntegrator($mybb, $db, $cache, $plugins, $lang, $config);
   }

}

Then extend all your controllers from MY_Controller and you magically have access to $this->mybb in each method of the child classes extended from your main controller.

With other words, you would have:
Code:
&lt;?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Welcome extends MY_Controller {

    function __construct()
    {
        parent::__construct();
    }

    function index()
    {
      $this->load->view('welcome_message');
        

      if($this->mybb->user['uid'])
      {

      }
      else
      {

      }        
    }
}

/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */


I noticed other posts of yours, you really need to understand how all of this "oop programming" works, otherwise, you will always be hitting these brick walls on simple issues.
#6

[eluser]Evollution[/eluser]
mersi dar e posibil sa fac sub forba de librarie ca sa nu copii codul de fiecare data ?!
#7

[eluser]Twisted1919[/eluser]
Cum ti-am aratat mai sus e varianta perfecta, nu vei copia codul de fiecare data, pt ca, codul e in MY_Controller, si tu extinzi fiecare controller din acel MY_Controller nu din CI_Controller deci ai access direct la variabilele si metodele din MY_Controller utilizand variabila $this.

In php oop, daca extinzi o clasa din alta, automat clasa aia preia toate atributele clasei parinte.
Ia urmatorul exemplu:
Code:
class parinte{

   public $varsta_parinte;

   public function __construct()
   {
        $this->varsta_parinte= 40 ;
   }

}

class copil extends parinte{

     public function __construct()
     {
        parent::__construct();//linia asta te asigura ca mostenesti atributele clasei parinte.
        echo $this->varsta_parinte;//40
        //va arata 40 chiar daca tu in clasa asta nu o declari, dar este preluata din clasa parinte
     }
}
Dupa cum am spus si mai sus, invata programarea oop, intelege-o, altfel chiar nu faci nimic.
#8

[eluser]Evollution[/eluser]
nam inteles eu ceva Smile

Code:
class MY_Controller extends CI_Controller{
  
   public $mybb;

   public function __construct()
   {
       require_once '/home/fifagoc1/public_html/go/forum/global.php';
       require_once '/home/fifagoc1/public_html/go/application/libraries/MyBBIntegrator.php';
       $this->mybb = new MyBBIntegrator($mybb, $db, $cache, $plugins, $lang, $config);
   }

}

asta trebuie so postez ca librarie
#9

[eluser]Evollution[/eluser]
deci am creat in app/core my_controller.php

Code:
&lt;?php
class MY_Controller extends CI_Controller{
  
   public $mybb;

   public function __construct()
   {
          define('IN_MYBB', NULL);
       require_once '/home/fifagoc1/public_html/go/forum/global.php';
       require_once '/home/fifagoc1/public_html/go/application/libraries/MyBBIntegrator.php';
       $this->mybb = new MyBBIntegrator($mybb, $db, $cache, $plugins, $lang, $config);
   }

}

si acum primesc eroarea :
Fatal error: Call to a member function simple_select() on a non-object in /home/fifagoc1/public_html/go/forum/inc/class_datacache.php on line 80


Line 80

// Database cache
$query = $db->simple_select("datacache", "title,cache");
while($data = $db->fetch_array($query))
{
$this->cache[$data['title']] = unserialize($data['cache']);
}
}
}

ceva idei :|
#10

[eluser]Twisted1919[/eluser]
Din cate imi dau eu seama, cred ca nu se poate conecta la baza de date, poate incerci setarile din nou ?
N-am nici ceea mai vaga ideea de ce ar merge asha pentru ca eu unu nu folosesc forumuri .
Interesant este, cand iti da eroarea asta ? cand instantiezi $this->mybb=? sau ?




Theme © iAndrew 2016 - Forum software by © MyBB