Git Product home page Git Product logo

easy-mvc's Introduction

Easy MVC Framework

composer require maaximelh/easy-mvc

If Easy MVC Framework is not on the server root, please uncomment the following line in public/.htaccess

# RewriteBase /

Then, configure your framework into App\Config.php.

This MVC Framework integrate by default the Doctrine ORM

How Doctrine ORM works

An user Entity has already created, you need to import it with CLI.

vendor/bin/doctrine orm:schema-tool:update --dump-sql --force

A new users table has been created in your database with the annotations in the Entity\User.php file.

How it works ?

First, you need to get repository from Entity Manager.

$em = Entity::getEntityManager(); // Get Entity Manager
$repository = $em->getRepository(User::class); // Get User repository

Then you can do all the treatments you want, like the examples above.

Example of finder with repository.

$user = $repository->findBy(['email' => '[email protected]']); // Find all users where email = [email protected]
$user = $repository->findOneByEmail('[email protected]'); // Find one user where email = [email protected]
$user = $repository->findAll(); // Find all users

Example of usage to create a user.

$user = new User();
$user->setFirstname("Maxime");
$user->setLastname("LE HENAFF");
$user->setEmail("[email protected]");
$entityManager->persist($user); // Persist user into Doctrine System
$entityManager->flush(); // Flush all persistent data (save / update)
echo 'User : ' . $user->getId(); // Will output new User ID

Example of usage to delete a user by id.

$user = $repository->find(1); // Get user instance
$entityManager->remove($user); // Remove user into doctrine system
$entityManager->flush(); // Flush all persistent data (save / update)

Example of usage to updated user.

$user = $repository->find(1);
$user->setFirstname("MaaximeLH");
$entityManager->flush();

For more, see the Doctrine ORM documentations.

Generate Entities from database

If you have already tables in your database, you can generate Entities automatically with the following command.

php generator.php

# OR

vendor/bin/doctrine orm:convert-mapping --from-database annotation App/Entity

easy-mvc's People

Contributors

maaximelh avatar

Stargazers

 avatar Carissa Farry Hilmi Az Zahra avatar Romain Pierucci avatar

Watchers

James Cloos avatar

Forkers

azrabash

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.