0
我想在cakephp中使用本地化功能。在app_model.php中,我有一種獲取不同付款方式的方法。CakePHP使用Set ::與本地化結合
function getDistinctFields($model, $field)
{
$list = ClassRegistry::init($model)->find('all', array(
'fields'=>array("DISTINCT $model.$field"),
'conditions' => array('not' => array("$model.$field" => null))
));
debug($list);
$translated = "{n}.$model.$field";
$return = Set::combine($list, "{n}.$model.$field", __($translated, true));
return $return;
}
調試($表)的結果是這樣的:
[0] => Array
(
[InstantPaymentNotification] => Array
(
[payment_status] => Pending
)
)
[1] => Array
(
[InstantPaymentNotification] => Array
(
[payment_status] => Completed
)
)
[2] => Array
(
[InstantPaymentNotification] => Array
(
[payment_status] => Denied
)
)
[3] => Array
(
[InstantPaymentNotification] => Array
(
[payment_status] => Refunded
)
)
方法的輸出是這樣的:
> Array (
> [Pending] => Pending
> [Completed] => Completed
> [Denied] => Denied
> [Refunded] => Refunded
> [Reversed] => Reversed
> [Canceled_Reversal] => Canceled_Reversal)
一些好的,但價值不翻譯它應該是。我在正確的位置創建了default.po文件並進行了測試,以確定它是否適用於其他頁面。但是,它似乎不適用於Set類。
我重寫功能,而不剛剛使用foreach和工作原理。如果有人仍然可以找到如何使用Set :: combine來做到這一點,我希望聽到它,謝謝。 \t 功能getDistinctFields($模式,$場) \t { \t $名單= ClassRegistry ::初始化($模型) - >查找( '所有',陣列( \t '場'=>陣列(「DISTINCT $ (「$ model。$ field」=> null)) \t));}}; \t'conditions'=> array('not'=> array \t $ nicer = Set :: extract($ list,「{n}。$ model。$ field」); \t foreach($ nice as $ nice){ \t $ translated [$ nice] = __($ nice,true); \t} \t return $ translated; \t} – jimiyash 2009-10-06 02:03:57