This question probably has been asked and answered hundred of times but after analysing answers found in the forum I’m not even a bit closer to the answer (incorrectly searching?). That’s why I’m asking.
To make this short. I have a DB query in action that returns querying result in $rows array. This action is called via AJAX:
$sql = 'SELECT * FROM TABLE(LHTML.GetWynList('.$id.'))';
$connection = Yii::app()->db;
$command = $connection->createCommand($sql);
$dataReader = $command->query();
$rows = $dataReader->readAll();
print_r($rows); //Works fine
echo($this->renderPartial('_wynik_main', array('rows'=>$rows), TRUE)); //Does not work
If I use first approach (printing array with print_r) everything is fine -> AJAX result is inserted into proper part of main view.
But if I use second approach (attempt to put array into renderPartial and then return it), AJAX action returns empty string (or at least nothing is inserted to DIV that is supposed to hold AJAX request result).
Thanks for your effort in testing this for me, frantic! :]
The problem is that this is a very early stage of developing this part of my project (and my first attempt to use renderPartial in AJAX requests) therefore my view file, you’re asking for contains nothing more than just:
So there shouldn’t be any problem here.
Actually I was moving this line between controller and view to test that it works like a charm in first version, while it doesn’t in second one.
Thanks! Seems like a deeper problem, while I was assuming that I made some very obvious mistake.
I didn’t think about testing it with Firebug, because I assumed (maybe mistakenly) that, if it works with print_r then the problem is in Yii code itself, not in AJAX request. I’ll test it at my work (currently have no access to this project) and write here, if I get to any conclusions.
Problem solved, it was something, what we call a Czech mistake in Polish - a very simple, but yet hard to notice error. My view file is:
<pre><?php print_r($rows) ?></pre>
I was playing with surrounding it with echo for some minor tests and for that reason I had to add second parameter to print_r - TRUE - to force result to be returned instead of being printed. I then remove echo but forgot to remove that TRUE, resulting in function returning its result out into space.