Hey i trying to learn modx but i keep getting a 500 error when i use this:
$objQuery = $modx->db->query('SELECT `content` FROM `modx_site_content` WHERE `parent` = 13');
$output = '';
while ($row = $modx->db->getRow($objQuery)) {
$output .= '<p>' . $row['content'] . '</p>';
}
echo $output;
but i try it in modx evolution and it worked fine, so any ideas what could be? maybe a server thing!?
-
☆ A M B ☆
- 24,524 Posts
For one thing, there is no "db" object in Revo, so you have to re-write your queries.
For another, a snippet should never "echo" anything, it should be returned, as if the snippet were a function (which in a sense it is).
thanks, but so how would that query looks like in revo? :S
-
☆ A M B ☆
- 24,524 Posts
-
☆ A M B ☆
- 24,524 Posts
Sorry I wasn't more directly helpful, but I'm new at Revo myself and not too sure about this xPDO stuff yet. Mostly at this point I just know pretty much where to go to find out.
Here's how to do it in xPDO:
$q = $modx->newQuery(
'modResource', // <-- 'modResource' automatically goes to modx_site_content
array(
'parent'=>13 // <-- A simple array list of fields => values
)
);
$pages = $modx->getCollection('modResource', $q); // <-- This is the way to get a list of resources
$output = '';
foreach ($pages as $res) // <-- iterates through the array automatically
{ $output .= '<p>' . $res->getContent() . '</p>'; //<-- getContent() is a nice shortcut
}
return $output; // <-- echo should not be used.
Here's another (not necessarily better) way --- note the capital 'C' in 'Children:
<?php
$parent = $modx->getObject('modResource', 13);
$pages = $parent->getMany('Children');
$output = '';
foreach ($pages as $res) {
$output .= '<p>' . $res->getContent() . '</p>';
}
return $output;
Note that the 'content' field is the only one you get with getContent(). All other fields use get() for the field value:
$created = $res->get('createdon');
$published = $res->get('published');
$content = $res->get('content'); // it will work with content too.
------------------------------------------------------------------------------------------
PLEASE, PLEASE specify the version of MODX you are using.
MODX info for everyone:
http://bobsguides.com/modx.html
BTW, getContent() is the more correct method, as opposed to get('content'), unless you want the raw content of something you're *sure* is a modDocument object, because getContent() it will work correctly on static resources and Articles.
If you're sure it will be a modDocument, get('content') will be a little faster.
------------------------------------------------------------------------------------------
PLEASE, PLEASE specify the version of MODX you are using.
MODX info for everyone:
http://bobsguides.com/modx.html