Help - Search - Members - Calendar
Full Version: error when sorting MTEntries by excerpt
Movable Type Community Forum > Other Product Discussion > Bugs and Odd Behavior
bluewater
MT::App::CMS=HASH(0x82ae878) Use of uninitialized value in string comparison (cmp) at lib/MT/Template/Context.pm line 664.

The Category section rebuild seems to go through. I just get this error repeating a zillion times underneath "Your Category pages have been rebuilt. View your site."

Does this look familiar to anyone???
RobNovak
I bet $1 that you spelled "excerpt" wrong in your sort_by= parameter.

It'd be nice if MT trapped that error, though, by checking if the sort_by parameter was valid.
bluewater
CODE
<MTArchiveList archive_type="Category">
<?
$cat = "<$MTArchiveTitle$>";
if (!strncmp($cat, $sortingCategory, $numchars))
{
print ('<h2>'.substr("<$MTArchiveCategory$>",$displayafterchars).'</br></h2>
<MTEntries sort_by="excerpt"><BLOCKQUOTE><h3><$MTEntryTitle$></h3></BLOCKQUOTE></MTEntries>');}
?>
</MTArchiveList>
<p>


rob, i wish you were right!!! even if it would've cost me a dollar. thanks a lot, though. apparently, that is not the problem. here is the trouble code. definitely related to the sort_by="excerpt" part b/c when i remove it the categories rebuild fine. i tried installing digest :: MD5 as suggested in another similar trouble post. it didn't solve the problem.
RobNovak
Didn't realize you had the tag in a PHP code block.

Line 664 in Context.pm is the sort command. Perl is complaining that one of the values passed to it is undefined (null). The only way I can duplicate that error is by putting an invalid value in the sort_by= parameter.

If PHP allows it (and I'm a little rusty), try putting your print output in a "here" doc with a single-quoted identifier to keep it from dereferencing.
stepan
If you let MT generate your excerpts, then your sort will not work correctly, anyway.

I'm not 100% sure, but it's possible that if you do not have an explicit excerpt for an entry, that field is not defined. MT generates if from the entry text for the MTEntryExcerpt tag, but it's note there for the sort. Even if it's just an empty string there would be nothing to sort on (but there shouldn't be a warning).
RobNovak
Actually, I tested that. Several ways.

Even if you let MT auto-generate the excerpts, sorting on that field functions properly. It's only when the sort_by value is invalid that I can duplicate the OP's error.
stepan
QUOTE (RobNovak @ Oct 14 2003, 06:25 PM)
Actually, I tested that.  Several ways.

Weird, I just tested it with MT 2.63 with autogenerated excerpts. Sorting using sort_by="excerpt" didn't do anything (as I suspected) but also didn't report any problems.

I looked at the code and noticed that the excerpt is generated in the "get_excerpt" method of the MT::Entry object. So if you have a list of entries in your context (and you do if it's inside an MTArchiveList tag), you can use sort_by="get_excerpt" to sort by the (generated) excerpt. Of course, it'll be case sensitive, but c'est la vie. If you want more fanciful sorting, you might want to do it at the PHP level.

BTW, this is what I tested with (I didn't have category archives set up, but it works the same way):
CODE
<MTArchiveList archive_type="Monthly">
<MTEntries sort_by="get_excerpt" sort_order="ascend">
<p>
<b><MTEntryID> <MTEntryTitle></b><br />
<MTEntryExcerpt>
</p>
</MTEntries>
<hr />
</MTArchiveList>
bluewater
SWEET! thank you both so much for responding to my desperate plea for help.

stephan, your suggestion to use

CODE
sort_by="get_excerpt"


instead of

CODE
sort_by="excerpt"


got rid of the error and the entries do seem to be sorting correctly by excerpt, regardless of whether or not an excerpt was specified. i'm not quite technical enough to understand why this works, but...

my final code ended up being

CODE
<MTArchiveList archive_type="Category">
<?
$cat = "<$MTArchiveTitle$>";
if (!strncmp($cat, $sortingCategory, $numchars))
{
print ('<h2>'.substr("<$MTArchiveCategory$>",$displayafterchars).'</br></h2>');

echo <<<STUFF
<MTEntries sort_by="get_excerpt" sort_order="descend"><BLOCKQUOTE><h3><$MTEntryTitle$></h3><$MTEntryExcerpt$> <MTDateHeader><span class="dateline">Last updated: <$MTEntryDate format="%x"$> | </span></MTDateHeader></BLOCKQUOTE></MTEntries>
STUFF;
}
?>
</MTArchiveList>


as i'm sure my code reflects, i am only just learning PHP. RobNovak, I did try out the here doc thing too, just for kicks.

thanks again to you both.
bluewater
also, i forgot to ask..

is there somewhere else that i should report this issue with sorting by excerpt?
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-2008 Invision Power Services, Inc.