Advertisement
Guest User

CakePHP Install

a guest
Mar 31st, 2020
226
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 4.84 KB | None | 0 0
  1. Проєкт на CakePHP
  2. Необхідно мати
  3. встановлений PHP https://www.php.net
  4. MySQL https://www.mysql.com
  5.  
  6. ## Встановити Composer
  7. ## Composer https://getcomposer.org
  8. php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
  9. php composer-setup.php
  10. php -r "unlink('composer-setup.php');"
  11.  
  12. ## Створення проекту https://cakephp.org
  13. php ./composer.phar create-project --prefer-dist cakephp/app:4.* mydemo
  14.  
  15. ./bin/cake server
  16.  
  17. # Налаштуванни БД https://book.cakephp.org/4/en/development/configuration.html
  18. # config/app_local.php
  19.  
  20. # Наповнення БД
  21. # https://book.cakephp.org/4/en/tutorials-and-examples/cms/database.html
  22.  
  23. CREATE TABLE users (
  24.     id INT AUTO_INCREMENT PRIMARY KEY,
  25.     email VARCHAR(255) NOT NULL,
  26.     password VARCHAR(255) NOT NULL,
  27.     created DATETIME,
  28.     modified DATETIME
  29. );
  30.  
  31. CREATE TABLE articles (
  32.     id INT AUTO_INCREMENT PRIMARY KEY,
  33.     user_id INT NOT NULL,
  34.     title VARCHAR(255) NOT NULL,
  35.     slug VARCHAR(191) NOT NULL,
  36.     body TEXT,
  37.     published BOOLEAN DEFAULT FALSE,
  38.     created DATETIME,
  39.     modified DATETIME,
  40.     UNIQUE KEY (slug),
  41.     FOREIGN KEY user_key (user_id) REFERENCES users(id)
  42. ) CHARSET=utf8mb4;
  43.  
  44. CREATE TABLE tags (
  45.     id INT AUTO_INCREMENT PRIMARY KEY,
  46.     title VARCHAR(191),
  47.     created DATETIME,
  48.     modified DATETIME,
  49.     UNIQUE KEY (title)
  50. ) CHARSET=utf8mb4;
  51.  
  52. CREATE TABLE articles_tags (
  53.     article_id INT NOT NULL,
  54.     tag_id INT NOT NULL,
  55.     PRIMARY KEY (article_id, tag_id),
  56.     FOREIGN KEY tag_key(tag_id) REFERENCES tags(id),
  57.     FOREIGN KEY article_key(article_id) REFERENCES articles(id)
  58. );
  59.  
  60. INSERT INTO users (email, password, created, modified)
  61. VALUES
  62. ('cakephp@example.com', 'secret', NOW(), NOW());
  63.  
  64. INSERT INTO articles (user_id, title, slug, body, published, created, modified)
  65. VALUES
  66. (1, 'First Post', 'first-post', 'This is the first post.', 1, NOW(), NOW());
  67.  
  68.  
  69. ## Bake
  70.  
  71. bin/cake bake model all
  72. bin/cake bake controller articles
  73. bin/cake bake template Articles
  74.  
  75. # https://milligram.io/
  76.  
  77.  
  78. ## Додавання плагінів
  79.  
  80. // composer.json
  81. ,
  82.     "repositories": [
  83.       {
  84.           "type": "vcs",
  85.           "url": "https://github.com/yarkm13/cakephp-adminlte-theme"
  86.       }
  87.     ]
  88.  
  89. # Тема адмінки https://github.com/maiconpinto/cakephp-adminlte-theme
  90. # https://maiconpinto.github.io/cakephp-adminlte-theme/start
  91. php ../composer.phar require maiconpinto/cakephp-adminlte-theme dev-master
  92. bin/cake plugin load AdminLTE
  93. // , ['bootstrap' => true, 'routes' => true]
  94.  
  95. // src/Controller/AppController.php
  96.  
  97. use Cake\Event\EventInterface;
  98. public function beforeRender(EventInterface  $event)
  99. {
  100.         if ($this->request->getParam('prefix') == 'Admin') $this->viewBuilder()->setTheme('AdminLTE');
  101.         if ($this->request->getParam('controller') == 'Pages') $this->viewBuilder()->setTheme('AdminLTE');
  102. }
  103. // AppView.php
  104. $this->loadHelper('Form', ['className' => 'AdminLTE.Form']);
  105.  
  106. // https://book.cakephp.org/4/en/development/routing.html#prefix-routing
  107.  
  108.     $builder->prefix('Admin', function (RouteBuilder $routes) {
  109.         $routes->fallbacks(DashedRoute::class);
  110.     });
  111.  
  112. bin/cake bake controller articles --theme AdminLTE --prefix admin
  113. bin/cake bake template articles --theme AdminLTE --prefix admin
  114. bin/cake bake controller tags --theme AdminLTE --prefix admin
  115. bin/cake bake template tags --theme AdminLTE --prefix admin
  116.  
  117. // src/Controller/Admin/ArticlesController.php:56
  118. // $article = $this->Articles->newEntity([]);
  119.  
  120.  
  121. ALTER TABLE `articles` DROP FOREIGN KEY `user_key`;
  122. DROP TABLE `users`;
  123. ALTER TABLE `articles` CHANGE `user_id` `user_id` CHAR(36)  NOT NULL  DEFAULT '';
  124.  
  125.  
  126. # Вхід/Реєстрація/Управління користувачами https://github.com/CakeDC/users
  127. php ../composer.phar require cakedc/users
  128. bin/cake plugin load CakeDC/Users
  129. // , ['bootstrap' => true, 'routes' => true]
  130. bin/cake migrations migrate -p CakeDC/Users
  131. bin/cake users addSuperuser
  132. # http://localhost:8765/users/index
  133. # http://localhost:8765/users/profile
  134.  
  135.  
  136. # https://getbootstrap.com
  137. # bootstrap-ui — вбудована підтримка Bootstrap https://github.com/FriendsOfCake/bootstrap-ui/tree/cake-4-bs-4
  138. php ../composer.phar require friendsofcake/bootstrap-ui dev-cake-4-bs-4
  139. bin/cake plugin load BootstrapUI
  140. #bin/cake bootstrap install
  141. php ../composer.phar require twbs/bootstrap:4.x
  142. php ../composer.phar require components/jquery
  143. mkdir -p webroot/bootstrap_u_i/css webroot/bootstrap_u_i/js
  144. cp vendor/twbs/bootstrap/dist/css/* webroot/bootstrap_u_i/css/.
  145. cp vendor/twbs/bootstrap/dist/js/* webroot/bootstrap_u_i/js/.
  146. cp vendor/components/jquery/jquery.js webroot/bootstrap_u_i/js/.
  147.  
  148. bin/cake bootstrap modify_view
  149. bin/cake bootstrap copy_layouts
  150.  
  151. bin/cake bake template Articles -t BootstrapUI
  152.  
  153. https://pastebin.com
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement