開発メモ

開発用のメモです。

Cakephp + Bootstrap で ドロップダウンボタン

Helper

 public function dropDown($name, $links = array()) {
        return $this -> Html -> tag("div", join("", array(
            "",
            $this -> Form -> button("SELECTED MOVE <span class='caret'></span>", array(
                "",
                "class" => "btn btn-default dropdown-toggle",
                "id" => $name,
                "data-toggle" => "dropdown"
            )),
            $this -> Html -> nestedList($links, array(
                "class" => "dropdown-menu",
                "role" => "menu",
                "aria-labelledby" => $name
            ), array("role" => "presentation"))
        )), array("class" => "dropdown"));
    }

View

<?php echo $this -> FormAssist -> dropDown("link1", array(
                $this -> Html -> link("Users", array(
                    "plugins" => "admins",
                    "controller" => "users",
                    "action" => "index"
                ), array(
                    "role" => "menuitem",
                    "tabindex" => -1
                )),
                $this -> Html -> link("Addresses", array(
                    "plugins" => "admins",
                    "controller" => "addresses",
                    "action" => "index"
                ), array(
                    "role" => "menuitem",
                    "tabindex" => -1
                )),
            ));
 ?>
Twitter: @asahina_alice