phreeze
phreeze copied to clipboard
Custom page: JSON rendering works, HTML rendering does not
I am creating a page that will only show entries that match a value in the Serial column. I have already worked out how to pull the value from a GETvariable, so I set the value statically here to simplify the code. My issue is that when using RenderJSON, the output is what I expect, however just Render results in an error: "Array to string conversion in Controller.php at line 746".
Working code in IssueController.php:
public function customJSON()
{
require_once('Model/IssueCriteria.php');
$criteria = new IssueCriteria();
$criteria->Serial_Equals = 'S399373';
$issues = $this->Phreezer->Query('Issue',$criteria)->ToObjectArray();
foreach ($issues as $issue)
{
$this->Assign('Serial',$issue->Serial);
$this->Assign('action',$issue->Action);
$this->Assign('Date',$issue->Date);
}
$this->RenderJSON($issues);
}
See results at http://re-sources.nexeng.us/customJSON
Non working code in IssueController.php:
public function custom()
{
require_once('Model/IssueCriteria.php');
$criteria = new IssueCriteria();
$criteria->Serial_Equals = 'S399373';
$issues = $this->Phreezer->Query('Issue',$criteria)->ToObjectArray();
foreach ($issues as $issue)
{
$this->Assign('Serial',$issue->Serial);
$this->Assign('action',$issue->Action);
$this->Assign('Date',$issue->Date);
}
$this->Render($issues);
}
See results at http://re-sources.nexeng.us/custom
There may be a better way to set all of this up. I appreciate any help in advance!
This may just be a simple issue of not using Render() in the correct way... anyone have an idea?
I'd suggest using debug mode in chrome. It will display any javascript errors. Best of luck
the Render method expects the name of a View template file as its parameter, but in this case you are giving it an array.
You can just render an array as JSON if you like using:
$this->RenderJson($issues);
That would give you a REST endpoint.
If you are wanting to render html then you can call render with either no parameter (in which case phreeze will auto-detect the view file name) or give it a specific file name.