Help - Search - Members - Calendar
Full Version: Wont Display
Invision Power Services > Community Forums > Community Web Design and Coding
Alεx
Hey
I am currently devising a script where admins can edit the site, at the moment it is in BETA mode, the code I am copying below is a test script which should display
QUOTE
Welcome MEMBERSDISPLAYNAME


However, it is displaying
QUOTE


This is the code:
CODE
<?php

$INFO = array();
define('ROOT_PATH', dirname(__FILE__).'/');
define('KERNEL_PATH', ROOT_PATH.'ips_kernel/');
require_once ROOT_PATH.'sources/ipsclass.php';
require_once ROOT_PATH.'sources/classes/class_display.php';
require_once ROOT_PATH.'sources/classes/class_session.php';
require_once ROOT_PATH.'conf_global.php';

define('USE_SHUTDOWN', 0);
define('SAFE_MODE_ON', 0);
define('IN_DEV', 0);

$ipsclass       = new ipsclass();
$ipsclass->vars = $INFO;
$ipsclass->init_db_connection();
$ipsclass->init_load_cache();
$ipsclass->print            =  new display();
$ipsclass->print->ipsclass  =& $ipsclass;
$ipsclass->sess             =  new session();
$ipsclass->sess->ipsclass   =& $ipsclass;
$ipsclass->parse_incoming();
$ipsclass->initiate_ipsclass();

new Install;
class Install
{
    var $output        = "";
    var $mysql_version = "";
    var $sql_data      = array();
    var $uninstalling  = false;

    function Install()
    {
        global $ipsclass;

        switch ($ipsclass->input['edit'])
        {
            default:
                $this->intro();
                break;
        }

        $this->print_it($this->output);
    }

    function intro()
    {
        if ( $this->ipsclass->member['id'] == 1) {
            $this->output .= "<p>Welcome {$this->ipsclass->member['members_display_name']}</p>";
          } else
        { $this->output .="<p>You cannot access this area</p>"; }
    }

    function print_it($output)
    {
    }
}

?>


Is there anything wrong in there as a reason why it is not connecting to the ipsclass parts?
Digi
Well, from what I can tell, you never logged in a member...sooo...not sure what you are doing :/
Alεx
? What do you mean by logged in a member, this is my first time at coding something for IPB, but it wont access IPSclass
cmanns
Try out IPB SDK its super duper easy and fun ^.^ I felt special using it!!
.Mike
QUOTE
Is there anything wrong in there as a reason why it is not connecting to the ipsclass parts?

Honestly, and I mean this in the nicest way possible, there are quite a few errors in that code. unsure.gif

Depending on the complexity of your mod, you may consider using the component system or the module system. It does all the IPB-related setup you need-- setting up the member, loading global templates/languages, etc. It makes for much easier mod development for some mods.

Like Digi said, you need to create a session. Have a look at the index.php file for your IPB.

You'll see a section of code like this:

CODE
//--------------------------------
//  The rest :D
//--------------------------------

$ipsclass->member     = $ipsclass->sess->authorise();
$ipsclass->lastclick  = $ipsclass->sess->last_click;
$ipsclass->location   = $ipsclass->sess->location;
$ipsclass->session_id = $ipsclass->sess->session_id; // Used in URLs
$ipsclass->my_session = $ipsclass->sess->session_id; // Used in code


That is what actually creates a member session, and sets up the $ipsclass->member array. I'm not sure if simply adding that code will create the session, though-- there may be more required code that is missing.

Also, I don't think you are passing the ipsclass to your class. Try:

CODE
$install = new Install;
$install->ipsclass =& $ipsclass;
$install->intro();
$install->print_it();


Your print_it function is also empty. You need to use that function to actually do the output. Something like this:

CODE
    function print_it()
    {
        $this->ipsclass->print->add_output("$this->output");
        $this->ipsclass->print->do_output( array( 'TITLE' => 'page title goes here', 'JS' => 0, NAV => 'nav data goes here' ) );
    }




I hope that helps!

smile.gif

Mike
Alεx
Thanks so much, i left print_it blank because i was working on other parts of it, forgot, thanks!

Print it function seems to be displaying:
Fatal error: Call to a member function on a non-object in /home/***/public_html/forum/siteadmin2.php on line 77
Digi
what is on line 77
Alεx
QUOTE
$this->ipsclass->print->add_output("$this->output");
Digi
Replace this:
CODE
new Install;
class Install
{
    var $output        = "";
    var $mysql_version = "";
    var $sql_data      = array();
    var $uninstalling  = false;


With:
CODE
$run = new Install;
$run->ipsclass =& $ipsclass;
class Install
{
    var $ipsclass;
    var $output        = "";
    var $mysql_version = "";
    var $sql_data      = array();
    var $uninstalling  = false;
Alεx
Still same
O.k, going on holiday so if anyone finds a fix cant do it until next saturday
Thanks for the great help so far though smile.gif Much appreciated.
Malefickus
QUOTE(AHobbs @ Jul 28 2006, 12:35 PM) *
QUOTE
$this->ipsclass->print->add_output("$this->output");

Does the $this->output really need to be in quotes in that?
Digi
It doesn't, but it doesn't hurt either way tongue.gif
Dan_merged
Can do, on some PHP installs. wink.gif
.Mike
The problem is that your class is named Install, and you have a function named Install.

When you initialize your class, it automatically calls function Install. Since, at that point, there has been no reference passed to the class for the $ipsclass, you can't access the $ipsclass.

Here is some example code to demonstrate auto-running:
CODE
<?php

$testclass = new MyClass;

class MyClass
{
    function MyClass()
    {
        echo "This function is autorun when you initialize the class.";
    }
    
    function MyFunction()
    {
        echo "You must call this function after you initilize the class.";
    }
}
?>


Since the class (MyClass) contains a function of the same name (MyClass), that function is auto-run.

So, what you need to do is rename your Install function to something else, and then make sure you have passed a reference to the $ipsclass your class before anything else.
.Mike
Sorry for the double reply...

This code should be a lot closer to what you need.

I added the code to create a session. I renamed the Install function do_Install. I passed an $ipsclass reference to the class before calling the install procedure. I added code to the do_output function.

Untested, but closer. smile.gif

CODE
<?php

$INFO = array();
define('ROOT_PATH', dirname(__FILE__).'/');
define('KERNEL_PATH', ROOT_PATH.'ips_kernel/');
require_once ROOT_PATH.'sources/ipsclass.php';
require_once ROOT_PATH.'sources/classes/class_display.php';
require_once ROOT_PATH.'sources/classes/class_session.php';
require_once ROOT_PATH.'conf_global.php';

define('USE_SHUTDOWN', 0);
define('SAFE_MODE_ON', 0);
define('IN_DEV', 0);

$ipsclass       = new ipsclass();
$ipsclass->vars = $INFO;
$ipsclass->init_db_connection();
$ipsclass->init_load_cache();
$ipsclass->print            =  new display();
$ipsclass->print->ipsclass  =& $ipsclass;
$ipsclass->sess             =  new session();
$ipsclass->sess->ipsclass   =& $ipsclass;
$ipsclass->parse_incoming();
$ipsclass->initiate_ipsclass();

//--------------------------------
//  The rest :D
//--------------------------------

$ipsclass->member     = $ipsclass->sess->authorise();
$ipsclass->lastclick  = $ipsclass->sess->last_click;
$ipsclass->location   = $ipsclass->sess->location;
$ipsclass->session_id = $ipsclass->sess->session_id; // Used in URLs
$ipsclass->my_session = $ipsclass->sess->session_id; // Used in code

$install = new Install;
$install->ipsclass =& $ipsclass;
$install->do_Install();

class Install
{
    var $output        = "";
    var $mysql_version = "";
    var $sql_data      = array();
    var $uninstalling  = false;
    var $ipsclass;

    function do_Install()
    {
        switch ($this->ipsclass->input['edit'])
        {
            default:
                $this->intro();
                break;
        }

        $this->print_it($this->output);
    }

    function intro()
    {
        if ( $this->ipsclass->member['id'] == 1) {
            $this->output .= "<p>Welcome {$this->ipsclass->member['members_display_name']}</p>";
          } else
        { $this->output .="<p>You cannot access this area</p>"; }
    }

    function print_it()
    {
        $this->ipsclass->print->add_output($this->output);
        $this->ipsclass->print->do_output( array( 'TITLE' => 'page title goes here', 'JS' => 0, NAV => 'nav data goes here' ) );
    }
}

?>
Alεx
Thanks for the help Mike, much appreciated, however, it is now saying:

Fatal error: Call to a member function on a non-object in /home/habbowi/public_html/forum/sources/classes/class_display.php on line 93

CODE
<?php

$INFO = array();
define('ROOT_PATH', dirname(__FILE__).'/');
define('KERNEL_PATH', ROOT_PATH.'ips_kernel/');
require_once ROOT_PATH.'sources/ipsclass.php';
require_once ROOT_PATH.'sources/classes/class_display.php';
require_once ROOT_PATH.'sources/classes/class_session.php';
require_once ROOT_PATH.'conf_global.php';

define('USE_SHUTDOWN', 0);
define('SAFE_MODE_ON', 0);
define('IN_DEV', 0);

$ipsclass       = new ipsclass();
$ipsclass->vars = $INFO;
$ipsclass->init_db_connection();
$ipsclass->init_load_cache();
$ipsclass->print            =  new display();
$ipsclass->print->ipsclass  =& $ipsclass;
$ipsclass->sess             =  new session();
$ipsclass->sess->ipsclass   =& $ipsclass;
$ipsclass->parse_incoming();
$ipsclass->initiate_ipsclass();

//--------------------------------
//  The rest :D
//--------------------------------

$ipsclass->member     = $ipsclass->sess->authorise();
$ipsclass->lastclick  = $ipsclass->sess->last_click;
$ipsclass->location   = $ipsclass->sess->location;
$ipsclass->session_id = $ipsclass->sess->session_id; // Used in URLs
$ipsclass->my_session = $ipsclass->sess->session_id; // Used in code

$install = new Install;
$install->ipsclass =& $ipsclass;
$install->do_Install();

class Install
{
    var $output        = "";
    var $mysql_version = "";
    var $sql_data      = array();
    var $uninstalling  = false;
    var $ipsclass;

    function do_Install()
    {
        switch ($this->ipsclass->input['edit'])
        {
            default:
                $this->intro();
                break;
        }

        $this->print_it($this->output);
    }

    function intro()
    {
        if ( $this->ipsclass->member['id'] == 1) {
            $this->output .= "<p>Welcome {$this->ipsclass->member['members_display_name']}</p>";
          } else
        { $this->output .="<p>You cannot access this area</p>"; }
    }

    function print_it()
    {
        $this->ipsclass->print->add_output($this->output);
        $this->ipsclass->print->do_output( array( 'TITLE' => 'page title goes here', 'JS' => 0, NAV => 'nav data goes here' ) );
    }
}

?>


Line 93 on class_display is
CODE
        $this->ex_time  = sprintf( "%.4f",$Debug->endTimer() );
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2009 Invision Power Services, Inc.