-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
added admin user to migrations and read me, reformatted to PSR-1/PSR-2 #3
base: rewrite
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,9 @@ The recommended way to install composer packages is: | |
|
||
``` | ||
$ composer require bakkerij/cakeadmin:dev-rewrite | ||
$ composer require friendsofcake/crud:^4.3 | ||
$ composer require gourmet/knp-menu:~0.4 | ||
$ composer require holt59/cakephp3-bootstrap-helpers:dev-master | ||
``` | ||
|
||
## Load Plugin | ||
|
@@ -34,3 +37,7 @@ Navigate to the new project's config/app.php and update your Datasources usernam | |
$ bin/cake migrations migrate -p Bakkerij/CakeAdmin | ||
``` | ||
|
||
After migrations you will have a default Admin user with the following credentials: | ||
email - [email protected] | ||
password - test | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,53 @@ | ||
<?php | ||
use Migrations\AbstractMigration; | ||
|
||
class Initial extends AbstractMigration | ||
{ | ||
use Migrations\AbstractMigration; | ||
|
||
class Initial extends AbstractMigration { | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we have a standard according to brackets There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I just used NetBeans auto format There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. CakePHP has its own standard: http://book.cakephp.org/3.0/en/intro/conventions.html You can validate your code using: https://github.com/cakephp/cakephp-codesniffer It might be a good idea to follow those standards and conventions... Probably there is a plugin for Netbeans to auto format to CakePHP's conventions, else you should do it manually (http://blog.bobbyallen.me/2013/03/24/configuring-netbeans-for-psr-1-and-psr-2-coding-guidelines/). |
||
/** | ||
* Change Method. | ||
* | ||
* More information on this method is available here: | ||
* http://docs.phinx.org/en/latest/migrations.html#the-change-method | ||
* @return void | ||
*/ | ||
public function change() | ||
{ | ||
$table = $this->table('cakeadmin_administrators', ['id' => false, 'primary_key' => ['id']]); | ||
$table | ||
->addColumn('id', 'uuid', [ | ||
'default' => null, | ||
'limit' => null, | ||
'null' => false, | ||
]) | ||
->addColumn('name', 'string', [ | ||
'default' => null, | ||
'limit' => 150, | ||
'null' => false, | ||
]) | ||
->addColumn('email', 'string', [ | ||
'default' => null, | ||
'limit' => 50, | ||
'null' => true, | ||
]) | ||
->addColumn('password', 'string', [ | ||
'default' => null, | ||
'limit' => 255, | ||
'null' => true, | ||
]) | ||
->addColumn('active', 'integer', [ | ||
'default' => 0, | ||
'limit' => 1, | ||
'null' => true, | ||
]) | ||
->addColumn('request_key', 'string', [ | ||
'default' => null, | ||
'limit' => 255, | ||
'null' => true, | ||
]) | ||
->addColumn('created', 'datetime') | ||
->addColumn('modified', 'datetime') | ||
->create(); | ||
public function change() { | ||
$table = $this->table('cakeadmin_administrators', ['id' => false, 'primary_key' => ['id']]); | ||
$table | ||
->addColumn('id', 'uuid', [ | ||
'default' => null, | ||
'limit' => null, | ||
'null' => false, | ||
]) | ||
->addColumn('name', 'string', [ | ||
'default' => null, | ||
'limit' => 150, | ||
'null' => false, | ||
]) | ||
->addColumn('email', 'string', [ | ||
'default' => null, | ||
'limit' => 50, | ||
'null' => true, | ||
]) | ||
->addColumn('password', 'string', [ | ||
'default' => null, | ||
'limit' => 255, | ||
'null' => true, | ||
]) | ||
->addColumn('active', 'integer', [ | ||
'default' => 0, | ||
'limit' => 1, | ||
'null' => true, | ||
]) | ||
->addColumn('request_key', 'string', [ | ||
'default' => null, | ||
'limit' => 255, | ||
'null' => true, | ||
]) | ||
->addColumn('created', 'datetime') | ||
->addColumn('modified', 'datetime') | ||
->create(); | ||
} | ||
} | ||
|
||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
use Cake\ORM\TableRegistry; | ||
use Migrations\AbstractMigration; | ||
|
||
class AddAdminUser extends AbstractMigration | ||
{ | ||
/** | ||
* Change Method. | ||
* | ||
* More information on this method is available here: | ||
* http://docs.phinx.org/en/latest/migrations.html#the-change-method | ||
* @return void | ||
*/ | ||
public function change() | ||
{ | ||
$AdminTable = TableRegistry::get('Bakkerij/CakeAdmin.Administrators'); | ||
$user = $AdminTable->newEntity([ | ||
'name' => 'admin', | ||
'email' => '[email protected]', | ||
'password' => 'test', | ||
'active' => 1 | ||
]); | ||
$AdminTable->save($user); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using a seed would be cleaner, but personally I prefer a shell to create an user yourself... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree a shell would be the final solution but this can get us up and testing very quickly until the shell has been created There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So let's accept this as a quick dirty solution for now :P |
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<% | ||
/** | ||
* Controller bake template file | ||
* | ||
* Allows templating of Controllers generated from bake. | ||
* | ||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org) | ||
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org) | ||
* | ||
* Licensed under The MIT License | ||
* For full copyright and license information, please see the LICENSE.txt | ||
* Redistributions of files must retain the above copyright notice. | ||
* | ||
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org) | ||
* @link http://cakephp.org CakePHP(tm) Project | ||
* @since 0.1.0 | ||
* @license http://www.opensource.org/licenses/mit-license.php MIT License | ||
*/ | ||
use Cake\Utility\Inflector; | ||
|
||
$defaultModel = $name; | ||
%> | ||
<?php | ||
namespace <%= $namespace %>\Controller<%= $prefix %>; | ||
|
||
use <%= $namespace %>\Controller\AppController; | ||
use Cake\Event\Event; | ||
|
||
/** | ||
* <%= $name %> Controller | ||
* | ||
* @property \<%= $namespace %>\Model\Table\<%= $defaultModel %>Table $<%= $defaultModel %> | ||
<% | ||
foreach ($components as $component): | ||
$classInfo = $this->Bake->classInfo($component, 'Controller/Component', 'Component'); | ||
%> | ||
* @property <%= $classInfo['fqn'] %> $<%= $classInfo['name'] %> | ||
<% endforeach; %> | ||
*/ | ||
class <%= $name %>Controller extends AppController | ||
{ | ||
<% echo $this->element('Controller/auth', $actions); %> | ||
<% | ||
echo $this->Bake->arrayProperty('helpers', $helpers, ['indent' => false]); | ||
echo $this->Bake->arrayProperty('components', $components, ['indent' => false]); | ||
foreach($actions as $action) { | ||
echo $this->element('Controller/' . $action); | ||
} | ||
%> | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
public function beforeRender(Event $event) | ||
{ | ||
$this->viewBuilder()->layout('admin'); | ||
} | ||
|
||
public function beforeFilter(Event $event) | ||
{ | ||
parent::beforeFilter($event); | ||
$this->Auth->deny(); | ||
} | ||
|
||
public function isAuthorized($user) | ||
{ | ||
// Registered Users can access | ||
if (in_array($this->request->action, [<% foreach($actions as $action) {echo "'$action', ";} %>])) { | ||
return true; | ||
} | ||
|
||
return parent::isAuthorized($user); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
<% | ||
/** | ||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org) | ||
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org) | ||
* | ||
* Licensed under The MIT License | ||
* For full copyright and license information, please see the LICENSE.txt | ||
* Redistributions of files must retain the above copyright notice. | ||
* | ||
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org) | ||
* @link http://cakephp.org CakePHP(tm) Project | ||
* @since 0.1.0 | ||
* @license http://www.opensource.org/licenses/mit-license.php MIT License | ||
*/ | ||
use Cake\Utility\Inflector; | ||
|
||
$fields = collection($fields) | ||
->filter(function($field) use ($schema) { | ||
return $schema->columnType($field) !== 'binary'; | ||
}); | ||
|
||
if (isset($modelObject) && $modelObject->behaviors()->has('Tree')) { | ||
$fields = $fields->reject(function ($field) { | ||
return $field === 'lft' || $field === 'rght'; | ||
}); | ||
} | ||
%> | ||
<?php | ||
// Title | ||
$title = __('<%= Inflector::humanize($action) %> <%= $singularHumanName %>'); | ||
$smallTitle = null; | ||
$this->assign('title', $title); | ||
echo $this->Layout->setPageTitle($title, $smallTitle); | ||
?> | ||
|
||
<?= $this->Form->create($<%= $singularVar %>) ?> | ||
<?php | ||
<% | ||
foreach ($fields as $field) { | ||
if (in_array($field, $primaryKey)) { | ||
continue; | ||
} | ||
if (isset($keyFields[$field])) { | ||
$fieldData = $schema->column($field); | ||
if (!empty($fieldData['null'])) { | ||
%> | ||
echo $this->Form->input('<%= $field %>', ['options' => $<%= $keyFields[$field] %>, 'empty' => true]); | ||
<% | ||
} else { | ||
%> | ||
echo $this->Form->input('<%= $field %>', ['options' => $<%= $keyFields[$field] %>]); | ||
<% | ||
} | ||
continue; | ||
} | ||
if (!in_array($field, ['created', 'modified', 'updated'])) { | ||
$fieldData = $schema->column($field); | ||
if (in_array($fieldData['type'], ['date', 'datetime', 'time']) && (!empty($fieldData['null']))) { | ||
%> | ||
echo $this->Form->input('<%= $field %>', ['empty' => true]); | ||
<% | ||
} else { | ||
%> | ||
echo $this->Form->input('<%= $field %>'); | ||
<% | ||
} | ||
} | ||
} | ||
if (!empty($associations['BelongsToMany'])) { | ||
foreach ($associations['BelongsToMany'] as $assocName => $assocData) { | ||
%> | ||
echo $this->Form->input('<%= $assocData['property'] %>._ids', ['options' => $<%= $assocData['variable'] %>]); | ||
<% | ||
} | ||
} | ||
%> | ||
?> | ||
<?= $this->Form->button(__('Submit'), ['type' => 'submit', 'class' => 'btn btn-primary']) ?> | ||
<?= $this->Form->end() ?> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dependencies can be removed from documentation and added to our
composer.json
right?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When I had them in our dependencies they were not being updated with composer so I moved them into app and it worked. This would be another shell solution.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is because you added the plugin to your
plugins/Bakkerij/CakeAdmin
for development reasons. Composer won't get that file.When the package is loaded by an user, the package is located in the
vendor
folder, and Composer will recognize it, and load its dependencies.TL;DR: This is only needed for development reasons but it might be solved another way...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually I used composer to download your version into vendor. Deleted the cakeadmin directory from vendor/bakkerij and then cloned my fork into the directory. This was the only way I could work on the files without routing issues.
Either way you had the CRUD version in the dependencies of cakeadmin and composer did not pull it in.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I stand corrected when I just started from scratch and the 2 were imported correctly when I used