Les dates avec cake

http://book.cakephp.org/2.0/fr/core-libraries/helpers/time.html

http://www.formation-cakephp.com/25/afficher-les-dates-en-francais

http://ch.php.net/manual/fr/function.setlocale.php http://php.net/manual/fr/function.strftime.php

Lors de l'édition dans cake, si on veut remplacer la date par la date courante:

commenter dans edit.ctp

	#echo $form->input('date');

et remplacer par:

		<label for="RemarqueDateMonth">Date</label>
 
<?
#begin radeff special: insert current date for update record
	$aujourdhui=date("Y-m-d h:i");
	$RemarqueDateMonth=date("m");
	$RemarqueDateDay=date("d");
	$RemarqueDateYear=date("Y");
	$RemarqueDateHour=date("H");
		$RemarqueDateHourAMPM=date("h");
 
	$RemarqueDateMin=date("i");
 
#echo $RemarqueDateDay; exit;

echo "<select name=\"data[Remarque][date][day]\" id=\"RemarqueDateDay\">";
 
$joursN=array("01","02","03","04","05","06","07","08","09","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24","25","26","27","28","29","30","31");
for($i=0;$i<31;$i++) {
echo "<option value=\"" .$joursN[$i] ."\"";
if($joursN[$i]==$RemarqueDateDay) {
echo " selected";
}
echo "\">" .$joursN[$i] ."</option>\n";
}
echo "</select>";
 
 
$moisN=array("01","02","03","04","05","06","07","08","09","10","11","12");
$moisL=array("Janvier","Février","Mars","Avril","Mai","Juin","Juillet","Août","Septembre","Octobre","Novembre","Décembre");
echo "-<select name=\"data[Remarque][date][month]\" id=\"RemarqueDateMonth\">";
 
for($i=0;$i<12;$i++) {
echo "<option value=\"" .$moisN[$i] ."\"";
if($RemarqueDateMonth==$moisN[$i]) {
echo " selected";
}
echo "\">" .$moisL[$i] ."</option>\n";
}
echo "</select>";
 
 
?>
 
-<select name="data[Remarque][date][year]" id="RemarqueDateYear">
<?
for($i=2000;$i<2012;$i++) {
echo "<option value=\"" .$i ."\"";
if($i==$RemarqueDateYear) {
echo " selected";
}
echo "\">" .$i ."</option>\n";
}
echo "</select>
 
 
<select name=\"data[Remarque][date][hour]\" id=\"RemarqueDateHour\">";
 
 
for($i=1;$i<13;$i++) {
if($i<10) {
$ajout="0";
}else{
$ajout="";
}
echo "<option value=\"" .$ajout.$i ."\"";
if($i==$ajout.$RemarqueDateHour) {
echo " selected";
}
echo "\">" .$i ."</option>\n";
}
 
?>
 
 
 
</select>:<select name="data[Remarque][date][min]" id="RemarqueDateMin">
 
 
<?
for($i=0;$i<60;$i++) {
if($i<10) {
$ajout="0";
}else{
$ajout="";
}
echo "<option value=\"" .$ajout.$i ."\"";
if($ajout.$i==$RemarqueDateMin) {
echo " selected";
}
echo "\">" .$ajout.$i ."</option>\n";
}
 
?>
 
</select> <select name="data[Remarque][date][meridian]" id="RemarqueDateMeridian">
 
<?
echo "<option value=\"am\""; 
if($RemarqueDateHourAMPM<12) {
echo " selected=\"selected\"";
}
echo ">am</option>";
 
echo "<option value=\"pm\""; 
if($RemarqueDateHourAMPM>11) {
echo " selected=\"selected\"";
}
echo ">pm</option>";
?>
</select>
</div>
<?
#end radeff special: insert current date for update record
  • info/cake_date_hours.txt
  • Dernière modification: 2018/07/18 09:45
  • par radeff