Recent Topics

1 Jun 25, 2006 21:30    

On my non-yet-operational site, the root-level default.php displays the most-recent post from each blog. The separate page for each blog is served by a skin.

In the skin, I successfully display the author of each post as a link using

<a href="<?php echo url_add_param( $Blog->get( 'blogurl', 'htmlattr' ), 'author='. $Item->Author->ID) ?>" title="<?php echo T_('Browse all posts by this author'); ?>"><?php $Item->Author->prefered_name(); ?></a>

However, when I include this exact same code into default.php, I get "Call to a member function on a non-object in...."

More specifically, the problem seems to lie in the call

<?php $burl=$Blog->get( 'blogurl', 'htmlattr' ) ?>

because that generates the error when I include that in default.php, but not when I include that in my skin's _main.php.

Any ideas what the problem is?

Where can I find documentation about the "get()" function? I found a get() function in b2evocore/_class_blog.php, but this only has a single argument, so it doesn't help me understand what 'htmlattr' is doing.

I'm using b2evolution v0.9.0.12

You can see the error message and source at

http://lakeshoreneighbors.org/blog/defaultProblem.php

I don't know whether this could possibly matter, but in the _main.php for the skin "guardian", I changed the baseurl to point at blog-root rather than point inside the skin folder.

Thanks in advance for any insights!

Jim

2 Jun 28, 2006 01:04

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

3 Jun 28, 2006 04:35

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

4 Jun 28, 2006 04:50

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.

5 Jun 28, 2006 05:53

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


Form is loading...