Dieses Blog durchsuchen

Sonntag, 10. Juli 2016

Install symphon2 on linux, create a project with database, crudforms and twittter bootstrap

 Today we want to create a simple blogapplication with symfony (3.1)

LEVEL: PHP Advanced / Symfony2 Novice

This blog will have 3 features
- Users (add, delete, edit, login)
- Posts (add, delete, edit)
- Replies (add, delete, edit)


You need to have PHP 5 or 7 and Mysql Server running


Install Symfony
$ sudo curl -LsS https://symfony.com/installer -o /usr/local/bin/symfony
$ sudo chmod a+x /usr/bin/local/symfony


Create App 
php bin/console new blog 3.1

Create Bundle
php bin/console generate:bundle
- call it BlogBundle


Edit databaseconfiguration
open parameters.yml in config folder and edit databaseaccess

Create a database
php bin/console doctrine:database create
- call it blog

open a mysql client (fy mysql-workbench)

create needed tables

CREATE TABLE `replies` (
  `id` int(11) NOT NULL,
  `userid` int(11) DEFAULT NULL,
  `title` varchar(255) DEFAULT NULL,
  `content` text,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE `users` (
  `id` int(11) NOT NULL,
  `firstname` varchar(255) DEFAULT NULL,
  `lastame` varchar(255) DEFAULT NULL,
  `username` varchar(50) DEFAULT NULL,
  `email` varchar(255) DEFAULT NULL,
  `password` varchar(255) DEFAULT NULL,
  `isDeleted` tinyint(4) DEFAULT NULL,  `isActive` tinyint(4) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE `blog`.`posts` (
  `id` INT NOT NULL COMMENT '',
  `userid` INT NULL COMMENT '',
  `title` VARCHAR(255) NULL COMMENT '',
  `content` TEXT NULL COMMENT '',
  `isDeleted` TINYINT NULL COMMENT '',  `isActive` TINYINT NULL COMMENT '',
  PRIMARY KEY (`id`)  COMMENT '');

create entities from database:
php bin/console doctrine:mapping:import --force BlogBundle xml
php bin/console doctrine:mapping:convert annotation ./src
php bin/console doctrine:generate:entities BlogBundle 
 
 
Install twitter boodstrap crud bundle 
composer require triton/crud-generator
Add it to the AppKernel.php class:
new Lexik\Bundle\FormFilterBundle\LexikFormFilterBundle(), new Triton\Bundle\CrudBundle\TritonCrudBundle(), 
 
Optionally for the bootstrap theme, add this to your app/config/config.yml
twig:
    form_themes:
    - 'bootstrap_3_layout.html.twig' 

 
generate crud controllers with twitter bootstrap look and feel 
php bin/console triton:generate:crud
 
 
  














Keine Kommentare:

Kommentar veröffentlichen