josegonzalez / app
CakePHP skeleton app
Installs: 457
Dependents: 0
Suggesters: 0
Security: 0
Stars: 8
Watchers: 7
Forks: 7
Open Issues: 0
Type:project
Requires
- php: >=7.0
- ext-apcu: *
- ext-intl: *
- ext-mbstring: *
- ext-pcntl: *
- ext-pdo_mysql: *
- ext-pdo_pgsql: *
- ext-pdo_sqlite: *
- ext-redis: *
- cakephp/cakephp: 3.8.*
- cakephp/migrations: ^2.0.0
- cakephp/plugin-installer: ^1.0
- friendsofcake/bootstrap-ui: 1.*
- friendsofcake/crud: ^5.0
- friendsofcake/crud-view: 0.*
- friendsofcake/search: 5.*
- josegonzalez/cakephp-queuesadilla: 0.6.*
- josegonzalez/cakephp-upload: 4.*
- josegonzalez/cakephp-users: 0.*
- josegonzalez/dotenv: 3.*
- josegonzalez/php-error-handlers: 0.*
- josegonzalez/queuesadilla: *
- markstory/asset_compress: 3.*
- mobiledetect/mobiledetectlib: 2.*
Requires (Dev)
- cakephp/bake: ^1.9.0
- cakephp/cakephp-codesniffer: ^3.0
- cakephp/debug_kit: ^3.17.0
- josegonzalez/dotenv: 3.*
- phpunit/phpunit: ^5|^6
- psy/psysh: @stable
Suggests
- dereuromark/cakephp-ide-helper: After baking your code, this keeps your annotations in sync with the code evolving from there on for maximum IDE and PHPStan compatibility.
- markstory/asset_compress: An asset compression plugin which provides file concatenation and a flexible filter system for preprocessing and minification.
This package is auto-updated.
Last update: 2024-11-20 00:07:25 UTC
README
A fork of the official skeleton for creating applications with CakePHP 3.x. It should be more or less "batteries included".
Installation
- Download Composer or update
composer self-update
. - Run
php composer.phar create-project --prefer-dist josegonzalez/app [app_name]
.
If Composer is installed globally, run
composer create-project --prefer-dist josegonzalez/app [app_name]
In case you want to use a custom app dir name (e.g. /myapp/
):
composer create-project --prefer-dist josegonzalez/app myapp
You can now either use your machine's webserver to view the default home page, or start up the built-in webserver with:
bin/cake server -p 8765
Then visit http://localhost:8765
to see the welcome page.
Update
Since this skeleton is a starting point for your application and various files would have been modified as per your needs, there isn't a way to provide automated upgrades, so you have to do any updates manually.
Features
- New Installed Packages and Plugins
- Environment Variable Configuration
- Asset Compression
- Crud Defaults
- Customizing Bake
- Error Handling
- Heroku Support
- Queuing
Installed Packages and Plugins
The following is a list of CakePHP plugins that are installed and pre-configured:
- friendsofcake/bootstrap-ui
- friendsofcake/crud-users
- friendsofcake/crud-view
- friendsofcake/crud
- friendsofcake/search
- josegonzalez/cakephp-users
- josegonzalez/cakephp-upload
- josegonzalez/cakephp-queuesadilla
- markstory/asset_compress
The following is a list of PHP packages that are installed and pre-configured:
Configuration
By default, this skeleton will use josegonzalez/php-dotenv to load configuration from the following files:
config/app.php
config/.env
- if this file does not exist,
config/.env.default
- if this file does not exist,
For "global" configuration that does not change between environments, you should modify config/app.php
. As this file is ignored by default, you should also endeavor to add sane defaults to app.default.php
.
For configuration that varies between environments, you should modify the config/.env
file. This file is a bash-compatible file that contains export KEY_1=VALUE
statements. Underscores in keys are used to expand the key into a nested array, similar to how \Cake\Utility\Hash::expand()
works.
As a convenience, certain variables are remapped automatically by the config/env.php
file. You may add other paths at your leisure to this file.
Asset Compression
The markstory/asset_compress plugin is installed and enabled by default. It is used by the CrudView plugin, but does not currently have an integration with the default layout.
Crud Defaults
By default, the crud plugin has been enabled with all known customizations. Simply creating a controller will enable all CRUD-actions in the default RESTful api mode.
Note that we also default pagination sorting to the table's primaryKey
(if there is a single primaryKey
field).
Crud Users Defaults
The CrudUsers
plugin has been preconfigured for use with the Users
plugin. A migration is pre-created in the skeleton app, and can be run to initialize the plugin. Associated plugin migrations will also be run via:
composer run-script compile
See the Users plugin documentation for more information.
Crud View Defaults
Crud View is enabled for all admin-prefixed actions in the Application::beforeFilter
. You may also turn it on automatically for a controller by setting the controller's $isAdmin
property to true
.
Note that the scaffold.brand
is set to the constant APP_NAME
, which can be modified in your config/.env.default
or config/.env
files.
Customizing Bake
There now exists a config/bake_cli.php
. This file should contain all bake-related event handlers. It is used to speed up the re-bake process such that we don't need to go in and re-add customizations.
As an example, the following event handler will add the Josegonzalez/Upload.Upload
plugin to the Users.photo
field:
EventManager::instance()->on('Bake.beforeRender.Model.table', function (Event $event) { $view = $event->subject(); $name = Hash::get($view->viewVars, 'name', null); if ($name == 'Users') { $behaviors = Hash::normalize(Hash::get($view->viewVars, 'behaviors', [])); $behaviors['Josegonzalez/Upload.Upload'] = ['photo' => []]; $view->set('behaviors', $behaviors); } });
Please refer to the bake documentation for more details.
Error Handling
Custom error handlers that ship errors to external error tracking services are set via the josegonzalez/php-error-handers package. To configure one, you can add the following key configuration to your config/app.php
:
[ 'Error' => [ 'config' => [ 'handlers' => [ // configuring the BugsnagHandler via an env var 'BugsnagHandler' => [ 'apiKey' => env('BUGSNAG_APIKEY', null) ], ], ], ], ];
Then simply set the proper environment variable in your config/.env
or in your platform's configuration management tool.
Heroku Support
Heroku and other PaaS-software are supported by default. If deploying to Heroku, simply run the following and - assuming you have the proper remote configuration - everything should work as normal:
git push heroku master
Migrations for the core application will run by default. If you wish to run migrations for plugins, you will need to modify the key scripts.compile
in your composer.json
.
Queuing
Queuing support is provided through the Queuesadilla php package, with a CakePHP plugin providing integration.
You can start a queue off the jobs
mysql table:
# ensure everything is migrated and the jobs table exists bin/cake migrations migrate # default queue bin/cake queuesadilla # also the default queue bin/cake queuesadilla --queue default # some other queue bin/cake queuesadilla --queue some-other-default # use a different engine bin/cake queuesadilla --engine redis
You can customize the engine configuration under the Queuesadilla.engine
array in config/app.php
. At the moment, it defaults to a config compatible with your application's mysql database config.
Need to queue something up?
// assuming mysql engine use josegonzalez\Queuesadilla\Engine\MysqlEngine; use josegonzalez\Queuesadilla\Queue; // get the engine config: $config = Configure::read('Queuesadilla.engine'); // instantiate the things $engine = new MysqlEngine($config); $queue = new Queue($engine); // a function in the global scope function some_job($job) { var_dump($job->data()); } $queue->push('some_job', [ 'id' => 7, 'message' => 'hi' ]);
See here for more information on defining jobs.
Layout
The app skeleton uses a subset of Foundation (v5) CSS framework by default. You can, however, replace it with any other library or custom styles.