How to Force a Method Call on a Property or Method of an Obj
Posted: Thu Jan 07, 2010 11:09 am
Here's the problem, I would like to use some form of automatic escaping of html entities. Right now I'm using Zend_View for my templates which means that the templates aren't compiled, and I'm assigning objects to the template and then retrieving values for output from those objects as either properties or methods.
Currently I'm escaping content as it goes into the database (default behavior for Zend_Filter_Input) however this creates issues with updating information because html entities that have been previously escaped as & become & etc. I could fix this but the current solution is flawed in that I really don't want to perform presentational transformations on the data when putting in it in the database, I'd rather do it only when rendering the view.
In my View (using Zend_View so the the view is an object), I make calls to object properties and methods to populate the template like so:
If I make it so that all property requests (like for 'user') go through __get() is there any way that I can catch the subsequent calls so that I can force a method call on the final outputted value? For example so that I could do automatic escaping of output.
As I see it right now, I either have to escape the input as it goes into the database or use compiled templates like Smarty does, or switch to assigning every variable to the View object so that it has direct control to force escaping before outputting the data, or use __get() within the model to escape the values if the template is being rendered; none of which is really optimal.
Currently I'm escaping content as it goes into the database (default behavior for Zend_Filter_Input) however this creates issues with updating information because html entities that have been previously escaped as & become & etc. I could fix this but the current solution is flawed in that I really don't want to perform presentational transformations on the data when putting in it in the database, I'd rather do it only when rendering the view.
In my View (using Zend_View so the the view is an object), I make calls to object properties and methods to populate the template like so:
Code: Select all
<?= $this->user->name ?> // Outputs John Doe
<br/>
<?= $this->user->getCompany()->name ?> // Outputs Acme
<br/>
<?= $this->method() ?> // Outputs foobarAs I see it right now, I either have to escape the input as it goes into the database or use compiled templates like Smarty does, or switch to assigning every variable to the View object so that it has direct control to force escaping before outputting the data, or use __get() within the model to escape the values if the template is being rendered; none of which is really optimal.