Articles->Programmazione->Php->CakePhp->

How to include and use the jscalendar in Cakephp
(Error rendering Element: ads/ins_link_468_15)
Ok, I created this solution, to provide for Cakephp the most pratical Calendar, JsCalendar. I downloaded the file from the site and I placed them in the Vendor folder.
I create a component to manage the code to put in the view, without use the helper.
This is not a good rule of programming, but the time, dear, it is really something of really important, so if you want make better, I am glad.
The first you must make is to put all the file that you download from the site, in the two folders:
- 1) \app\webroot\js\jscalendar-1.0\ ==>all files
- 2) \vendors\jscalendar-1.0 ==>all files (attention vendors, in this case, is the first level folder of your CakeApp
- 3)You must go in your layout file and put this code to get the reference to the calendar
- 4)You must copy the cale.php in the folder \app\controllers\components
In your controller you must get reference to the component Calendar (Error rendering Element: ads/onlylink468_60)
-
5)In the method of your controller you must initialize the Calendar:
$this->Cale->initCalendar();
- 6) In every view that you want include the calendar, you must use this code:
<?
$calendarOptions = array(
'firstDay' => 1, // show Monday first
'showsTime' => true,
'showOthers' => true,
'ifFormat' => '%d-%m-%Y %H:%M',
'daFormat' => '%d-%m-%Y %H:%M',
'timeFormat' => '24',
'align' => 'cl'
);
$idfield="InputTest";
echo $html->input('Post/datebirth', array('id' => $idfield));
$field_attributes=array();
$Test2=$calendar->make_input_fieldVar($calendarOptions,$field_attributes,$idfield);
echo ($Test2 );
?>
Naturally, if you want you can use a global var, if you want use always the same options for the calendar. Notice that $calendarOptions is an array that contains the setting for the calendar to be showed. Read the documentation of Jscalendar for all the cool options.
The most important you must learn and pass is the var ,$idfield, that is the id of the html input field, because the calendar has as target it, when the user choices the date.
make_input_fieldVar is the function that I created in the file \vendors\jscalendar-1.0\calendar.php, and it creates a reference to the field of the form.
That’s all dears, now you can make every improvement to this, but sure, all is functionally for your scope.
You must also change the database setting in your database.php file.
Download all the code, the cakephp core is not included, so you must download cake from site. You must download 7zip reader to view the code, because with 7zip I gained 200% of size, and I must pay the server.
The demo is here. If you like this solution, you can vote our site, or you can discuss on the forum, subscribe it before. Good work!

How to include and use the jscalendar in Cakephp
Inserisci Annuncio Gratis
segnala sito
Postato da: Pierpaolo Romanelli
5 Comments +
- Why use a completely non standard zip? Rubbish.
H @ 2007-06-15 14:22:58 - Dear with 7zip you gain a lot of space, this is really good for all, also for you.
Admin @ 2007-06-16 10:13:16 - I get consufed here:
"3)You must go in your layout file and put this code to get the reference to the calendar"
what "layout file"? the one located in
/app/views/default.thtml
is that what you mean layout file? please explain more. thanks. i hope this works.
Aj Macaro @ 2007-08-30 10:33:02 - Hi, again. I got confused again:
"4)You must copy the cale.php in the folder \app\controllers\components"
Where is cale.php? do you mean calendar.php?
Aj Macaro @ 2007-08-30 10:48:18 - Hi again, sorry about that. I didnt download your
jscalendar.7z. there i found the "cale.php". further investigation need. i'll get back here once i make it working.
Aj Macaro @ 2007-08-30 12:28:47


























