+ Reply to Thread
Results 1 to 5 of 5

Thread: Stripslashes from Zend_Db_Table_Row Object

  1. #1
    benxmy is offline Junior Member
    Join Date
    Jan 2009
    Location
    Somewhere outside Adirondack State Park, NY
    Posts
    4

    Default Stripslashes from Zend_Db_Table_Row Object

    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!

  2. #2
    Untitled No. 4 is offline Junior Member
    Join Date
    Jul 2008
    Posts
    28

    Default

    In your controller(s) add the following:

    public function init() {
    $this->view->setEscape('stripslashes');
    }

  3. #3
    benxmy is offline Junior Member
    Join Date
    Jan 2009
    Location
    Somewhere outside Adirondack State Park, NY
    Posts
    4

    Default

    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!

  4. #4
    Untitled No. 4 is offline Junior Member
    Join Date
    Jul 2008
    Posts
    28

    Default

    Zend_Validate and Zend_Filter and Zend_Form

  5. #5
    nosro is offline Junior Member
    Join Date
    Nov 2009
    Posts
    1

    Default

    Quote Originally Posted by Untitled No. 4 View Post
    In your controller(s) add the following:

    public function init() {
    $this->view->setEscape('stripslashes');
    }
    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.

+ Reply to Thread

Similar Threads

  1. Zend_Controller ->getParam('param') return [object Object]
    By sobert in forum General Q&A on Zend Framework
    Replies: 2
    Last Post: 07-20-2010, 12:34 PM
  2. Select object -> to sql
    By sing1ejack in forum General Q&A on Zend Framework
    Replies: 4
    Last Post: 07-19-2010, 06:48 AM
  3. Replies: 0
    Last Post: 02-27-2010, 08:56 PM
  4. need help with zend_Db_table_row
    By carrier24sg in forum General Q&A on Zend Framework
    Replies: 4
    Last Post: 08-13-2009, 10:34 AM
  5. need help with zend_Db_table_row
    By carrier24sg in forum Databases
    Replies: 1
    Last Post: 08-12-2009, 09:19 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts