{"id":18750707,"url":"https://github.com/webiny/bootstrap","last_synced_at":"2025-11-26T21:30:14.977Z","repository":{"id":27410187,"uuid":"30887090","full_name":"webiny/Bootstrap","owner":"webiny","description":"[READ-ONLY] PHP MVC bootstrap component for Webiny Framework. (master at Webiny/Framework)  http://www.webiny.com/ ","archived":false,"fork":false,"pushed_at":"2017-11-26T21:24:15.000Z","size":28,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-12-28T22:54:29.459Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/webiny.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-02-16T20:37:12.000Z","updated_at":"2023-05-21T17:35:17.000Z","dependencies_parsed_at":"2022-09-02T05:11:23.480Z","dependency_job_id":null,"html_url":"https://github.com/webiny/Bootstrap","commit_stats":null,"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/webiny%2FBootstrap","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/webiny%2FBootstrap/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/webiny%2FBootstrap/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/webiny%2FBootstrap/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/webiny","download_url":"https://codeload.github.com/webiny/Bootstrap/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239636253,"owners_count":19672314,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-07T17:12:51.704Z","updated_at":"2025-11-26T21:30:14.911Z","avatar_url":"https://github.com/webiny.png","language":"PHP","readme":"Bootstrap Component\n===================\n\nBootstrap is the first piece of code your web application runs. It loads all system components, and then runs your application.\nThe component uses MVC application architecture. **Note** that Webiny Framework is not an MVC framework, rather it's a set\nof modular components that you can use in various different application architectures, for example like HMVC and others.\n\nHowever, we decided to create this component, so that it helps other developers, that are mostly familiar with MVC, to\nuse Webiny Framework in their projects.\n\n\nInstall the Component\n---------------------\nThe best way to install the component is using Composer.\n\n\n```bash\ncomposer require webiny/bootstrap\n```\nFor additional versions of the package, visit the [Packagist page](https://packagist.org/packages/webiny/rest).\n\n\n## Requirements \n\nThe component requires that you follow a specific file-folder structure.\n \nA skeleton app can be found here [Bootstrap Skeleton App](http://github.com/Webiny/Bootstrap-SkeletonApp).\n\nA more advanced demo application can be found here [Bootstrap Todo Demo App](https://github.com/Webiny/Tutorial-TodoApp/).\n\n\n### Application Namespace\n\nOnce you have your structure in place, you need to set your desired application namespace inside the `Config/App.yaml` file.\n\n```yaml\nApplication:\n    Namespace: MySuperApp\n```\n\nThe `Namespace` defines the class root namespace for your module.\n\n\n### Modules\n\nEvery module is placed inside the `Modules` folder inside the skeleton app. The module name should be written in CamelCase, e.g. \"MySuperAwesomeModule\".\n\n```\nModules/\n    |- MySuperAwesomeModule/\n        |- Controllers/\n        |- Views/\n```\n\n\n### Controllers\n\nThe `Controllers` folder, which is inside your module folder, holds your controller classes. Controller name must also be written in CamelCase. Every controller class must `use` the `Webiny\\Component\\Bootstrap\\ApplicationTraits\\AppTrait` trait. \n\n```php\n\u003c?php\n\nnamespace MySuperApp\\Modules\\MySuperAwesomeModule\\Controllers;\n\nclass Homepage\n{\n    use Webiny\\Component\\Bootstrap\\ApplicationTraits\\AppTrait;\n\n    public function doSomethingAction()\n    {\n        // your code goes here\n    }\n}\n```\n\n#### `AppTrait`\n\nThe `AppTrait` gives you access to the `app` method, which then provides access to various helper methods.\n\n```php\nclass Homepage\n{\n    use Webiny\\Component\\Bootstrap\\ApplicationTraits\\AppTrait;\n\n    public function doSomethingAction()\n    {\n        // get absolute path\n        $this-\u003eapp()-\u003egetAbsolutePath();\n        \n        // get web path\n        $this-\u003eapp()-\u003egetWebPath();\n    \n        // assign data to the view\n        $viewData = [\n            'title' =\u003e 'This is a title'\n        ];\n        $this-\u003eapp()-\u003eview()-\u003eassign($viewData);\n    }\n}\n```\n\nThere are also couple of View helper methods:\n\n```php\nclass Homepage\n{\n    use Webiny\\Component\\Bootstrap\\ApplicationTraits\\AppTrait;\n\n    public function doSomethingAction()\n    {\n        $this-\u003eapp()-\u003eview()\n             -\u003esetTitle('Webiny Todo App')\n             -\u003esetMeta('description', 'Webiny demo Todo application')\n             -\u003eappendStyleSheet('//maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css')\n             -\u003eappendScript('//code.jquery.com/jquery-2.1.1.min.js')\n             -\u003eappendScript('//maxcdn.bootstrapcdn.com/bootstrap/3.3.1/js/bootstrap.min.js');\n    }\n}\n```\n\nThese setter methods, have also a getter pair, for outputting the result:\n\n```php\nclass Homepage\n{\n    use Webiny\\Component\\Bootstrap\\ApplicationTraits\\AppTrait;\n\n    public function doSomethingAction()\n    {\n        // outputs 'Webiny Todo App'\n        $this-\u003eapp()-\u003eview()-\u003egetTitle();\n        \n        // outputs '\u003ctitle\u003eWebiny Todo App\u003c/title\u003e' \n        $this-\u003eapp()-\u003eview()-\u003egetTitleHtml();\n        \n        // outputs an array of scripts\n        $this-\u003eapp()-\u003eview()-\u003egetScripts();\n        \n        // outputs a list of scripts as a HTML tags\n        $this-\u003eapp()-\u003eview()-\u003egetScriptsHtml();\n        \n        //...and few other, checkout the View.php class inside the ApplicationClasses folder\n    }\n}\n```\n\n#### Controller Actions\n\nEvery controller exposes certain public method that can be accessed over url. The method name of these methods must end\nwith `Action` keyword. Eg `doSomethingAction`.\n\n\n### Views\n\nEvery controller has it's own view folder, that holds the view templates for controller actions. The view folder name,\nmust match the controller class name.\n\n```\nModules/\n    |- MySuperAwesomeModule/\n        |- Controllers/\n            |- Homepage.php\n            |- ProductSearch.php\n        |- Views/\n            |- Homepage/\n                |- DoSomething.tpl\n```\n\nThe requirements for the view template name are:\n- written in CamelCase\n- must match the action name of the controller\n- should not contain `Action` at the end\n- example `Homepage/DoSomething.tpl` matches the `doSomethingAction` method on the `Homepage` controller.\n\nBy default, the Bootstrap component uses the [TemplateEngine](../TemplateEngine/) component, which uses `Smarty` template engine.\n\n\n## Environments and Configuration Files\n\nWithin the `Config` folder, you have the `Production` folder, which must always exist. This is the location from where \nthe component reads the configuration files. However, you can have additional folders, alongside the production one, that \n hold environment-specific configurations. The `Production` config files are **always** loaded, the additional env-specific\n config files, just overwrite the production config variables. \n\nTo create an environment, you need to first define it inside the `Config/App.yaml` config file:\n\n```yaml\nApplication:\n    Namespace: MySuperAwesomeModule\n    Environments:\n        Production:\n            ErrorReporting: off\n        Development:\n            Domain: http://www.myapp.local/\n            ErrorReporting: on\n            SomeCustomVar: varValue\n```\n \nThe `Domain` parameter defines when a certain environment will be loaded. The environment name, defines the folder that\nwill hold the configuration files. You can have as many environments as you want. \n\nIf the `Domain`, for the upper example, matches the current hostname, the component will first load all the config files,\nfrom the `Production` folder, and then all the files from the `Development` folder, and then it will merge both configurations\ninto one. \n\n```\nConfig/\n    |- Production/\n        |- Router.yaml\n        |- Mongo.yaml\n    |- Development/\n        |- Mongo.yaml \n```\n\n\n### System Configurations\n\nAlmost every component within Webiny Framework, takes a configuration file. That file defines the initial component data,\nand how the component should be constructed. \n\nThe `Bootstrap` component handles this initialization process automatically. If you create a configuration file, with a \nname matching a Webiny Framework component, the component will be initialized upon the application boot time and will\n be immediately available for usage in your application code. \n\n\nCheckout the `Config` folder inside the [Bootstrap Todo Demo App](https://github.com/Webiny/Tutorial-TodoApp/tree/master/src/App/Config/Production).\n\n## Routing\n\nBy default the component uses standard MVC routing. For example, a request looking like this:\n`www.myapp.com/HelloWorld/Foo/sayHi/` would match the following:\n- `HelloWorld`: module name\n- `Foo`: controller name\n- `sayHiAction`: method name\n\nThe upper url, can also we written in lowercase with hyphens `www.myapp.com/hello-world/foo/say-hi/`. This would match\nthe same module-controller-action. \n\n### Custom Routes\n\nTo define custom routes, just create a `Router.yaml` config file, inside your environment. This file should follow the\n[Router Component](../Router/) setup. The Bootstrap component will automatically pick up all the defined routes\nand do the matching. If a custom route is not matched, Bootstrap will do a fall-back to the default MVC router.\n\nThis is an example how a custom route should be defined.\n\n```yaml\nRouter:\n    Routes:\n        StartPage:\n            Path: /\n            Callback:\n                Class: Demo\\Modules\\StaticPages\\Controllers\\Homepage\n                Method: displayHomepage\n```\n\n\n### Passing Parameters\n\nIf an action method, takes one or more parameters, you can pass them inside the url path.\n\nFor example, let's say you have the following action method:\n\n```php\npublic function sayHiAction($name, $location='Planet Earth')\n{\n    echo 'Hi '.$name.', from '.$location;    \n}\n```\n\nYou can pass the parameters like this: `www.myapp.com/hello-world/foo/say-hi/Jack/`, which would output: \n\n`Hi Jack, from Planet Earth`\n\nor like this: `www.myapp.com/hello-world/foo/say-hi/Jack/Hawaii`, which would output:\n\n`Hi Jack, from Hawaii`\n\n\nResources\n---------\n\nTo run unit tests, you need to use the following command:\n\n    $ cd path/to/Webiny/Component/Bootstrap/\n    $ composer.phar install\n    $ phpunit\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwebiny%2Fbootstrap","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwebiny%2Fbootstrap","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwebiny%2Fbootstrap/lists"}