本文整理汇总了PHP中Propel::toTwig方法的典型用法代码示例。如果您正苦于以下问题:PHP Propel::toTwig方法的具体用法?PHP Propel::toTwig怎么用?PHP Propel::toTwig使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Propel
的用法示例。
在下文中一共展示了Propel::toTwig方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: toTwig
public static function toTwig(\BaseObject $obj, $checkToTwig = true, $includeRelated = true, $includeVirtual = true, $includeI18n = true)
{
if ($checkToTwig && method_exists($obj, 'toTwig')) {
return $obj->toTwig();
}
$tableMap = \PropelQuery::from(get_class($obj))->getTableMap();
$p = $obj->toArray(\BasePeer::TYPE_PHPNAME);
if ($includeRelated) {
foreach ($tableMap->getRelations() as $relation) {
if (in_array($relation->getType(), array(\RelationMap::ONE_TO_MANY, \RelationMap::MANY_TO_MANY))) {
$name = $relation->getPluralName();
$p[lcfirst($name)] = new OnDemand(function () use($obj, $name) {
return ArrayHelper::objectsToArray($obj->{'get' . $name}(), null, array('Curry\\Util\\Propel', 'toTwig'));
});
} else {
$name = $relation->getName();
$p[lcfirst($name)] = new OnDemand(function () use($obj, $name) {
$rel = $obj->{'get' . $name}();
return $rel ? Propel::toTwig($rel) : null;
});
}
}
}
// Automatic URL
$p['Url'] = new OnDemand(function () use($obj, $tableMap) {
$params = array();
foreach ($tableMap->getPrimaryKeys() as $pk) {
$params[$pk->getName()] = $obj->{'get' . $pk->getPhpName()}();
}
return url(L(get_class($obj) . 'Url'), $params);
});
// Virtual columns
if ($includeVirtual) {
$p = array_merge($p, $obj->getVirtualColumns());
}
// I18n behavior columns
if ($includeI18n && self::hasBehavior('i18n', $tableMap)) {
$translation = $obj->getCurrentTranslation();
$p = array_merge($p, $translation->toArray());
}
return $p;
}