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