예제 #1
0
 public function getErrorMessage($key, $field = null)
 {
     if (isset($this->messages) && isset($this->messages[$field][$key])) {
         $message = $this->messages[$field][$key];
     } else {
         if (isset($this->messages) && isset($this->messages[$key])) {
             $message = $this->messages[$key];
         } else {
             if (isset($this->defaultMessages[$key])) {
                 $message = $this->defaultMessages[$key];
             } else {
                 $message = cfirst($key);
             }
         }
     }
     if ($field) {
         $columns = $this->getTable()->getColumns();
         if (isset($columns[$field])) {
             $default = array('minlength' => null, 'range' => array(null, null));
             $column = array_merge($default, $columns[$field]);
             $message = str_replace('%length%', $column['minlength'], $message);
             $message = str_replace('%min%', $column['range'][0], $message);
             $message = str_replace('%max%', $column['range'][1], $message);
         }
     }
     return $message;
 }
예제 #2
0
 public static function humanize($string)
 {
     $string = InflectionComponent::unCamelCase($string);
     $string = preg_replace('/_|-/', ' ', $string);
     $string = preg_replace('/ {2,}/', ' ', $string);
     $string = cfirst($string);
     return $string;
 }
예제 #3
0
		if (!$this->Request()->post('id')) {
			FlashComponent::set('error', "Au moins un éléments doit être coché.");
			$this->redirect(array('action' => 'index'));
		} else {
		    $id = $this->Request()->post('id');
		}

		switch ($action) {
			case "delete":
                $Items = Doctrine::getTable('<?php 
echo $model;
?>
')
                            ->createQuery()
                            ->whereIn('id', $id)
                            ->execute();
				foreach ($Items as $Item) {
					$Item->delete();
				}
				FlashComponent::set('success', pluralize(count($id), "{<?php 
echo cfirst('{#Singular#}');
?>
|<?php 
echo cfirst('{#Plural#}');
?>
} effacé{#female#}{s}"));
			break;
		}
		$this->redirect(array('action' => 'index'));
	}
예제 #4
0
			<li><a class="sprite prefix home" href="[?= UrlComponent::path(array('action' => 'index')) ?]">Retour aux {#plural#}</a></li>
		</ul>

		[? $i=0; ?]
<? $fields = Doctrine::getTable($model)->getColumns(); ?>
		<table class="summary">
			<colgroup>
				<col style="width:20%">
				<col>
			</colgroup>
			<tbody>
<? foreach($fields as $field => $options) : ?>
<? if (!in_array($field, $exclude)) : ?>
				<tr class="[?= ++$i % 2 ? 'odd': 'even' ?]">
					<th scope="row"><?php 
echo cfirst(ThisGeneratorHelper::field($field, $mapping));
?>
</th>
					<td>[?= ${#Model#}['<?php 
echo $field;
?>
'] ?]</td>
				</tr>
<? endif ?>
<? endforeach ?>
			</tbody>
		</table>

		<div class="form">
		<form method="post" action="[?= UrlComponent::path(array('action' => 'delete'), ${#Model#}['id']) ?]">
			<input type="hidden" name="id" value="[?= ${#Model#}['id'] ?]">
예제 #5
0
	// Edit
	public function edit($id = null) {	
		if ($this->Request()->post('id')) {
			${#Model#} = Doctrine::getTable('<?php 
echo $model;
?>
')->find($this->Request()->post('id'));
			if (!${#Model#}) {
				FlashComponent::set('error', "Cet enregistrement n'existe pas.");
				$this->redirect(array('action' => 'index'));
			}
			${#Model#}->fromArray($this->Request()->post());
			if (${#Model#}->isValid()) {
				${#Model#}->save();
				FlashComponent::set('success', "<?php 
echo cfirst('{#Singular#}');
?>
 édité{#female#}.");
				$this->redirect(array('action' => 'index'));
			} else {
				$errors = ${#Model#}->getErrorStack();
				FlashComponent::set('error', "Le formulaire contient ".pluralize(count($errors), '{une|{#}} erreur{s}.'));
			}
		} else {
			${#Model#} = Doctrine::getTable('<?php 
echo $model;
?>
')->find($id);
			if (!${#Model#}) {
				FlashComponent::set('error', "Cet enregistrement n'existe pas.");
				$this->redirect(array('action' => 'index'));