Jump to content

Recommended Posts

I am trying to learn smarty and OO Php by going through a sample application.  I have downloaded everything and setup libraries.  After I have instantiated my object, nothing displays.

 

I have set error_reporting(E_ALL);

 

In an effort to debug - I've put in the following echo statements in.

 

echo "before instantiating"; 

// create guestbook object 
$guestbook =& new Guestbook; 

$guestbook->sql->query("select * from guestbook", SQL_ALL); 
print_r($guestbook->sql->record);    
echo "after instantiating "; 

 

All that displays when I run this is :

 

Now when I run it, it only displays the following :

 

before instantiating

 

Please help

I am also new to OO php, so this could be something very basic that I'm overlooking.  I am not too sure why they use =& in the code to instantiate the object.  Below is the constructor for the guestbook class.

 

class Guestbook {
    public $testname = "testgbname";

// database object
    var $sql = null;
// smarty template object
    var $tpl = null;
// error messages
    var $error = null;
    
    /**
     * class constructor
     */
    function Guestbook() {

	// instantiate the sql object
        $this->sql =& new GuestBook_SQL;
	// instantiate the template object
        $this->tpl =& new Guestbook_Smarty;

\

 

and here is the Guestbook_SQL

 

class GuestBook_SQL extends SQL {
    function GuestBook_SQL() {
	    
        // dbtype://user:pass@host/dbname
        $dsn = "mysql://root:pass@localhost/guestbook";
       $this->connect($dsn) || die('could not connect to database');           		 
    }       
}

 

Please help, I have no idea where to go from here.  I also tried to access the $guestbook->testname  property, but that doesn't display anything either.

 

Thanks

Andi

Link to comment
https://forums.phpfreaks.com/topic/179058-no-output-after-object-instantiated/
Share on other sites

Use both of the following lines of code so that errors are both reported and displayed -

ini_set("display_errors", "1");
error_reporting(E_ALL);

 

On a development system, you should actually have these two settings in your master php.ini so that you don't need to put them into your files or remember to remove them when you put your finished code on a live server.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.