Hi all!
I'm working on a project which uses several databases, 2 of them are
MS-SQL with wrong encoding. They are shared with other apps, so I
can't change the encoding on the database.
That's why i built 2 methods to switch data to utf8 and back:

/**
 * MS-SQL specific beforeSave
 *
 * @param $data array
 * @return array
 */
        function fromUtf8($data) {
                foreach($data as $key => $val) {
                        if(!is_array($val)) {
                                $val = trim($val);
                                $data[$key] = utf8_decode($val);
                        } else {
                                $data[$key] = $this->fromUtf8($val);
                        }
                }
                return $data;
        }

/**
 * MS-SQL specific afterFind
 *
 * @param $data array
 * @return array
 */
        function toUtf8($data) {
                foreach($data as $key => $val) {
                        if(!is_array($val)) {
                                $val = trim($val);
                                $data[$key] = utf8_encode($val);
                        } else {
                                $data[$key] = $this->toUtf8($val);
                        }
                }
                return $data;
        }

They reside in app_model.php and are called from the models which
access the specific db.

        function afterFind($results,$primary = false) {
                if($primary == true) {
                        $results = $this->toUtf8($results);
                }
        }


This works in most cases, but now I'm experiencing some odd issues:

// snippet from request_controller.php
$this->Request->contain('Adress','Contactperson');
$request = $this->Request->read(null, $id);
$request['Adress'] = $this->Request->toUtf8($request['Adress']);

1st: the last line of that snipped shouldn't be needed, because the
toUtf8 method is already called by Adress-Model


2nd: Contactperson is a table in the same db as Adress. Request
belongsTo Both. Although a query is run for Contactperson and returns
1 row, $request['Contactperson'] is empty...


I hope anybody can point me to the right direction, I'm really stuck.
If you need some more info just tell me...

Thanks in advance,

Michael

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

Reply via email to