In your controller(s) add the following:
public function init() {
$this->view->setEscape('stripslashes');
}
Hi,
I may be making this more complex than it needs to be, but I'm setting up a model for a db table that stores a number of blobs that are basically going to be text entry. When I insert the data I iterate through the data array passed to the function and use the mysql_real_escape_string function to add slashes, then the update function in the class.
My problem is in retrieving the data and removing the slashes. Is there an easy way to iterate through a Zend_Db_Table_Row object. Currently I'm using this code, but it obviously doesn't work.
[PHP]public function getInfo($user_number) {
$userinfo = $this->fetchRow($this->select()
->where('user_number = ?', $user_number));
foreach($userinfo AS $k=>$v) {
$userinfo->$v = stripslashes($v);
}
return $userinfo;
}
[/PHP]
I was hoping to create a way to automatically run stripslashes on all returned values without needing to know the table fields and without using the toArray() function (which would mean I couldn't use the save() function when the user is done editing!). Thanks for any help!
In your controller(s) add the following:
public function init() {
$this->view->setEscape('stripslashes');
}
That's great! Thanks!
On a related note, I've been trying to find info about how to clean data going into the db on the server side (vs form validation) and if zf does any cleaning similar to mysql_real_escape_string() when using the save(), update(), or insert() functions or if i'd need to build that in to a class that my models extend. I may be overlooking a different conceptual perspective on this. Does anyone have any suggestions? I've been searching through forums and tutorials, etc for some data on thus but come up empty!
Zend_Validate and Zend_Filter and Zend_Form
I tried this method and then looked into the View Abstract.php setEscape() (in ZF version 1.9) function and realized that this replaces the default escape function completely (htmlspecialchars). It might be better to instead make your own escape function which chains the php functions you need and setEscape() to that.