Coder Social home page Coder Social logo

davidyell / cakephp-niceadminbakescripts Goto Github PK

View Code? Open in Web Editor NEW
14.0 3.0 6.0 61 KB

Nice Admin bake theme for CakePHPs Bake plugin.

License: Other

PHP 79.18% CSS 20.82%
cakephp cakephp3 bake-theme twitter-bootstrap cakephp-bake bootstrap-ui

cakephp-niceadminbakescripts's Introduction

Nice Admin Bake Theme

A custom theme using Twitter Bootstrap to bake admin templates in CakePHP 3, using the CakePHP Bake plugin.

Requirements

  • CakePHP 3
  • PHP 5.6+

What is it?

This is a theme for the CakePHP/Bake plugin which will customise the code which is generated. I've made it because I don't like the default bake theme, or the fact that it outputs the actions sidebar.

Plus I tend to use Twitter Bootstrap to make my admin areas so this theme will leverage that front-end framework.

Installation

You should install this plugin into your CakePHP application using composer.

The recommended way to install composer packages is using,

composer require davidyell/nice-admin-bake-scripts

Setup

In your config/bootstrap.php you'll need to load the plugin with Plugin::load('NiceAdminBakeTheme');

In your admin layout, you'll need to include the theme and javascript if you're using Twitter Bootstrap. This snippet also includes jQuery, so if you've already loaded that, please remove that line.

// In the head of your layout
<?= $this->Html->css([
    '//maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css',
    '//maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap-theme.min.css'
]) ?>

// Before your script block
<?= $this->Html->script([
    '//ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js',
    '//maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js'
]);?>

Optional extras

If you want to use Twitter Bootstrap for all your forms be sure to enable friendsofcake/bootstrap-UI in your application and loading the helpers in your src/View/AppView.php. Find out more about installing bootstrap-ui in their readme.

This can be easily coupled with the friendsofcake/crud plugin to pretty much make an entire basic admin in around 5 minutes!

A basic stylesheet is included to fix some minor things. You can symlink the stylesheet into your own webroot/css and include it from there, using

$ bin/cake plugin assets symlink NiceAdminBakeTheme

Of if you want to create the link manually cd webroot/css && ln -s ../../vendor/davidyell/nice-admin-bake-scripts/webroot/css/nice-admin.css.

Baking

The theme should be available when you are baking. You can check this by just running a bake command with -h and checking the available themes listed in the --theme option help. If you don't see it make sure you've loaded the plugin.

Controllers

bin/cake bake controller --theme=NiceAdminBakeTheme Examples

Templates

bin/cake bake template --theme=NiceAdminBakeTheme Examples

Prefixed templates

bin/cake bake template --theme=NiceAdminBakeTheme --prefix=Admin Examples

Example layout, elements and dashboard

A basic admin layout, dashboard and navigation elements are included in the plugin. Which you can symlink, extend, or copy into your project as you see fit.

If you want to link to the styles. echo $this->Html->css(['nice-admin']);

However it's preferable to use a symlink.

$ bin/cake plugin assets symlink NiceAdminBakeTheme

โš ๏ธ These elements are optional, and do not provide a completed admin. You will need to customise this to suit your needs.

Changes to standard bake

  • Removed the _serialize from the controllers
  • Removed the actions sidebar from all templates
  • Formatted tables with Bootstrap
  • Added a 'New' button to the top of tables
  • Add basic filter form to index templates
  • Tidied up the pagination
  • Made the Actions column links into buttons
  • Added handling for date, datetime and time using the Time helper
  • Added handling for boolean data using Bootstrap icons
  • Updated the View template to use Bootstrap panels
  • Spaced out the Table definition functions
  • Added classes to the columns in index templates
  • Lists are now ordered
  • Index pagination is done with a query

License

See license.md

cakephp-niceadminbakescripts's People

Contributors

davidyell avatar ogrrd avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

cakephp-niceadminbakescripts's Issues

Create an install shell

I wonder if the plugin can have an install shell, or script in composer which automatically symlinks the stylesheets?

$ bin/cake plugin assets symlink NiceAdminBakeTheme

Table 'dbpo.examples' doesn't exist

Where is sql our how to I create a table db.examples ?

bin/cake bake template --theme=NiceAdminBakeTheme Examples
Exception: SQLSTATE[42S02]: Base table or view not found: 1146 Table **'db.examples' doesn't exist** in [/www/app/vendor/cakephp/cakephp/src/Database/Schema/Collection.php, line 131]

bin/cake bake template --theme=NiceAdminBakeTheme --prefix=Admin Examples
Exception: SQLSTATE[42S02]: Base table or view not found: 1146 Table **'db.examples' doesn't exist** in [/www/app/vendor/cakephp/cakephp/src/Database/Schema/Collection.php, line 131]

Include timezone in datetime outputs

When outputting a datetime string it should be customised to the timezone and locale.

$entity->get('modified')->nice('Europe/London', 'en_GB');
$entity->get('modified')->timeAgoInWords(['timezone' => 'Europe/London']);

Missing ]

Thank you for your plugin. Very good.

Missing ] continue

See:
bin/cake bake controller --theme=NiceAdminBakeTheme Customers

Baking controller class for Customers...

Creating file /backup/www/cake/cake3theme/src/Controller/CustomersController.php
Wrote /backup/www/cake/cake3theme/src/Controller/CustomersController.php
Exception: syntax error, unexpected ')', expecting ']' in [/backup/www/cake/cake3theme/src/Controller/CustomersController.php, line 25]
2019-06-07 16:32:04 Error: [ParseError] syntax error, unexpected ')', expecting ']' in /backup/www/cake/cake3theme/src/Controller/CustomersController.php on line 25

3.x version

It would be worth creating a version of the bake script for the 3.x version of the framework. Especially as by default it bakes using the paginate() shortcut method in the controller which is a bit dirty imho.

Views detect field type

Allow views to detect field type and automatically use the Boolean helper.

$this->Boolean->display($data['Model']['field'])

Templae bake

In
src/Template/Bake/Element/Controller/index.ctp

Correct is:
$this->set('<%= $pluralName %>', $this->paginate($query, [
'order' => [$this-><%= $currentModelName %>->aliasField('modified') => 'desc']
]));
Your code are withiut ].
Thank you.

Behaviour detection

Make views aware of Behaviours such as SoftDelete to make button display conditional.

As I have purge and deleted buttons, it makes sense that they should not be included if the SoftDelete behaviour isn't attached to the model. Could also be removed if the Utils plugin isn't installed at all.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.