cakephp:如何在default.ctp中添加dropdownlist?

cakephp:如何在default.ctp中添加dropdownlist?,php,mysql,database,cakephp,Php,Mysql,Database,Cakephp,在default.ctp中,我想添加两个下拉列表。 一个是2010年至2020年的年度清单,另一个是1月至12月的月份清单 我该怎么做 我必须为此创建表单吗?像 echo $this->Form->create... echo $this->Form->end.. 或者我可以添加两个下拉列表和一个搜索按钮吗 如果我点击“搜索”按钮,它将转到posts/archive操作,并在posts表的“created”列中显示那些带有“year-month”的posts 有人可以发

在default.ctp中,我想添加两个下拉列表。 一个是2010年至2020年的年度清单,另一个是1月至12月的月份清单

我该怎么做

我必须为此创建表单吗?像

echo $this->Form->create...
echo $this->Form->end..
或者我可以添加两个下拉列表和一个搜索按钮吗

如果我点击“搜索”按钮,它将转到posts/archive操作,并在posts表的“created”列中显示那些带有“year-month”的posts

有人可以发布这个的示例代码吗

这就是我迄今为止所尝试的: $listyear=array()

对于($i=2010;$i‘一月’,
2=>‘二月’,
3=>“三月”,
4=>“四月”,
5=>“五月”,
6=>六月,
7=>七月,
8=>“八月”,
9=>9月,
10=>“十月”,
11=>11月,
12=>‘12月’;
echo$this->Form->create('Post',array('url'=>array('controller'=>'posts','action'=>'listcarve'));
echo$this->Form->input('Select year',数组('type'=>'Select','options'=>$listyear));
echo$this->Form->input('Select month',数组('type'=>Select','options'=>$months));
echo$this->Form->end('Search');

是的,您需要创建一个表单(或者使用JavaScript,但是普通的HTML表单更容易、更可靠)。您可以使用
Form::year()
为年份和月份创建下拉列表

如果您在创建表单时遇到问题,最好是发布您尝试过的内容并提出具体问题。烹饪书()中涵盖了相当广泛的形式

看到代码后编辑:您可以这样做,让Cake完成工作:

echo $form->create( 'Post', array( /* whatever you need */ ) );
echo $form->year( 'year', 2010, 2020 );
echo $form->month( 'month' );
echo $form->end( 'Search' );

好吧,如果它起作用,它是正确的;)看起来你正在做很多蛋糕可以自动完成的事情。请参阅编辑后的答案。在posts表中没有名为“年”或“月”的列,这有问题吗?我必须得到值数据['Post']['year']和数据['Post']['month'],然后比较posts表的'created'列,这就是全部,这不是问题。您可以在控制器中使用所需的任何逻辑。
echo $form->create( 'Post', array( /* whatever you need */ ) );
echo $form->year( 'year', 2010, 2020 );
echo $form->month( 'month' );
echo $form->end( 'Search' );