duancuan6466
duancuan6466
2016-01-30 06:53

cakephp:如何在我的下拉列表中显示默认值?

  • php

i want to display a default value like 'select category' insted of blanck space

here is my tables

category_tbls

  • id
  • cat_name

subcategory_tbls

  • id
  • category_tbls_id
  • sub_cat

Model Addcat.php

class Addcat extends AppModel
{
    public $name = 'category_tbls';
    public $hashMany = 'subcategory_tbls';
}

Model Subcat.php

class Subcat extends AppModel
{
    public $name = 'subcategory_tbls';
    public $belongsTo = 'category_tbls';
}

AdminController.php

public function subcat()
{
    $this->loadModel("Subcat");

    if($this->Subcat->save($this->request->data))
    {
        $this->Session->setFlash('Successully save your information!');
    }

    $this->loadModel("Addcat");
    $dt=$this->Addcat->find('list',array('fields'=>array('id','cat_name')));
    $this->set('drop',$dt);

view file is as bellow

subcat.ctp

<h2>Add Sub Category!</h2>
                    <form action="subcat" method="post">
                    <?php echo $this->Form->select('category_tbls_id',$drop);?>
                        <input type="text" name="sub_cat" placeholder="sub category name" required/>

                        <button type="submit" class="b1">Add Sub Category</button>
                    </form>
  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

1条回答