本文整理匯總了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;
}