views:

879

answers:

2

i am creating a calender prog, using cakephp when calling a method disp with month and year as params, it should disp the calender..

this my index.ctp//$month int 1 to 12 //$mon[12]=='December'

<?php echo $form->create('Calendar', array('action' => 'disp', 'class' => 'normal')); ?>
 <?php 
  echo $form->input('month', array('options' => $mon, 'empty'=>$mon[$month]));
  echo $form->input('year', array('options' => $yr, 'empty' => $year));
 ?>
<?php echo $form->end('Submit'); ?> 

month contains jan to dec and years 1990 to 2010

this is disp method

function disp()
 {
  $month= $this->data['Calendar']['month'];
  $year= $this->data['Calendar']['year'];
  $this->redirect(array('controller' => 'calendars', 'action' => 'index',$month,$year));
 }

when calling function it displays the calender perfectly my prob is the loaded month should select in drop down list by default it shows the first value i used 'empty'=>$mon[$month] this disp the month but duplicate..

what to do to select the month in the list, which was displaying at current??

A: 

Not quite sure if I got you correct. You want to display 2 select boxes containing the available months/years and preselect the current month/year?!

If so I would recommend using the select-function instead of input

$form->label('Calender.month', __('month', true));
$form->select('Calender.month', $mon, $month, array('class'=>'normal'), false);

http://api.cakephp.org/class/form-helper#method-FormHelperselect

harpax
yes, i got it bcaz of you..thank you so much harpax. :)
udhaya
A: 

You should use the built in date form elements

have a look at this

http://book.cakephp.org/view/204/Form-Element-Specific-Methods

echo $form->month('month');
echo $form->year('year');

or you can use

echo $form->dateTime('date');

and i think if you do something like this:-

echo $form->input('date',array('dateFormat' => 'MY'));

it should generate you two dropdowns.

cakephp tends to guess the data type of your fields. it does it by the name of your field for example if the field name is 'id' it will always generate a hidden field for it. cakephp also looks at the schema of your db and based on the data type it will generate you form elements. for a tinyint it will generate a checkbox. all you have to do if

$form->input('visible');

where visible is a tinyint field.

read more about automagic form elements

Yash