Defining Bundles

Define bundles inside the application/configs/bundles.php file to make them accessible by any controller action.

<?php
    $bundles['datetimepicker'] = new Bundle(
        array(
            "public/js/eonasdan-bootstrap-datetimepicker/build/css/bootstrap-datetimepicker.min.css"
        ),
        array(
            "public/js/moment/min/moment-with-locales.min.js",
            "public/js/eonasdan-bootstrap-datetimepicker/build/js/bootstrap-datetimepicker.min.js"
        )
    );

    $bundles['knockout'] = new Bundle(
        array(
        ),
        array(
            "public/js/knockout/knockout-3.3.0.js",
            "public/js/knockout/knockout.mapping-2.4.1.js"
        )
    );

    $bundles['sweetalert'] = new Bundle(
        array(
            "public/js/sweetalert/dist/sweetalert.css"
        ),
        array(
            "public/js/sweetalert/dist/sweetalert.min.js"
        )
    );

Below is an example of a FakeController with an action that uses some bundles defined in the above sample file. Note that this controller is not actually part of this project and is used only for demonstration purposes.

<?php
    class FakeController extends FrontController
    {
        /**
         * @return View
         */
        public function addAction()
        {
            $this->view->title = "Add Person";

            $this->view->breadcrumbs = array(
                $this->route("Index") => "Home",
                $this->route("People", "list") => "List People",
                "" => "Add Person"
            );

            $this->view->addBundle("knockout")
                       ->addBundle("sweetalert")
                       ->addJavascript("public/js/people.add.js");

            return $this->view();
        }
    } /*end of class FakeController*/

One More Thing

Did you know that you can also add individual javascript or CSS files without using bundles?
Just use the $this->view->addJavascript(""); or $this->view->addCSS(""); methods instead.