Friday, July 30, 2010

Re: Behavior afterFind not filtering data?

Ok, the problem appears to be that somewhere in the bowels of
CakePHP's Models, it doesn't seem to like certain characters and just
replaces them with "?"

I've discovered this because I'm attempting to run batches through the
Console. So, I'm only using a Shell script and the Model in question
and I'm definitely getting "?" where I should be getting ™. I've
verified that my database.php file is using 'encoding' => 'iso-8859-1'
and that my core.php shows Configure::write('App.encoding',
'iso-8859-1'); but neither of these two things is solving the problem.

Cricket: I've finally convinced people here to get rid of the blasted
weird characters and replace with HTML entities, but now the battle is
actually getting that done! Trying to use SQL Server's Import and
Export utility is at least as unsuccessful so far as doing it the
CakePHP way and for a variety of reasons, I'd prefer to go CakePHP.

Thanks to anyone who can help.

On Jul 22, 3:15 pm, DragonFlyEye <dragonflyey...@gmail.com> wrote:
> Not really. We're talking about thousands of products for a start. And
> I expect to have problems with data entry in the future, like cutting
> and pasting from Word. Plus there is some resistence to changing
> things around here that I've got to slowly overcome. In the meanwhile,
> I have to be able to show progress.
>
> The result I'm getting is exactly the same as the original query. IOW:
> as though the filtering isn't happening. I've intentionally put errors
> in the code to make sure that the Model that it's being declared in is
> correctly identifying the file, which it is. But even if I put in
> "return 'Bupkis'," I still get the same response.
>
> On Jul 22, 2:59 pm, cricket <zijn.digi...@gmail.com> wrote:
>
> > You haven't said what results you're seeing. Anyway, at a glance, I
> > can see one problem.
>
> > Sanitize::clean($results);
>
> > should be:
>
> > $results = Sanitize::clean($results);
>
> > But, wouldn't it be simpler to just write a script that cleans up the
> > DB once and forget about it?
>
> > On Thu, Jul 22, 2010 at 2:06 PM, DragonFlyEye <dragonflyey...@gmail.com> wrote:
> > > I'm sure I'm missing something silly, but I cannot get this Behavior
> > > to work. I've got data with a bunch of nasty characters in the
> > > database that I need to avoid or escape before presenting to the
> > > browser. Also, it's got a lot of white space at the end of much of the
> > > data because someone erroneously used the nchar datatype on the MS-SQL
> > > database I'm working off of. So this Behavior is just to be able to
> > > get rid of those problems going forward. Right now, I'm using it on
> > > the afterFind hook, but once I know it works safely I'll apply it to
> > > the beforeSave hook:
>
> > > <?php
> > > App::import('Sanitize');
> > > class TrimAndEscapeBehavior extends ModelBehavior {
> > >        var $errors             = array();
>
> > >        function afterFind(&$Model, $results, $primary) {
> > >                $results = $this->cleanText($results);
> > >                Sanitize::clean($results);
> > >                return $results;
> > >        }
>
> > >        /*
> > >        // cleanText:                   Recursive function trims text and removes illegal
> > > characters.
> > >        // @var mixed $data:    The data to inspect and clean.
> > >        // @data mixed $data:   The cleaned data.
> > >        */
> > >        function cleanText($results) {
> > >                // If this is an array, send it back through:
> > >                if(is_array($results)) :
> > >                        foreach($results as $key=>$value) :
> > >                                $results[$key]  = $this->cleanText($value);
> > >                        endforeach;
> > >                // We have a text node. Trim and escape:
> > >                else :
> > >                        // replace Trademarks:
> > >                        $results = str_replace(chr(8482), '<sup>&trade;</sup>', $results);
> > >                        // Replace Registered Trademarks
> > >                        $results = str_replace(chr(174), '<sup>&reg;</sup>', $results);
> > >                        // replace Trademarks:
> > >                        $results = str_replace('&#8482;', '<sup>&trade;</sup>', $results);
> > >                        // Replace Registered Trademarks
> > >                        $results = str_replace('&#174;', '<sup>&reg;</sup>', $results);
> > >                        // Trim content:
> > >                        $results = trim($results);
> > >                        return $results;
> > >                endif;
> > >        }
> > > }
> > > ?>
>
> > > Check out the new CakePHP Questions sitehttp://cakeqs.organdhelp others with their CakePHP related questions.
>
> > > You received this message because you are subscribed to the Google Groups "CakePHP" group.
> > > To post to this group, send email to cake-php@googlegroups.com
> > > To unsubscribe from this group, send email to
> > > cake-php+unsubscribe@googlegroups.com For more options, visit this group athttp://groups.google.com/group/cake-php?hl=en
>
>

Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions.

You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en

No comments: