if ($form->isValid()){
$form->save();
}else {
echo $form->getErrorSchema()->getMessage();
}
$form->save();
}else {
echo $form->getErrorSchema()->getMessage();
}
Pero la mayor parte del tiempo, tu sitio web no estará disponible en los 136 principales idiomas. El métodoSí, pero si quieres hilar fino en tus aplicaciones pronto descubrirás que Symfony se queda corto con el métodogetPreferredCulture()devuelve el mejor lenguaje mediante la comparación de los idiomas preferidos del usuario y los idiomas de tu sitio web:
// in an action
$language = $request->getPreferredCulture(array('en', 'fr'));
getPreferredCulture():/** * Returns the preferred culture for the current request. * * @param array $cultures An array of ordered cultures available * * @return string The preferred culture */ public function getPreferredCulture(array $cultures = null) { $preferredCultures = $this->getLanguages(); if (null === $cultures) { return isset($preferredCultures[0]) ? $preferredCultures[0] : null; } if (!$preferredCultures) { return $cultures[0]; } $preferredCultures = array_values(array_intersect($preferredCultures, $cultures)); return isset($preferredCultures[0]) ? $preferredCultures[0] : $cultures[0]; }
/** * Makes the best choice of culture. It can check the domain of preferred * languages in order to choose a more generic language if it's available. * * Example: * * preferred cultures: es_ES, en * available cultures: es, en, fr * * In this example this method will return 'es' over 'en' as the best choice * if $checkCultureDomains flag is enabled. * * If no preferred culture is available this method will return the * $defaultCulture. * * @param array $availableCultures Array of valid available cultures * @param array $preferredCultures Array of preferred cultures. Order DOES matter (lower index => higher priority) * @param string $defaultCulture A default culture if none of the preferred cultures is available * @param bool $checkCultureDomains Flag to enable/disable language domain check * @return string best choice culture */ public static function bestChoiceCulture($availableCultures, $preferredCultures, $defaultCulture, $checkCultureDomains = true) { foreach ($preferredCultures as $culture) { if (in_array($culture, $availableCultures)) { return $culture; } if ($checkCultureDomains) { $domain = substr($culture, 0, 2); if ($domain != $culture && in_array($domain, $availableCultures)) { return $domain; } } } return $defaultCulture; }
lib/vendor/symfony/lib/plugins/sfDoctrinePlugin/data/generator/sfDoctrineModule/admin/template/templates/_list_td_actions.phpAnd modify the original code like this:
<td>
<?php if ($this->configuration->getValue('list.object_actions')): ?>
<ul class="sf_admin_td_actions">
<?php foreach ($this->configuration->getValue('list.object_actions') as $name => $params): ?>
<?php if ( isset( $params['condition'] ) ): ?>
[?php if ( <?php echo ( isset( $params['condition']['invert'] ) && $params['condition']['invert'] ? '!' : '') . '$' . $this->getSingularName( ) . '->' . $params['condition']['function'] ?>( <?php echo ( isset( $params['condition']['params'] ) ? $params['condition']['params'] : '' ) ?> ) ): ?]
<?php endif; ?>
<?php if ('_delete' == $name): ?>
<?php echo $this->addCredentialCondition('[?php echo $helper->linkToDelete($'.$this->getSingularName().', '.$this->asPhp($params).') ?]', $params) ?>
<?php elseif ('_edit' == $name): ?>
<?php echo $this->addCredentialCondition('[?php echo $helper->linkToEdit($'.$this->getSingularName().', '.$this->asPhp($params).') ?]', $params) ?>
<?php elseif ('_show' == $name): ?>
<?php echo $this->addCredentialCondition('[?php echo $helper->linkToShow($'.$this->getSingularName().', '.$this->asPhp($params).') ?]', $params) ?>
<?php else: ?>
<li class="sf_admin_action_<?php echo $params['class_suffix'] ?>">
<?php echo $this->addCredentialCondition($this->getLinkToAction($name, $params, true), $params) ?>
</li>
<?php endif; ?>
<?php if ( isset( $params['condition'] ) ): ?>
[?php endif; ?]
<?php endif; ?>
<?php endforeach; ?>
</ul>
<?php endif; ?>
</td>
actionName:
label: actionLabel
action: executeAction
#Now the enhancement =D
condition:
# function is the name of function in the model::functionName and must return boolean
function: functionName
# params are the params to send to functionName
params: "$model->getDbField(), $sf_user, 'test'"
# invert is used if you need invert the result of functionName
invert: false
lib/model/doctrine/model.class.php
/** * $param1 is $model->getDbField() * $param2 is $sf_user * $param3 is 'test' */ public function functionName($param1, $param2, $param3){ //code personal return boolean; }
php symfony cache:clear

string generateUrl('URL_ROUTE',
array(
'module'=>'MODULE_NAME',
'action'=>'ACTION_CALLED',
'PARAMS'=>'VALUE'
),
$isAbsolute
);
URL_ROUTE is the SEO Friendly URL pattern you defined in config file of module, if not defined use 'default' second is the config array in which we define module name and the action we want to call next is the parameter we want to pass via URL you can pass as many as you want params through it, in the form 'PARAM1'=>'VALUE1','PARAM2'=>'VALUE2',.... and last parameter is $isAbsolute it instruct whether we want relative or absolute URL, default is false it generate relative URL by default.$this->generateUrl('default',
array('module'=>'User','action'=>'EditUser','uid'=>$id))
the out will be something like this...backend_dev.php/User/EditUser/uid/1130hope it helps...