2 smpdawg Jun 28, 2006 01:04

smpdawg wrote:
By any chance is that line within a function?
It looks like the variable $Blog is not defined for some reason. If it is within a function, you may want to add a line like this before the one that is causing the error.
global $Blog;
John, thanks for the reply. To simplify the analysis, I created a small file, test.php, that contains the following code:
<?php require(dirname(__FILE__).'/b2evocore/_main.php'); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="<?php locale_lang() ?>" lang="<?php locale_lang() ?>">
<head>
<?php
$blog = 2;
echo "Here's what I think \$blog is:", $blog;
$blog->get( 'blogurl', 'htmlattr' );
?>
</body>
</html>
When I point my browser to this page, I get:
Here's what I think $blog is:2
Fatal error: Call to a member function on a non-object in /home/lakeshor/public_html/blog/test.php on line 8
Since it prints out $blog=2, there appears not to be a problem with $blog being undefined.
Also, in case this matters (e.g., for require statement), test.php is at
http://lakeshoreneighbors.org/blog/test.php
Thanks in advance if this helps pin it down!
Jim
PHP is case-sensitive so the variable $blog and $Blog are two different things. $blog is the blog id as it is stored in the database. Whereas $Blog is a PHP object that has blog information and methods.
Based on your code snippet you would have been trying to call a method named get that is stored in the $blog variable. The problem is that $blog is an integer and not an object. The correct form should be this:
$Blog->get( 'blogurl', 'htmlattr' );
You can try doing this to see the contents of the $Blog object and that would also show you whether or not the object exists and is set. If you get nothing, it isn't set but if you see something you probably have the right object.
print_r($Blog);
BTW - I am using Phoenix so my advice can be skewed because that is all that I use.
Thanks, John. Being new to PHP and b2evolution, your comment helped a lot.
When, in the original problematic code, I included "print_r($Blog);", it just printed nothing (i.e., not even a space), so that makes me think that $Blog isn't defined here.
The bigger picture is that I'm calling this on a page which is NOT a blog page, but rather a page on which I want to display the most-recent post from each of several specified blogs.
Here's a compressed code fragment that shows what I'm trying to do:
$blog = 2;
$num_recent_posts = 1;
// Displays name of blog
<a href="<?php blog_list_iteminfo('blogurl', 'raw' ) ?>"><?php blog_list_iteminfo( 'name', 'htmlbody'); ?></a>
// Gets most-recent item of blog number $blog
<?php
$BlogBList = & new ItemList( $blog, '', '', $m, $w, '', array(), $author, 'DESC', '', $posts, '', '', '', '', '', '', '', $num_recent_posts, 'posts' );
while( $Item = $BlogBList->get_item() )
{?>
<?php $Item->content( 1, false, '', '', '', '' ); ?>
<?php link_pages() ?>
// Here's where the crash occurs:
<a href="<?php echo url_add_param( $Blog->get( 'blogurl', 'htmlattr' ), 'author='. $Item->Author->ID) ?>">
<?php $Item->Author->prefered_name(); ?> </a>
<?php } ?>
So what I was almost completely successful at doing was assigning $blog to the number of the blog I wanted to display (viz., 2), getting that blog's most-recent post, and displaying its content and displaying other information from that post.
This was working fine, until I tried getting the author's ID, in order to construct the URL for that author's blog, using
<?php echo url_add_param( $Blog->get( 'blogurl', 'htmlattr' ), 'author='. $Item->Author->ID) ?>
Is there a different way to get the URL for that author's blog?
Thanks!
Jim
By any chance is that line within a function?
It looks like the variable $Blog is not defined for some reason. If it is within a function, you may want to add a line like this before the one that is causing the error.
John