Twitter Bootstrap Plugin for CakePHP 3 with bundled less.php and less.js parsers, helpers and bake templates, translated to pt_BR, search, access control, tinymce, etc


Keywords
plugin, bootstrap, search, tinymce, cakephp, bcrypt, access control
License
MIT

Documentation

Customização do Bootstrap plugin for CakePHP 3.X

twbs-br

Isso é uma customização do excelente plugin do Òscar Casajuana em https://github.com/elboletaire/twbs-cake-plugin

Tradução para Português do Brasil e adição de element topmenu e vários outros bons recursos

License Latest Stable Version Total Downloads

This plugin includes both lessjs and less.php parsers and allows you to easilly deploy CakePHP applications with (Twitter) Bootstrap.

Since version 3.0.2 this plugin dropped its own helpers and components and added friendsofcake/bootstrap-ui as a composer requirement, so you will use all their classes instead.

It also contains bake templates that will help you starting twitter-bootstraped CakePHP webapps.

General Features

  • Parses less files using less.js and/or less.php.
  • LessHelper to easily parse files.
  • Bake templates.
  • Generic Bootstrap layout.
  • All the included utilities from BootstrapUI plugin.
  • Tradução para pt-BR
  • Element topmenu
  • Editor TinyMCE
  • Busca por vários campos e com paginação
  • Cripografia de senhas com Bcrypt
  • Controle de acesso com o componente Control
  • etc

Installation/Instalação

Resumo simplificado do original em inglês. Para ver o original completo em inglês acesse: https://github.com/elboletaire/twbs-cake-plugin

composer require ribafs/twbs-cake-plugin-br

Edite o config/bootstrap.php

E adicione ao final do arquivo a linha seguinte: Plugin::load('Bootstrap', ['bootstrap' => true]);

Carregando os Helpers:

Adicionar ao início da classe do src/Controller/AppController.php do seu aplicativo:

public $helpers = [
    'Less.Less', // required for parsing less files
    'BootstrapUI.Form',
    'BootstrapUI.Html',
    'BootstrapUI.Flash',
    'BootstrapUI.Paginator'
];

Carregando o Layout

Adicione ao início do método beforeRender() do AppController.php do seu aplicativo:

    $this->viewBuilder()->layout('Bootstrap.default');

Gerando o código com o plugin twbs-br:

cd aplicativo

bin/cake bake.bake all Groups --theme Bootstrap --force bin/cake bake.bake all Users --theme Bootstrap --force bin/cake bake.bake all Permissions --theme Bootstrap --force bin/cake bake.bake all Servidores --theme Bootstrap --force

Acesse pela web e verifique como ficou.

O primeiro acesso demora um pouco, pois ele está compilando o CSS e gerando os arquivos less, mas das próximas vezes será normal e até mais rápido.

Caso queira adicionar um novo layout, copiar o default e adicionar assim Um layout para os grupos administradores e outro para os demais:

Neste caso precisará duplicar o Bootstrap.layout para Bootstrap.admin E também duplicar o Template/Layout/default para Template/Layout/admin.ctp chamando o respectivo layout

public function beforeRender(Event $event)
{       
    if($loguser == 'super' || $loguser == 'admin'){
        $this->viewBuilder()->layout('Bootstrap.admin');
    }else{
        $this->viewBuilder()->layout('Bootstrap.default');
    }       
    ...
}

Acesse a pasta docs

Na pasta existe alguns pequenos arquivos com dicas e recursos. Leia o arquivo 1leiame.txt na pasta docs para implementar um aplicativo usando este plugin.

Para criar seu próprio layout veja a documentação abaixo em inglês:

Creating your own layout

Create a styles.less file on your webroot/less folder (also create that folder if it does not exist) containing this line:

@import '../bootstrap/less/bootstrap.less';

Finally, load the less file from your view or layout:

echo $this->Less->less('less/styles.less');

If you want to extend twitter bootstrap styles I recommend you to copy the bootstrap.less file to your less folder and customize it to your needs. For the variables.less create a custom-variables.less and load it just after variables.less in bootstrap.less file. Any variable defined in that file will overwrite the value defined in variables.less and your code won't break when updating (Twitter) Bootstrap.

If you'd like to see an example of this you can check the files included in webroot/less/cakephp specially made to extend the default CakePHP baked templates.

Utilities

This plugin "includes" the following utilities (all they come from other plugins):

A note about Bootstrap's FlashComponent

The old Bootstrap FlashComponent used to have a close option that allowed you to define whether the flash alert would have a close button or not.

With BootstrapUI FlashHelper this works different. It looks for an alert-dismissible class (which is set by default) and, if defined, will show the close button.

For disabling the close button for the current Flash alert you can do:

$this->Flash->{whatever}("Hello World", ['params' => ['class' => ['alert']]]);

// where {whatever} is any of the Bootstrap alert classes (danger, info, warning...)
$this->Flash->success("Hello World", ['params' => ['class' => ['alert']]]);

Note that the class param is defined as an array.

LessHelper

Used on your template or view to parse and load the compressed CSS.

The LessHelper is part of the less cakephp plugin. Check out all its details there.

Dependencies

Included dependencies

About versioning

This project started using the same versioning as CakePHP 3.X during its development stage. For this reason, I'll continue using this but reserving the latest version number for my versions.

This means that any version of this plugin with 3.0.X version number should be compatible with any CakePHP 3.0 version.

License

The MIT License (MIT)

Copyright 2013-2015 Òscar Casajuana (a.k.a. elboletaire)

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.