Hi,
I’m missing something here, I have this binding in a TV datagrid widget
@EVAL $modx->runSnippet("doit");
with the snippet being :-
<?php
global $modx;
$sql = "SELECT id,pagetitle FROM modx_site_content";
$result = $modx->db->query($sql);
return $result;
?>
OK, if I do this as an @SELECT ie ’@SELECT id.pagetitle from modx_site_content’ it works in the datagrid, ie I get the two columns formatted correctly as I want, the @EVAL however doesnt work, it always produces no output even though it returns a resultset which I assume the @SELECT is doing. I know the snippet is being called.
What am I missing here?
Use MODx, or the cat gets it!
-
MODX Staff
- 10,725 Posts
You are returning a MySQL result set resource; snippets must return strings.
Thanks for the reply.
OK, I thought thats what the datagrid widget wanted a resultset(or an array I believe). Looking at the code for the SELECT binding it seems to return a resultset to its caller. But Ok, are you saying I should parse the result set into rows and return them as a string? How then would the datagrid widget format this into columns? Also I thought a snippet could return anything?
I’ve got more time today to go through the datagrid widget code, I’ll have alook and see what it needs, then see how I can do this.
Actually the real prob I’ve got here is that I want the datagrid TV to have a different WHERE clause when invoked, I dont mind using SELECT to do this but how do you dynamically bind a WHERE clause to it?
Use MODx, or the cat gets it!
Ok,
If you write the EVAL binding like this the datagrid works ’global $modx;$rs=$modx->db->query("select id,pagetitle from modx_site_content");return $rs; ’ Note it is all on one line, NO line breaks, if you line break after say ’global $modx;’ it will only evaluate up to it and no further, only the string up to the line break gets EVAL’d so you don’t get the resultset back.
Ok, this bit solved but still not what I want.
The EVAL binding simply does an eval() on its input string and returns the result, if you give this a runSnippet() the nesting becomes horrible,
as this also eventually evals() the snippet, the return path becomes ’lost’ somehow with the resource return not being seen correctly by the datagrid widget.
I’ve tried using @CHUNK with the chunk containing an @EVAL with placeholders eg WHERE id=[+number+], however I cant get the placeholders to substitute in the chunk, even when set by calling a snippet to do this. The DBASE and PREFIX placeholders work but they are done inline in the code for the SELECT binding in tmplvars.commands.inc.php.
So, this wont do what I want as I still cant dynamically generate the WHERE clause, OK, i’ll do it by using s snippet to update the tmplvar table so the TV has the SELECT binding I want before invoking it, bit underhand but it works OK.
Been interesting looking at this, bet someones now going to say ’’ why dont you just do this......", OK if it works I will!
Use MODx, or the cat gets it!