S YMFONY ORM - D OCTRINE Sayed Ahmed B.Sc. Eng. in Computer Science & Engineering M. Sc. in Computer Science Exploring Computing for 14+ years

Slides:



Advertisements
Similar presentations
What is a Database By: Cristian Dubon.
Advertisements

1.  Understanding about How to Working with Server Side Scripting using PHP Framework (CodeIgniter) 2.
Chapter 5 Data Management. – The Best & Most Convenient Way to Learn Salesforce.com 2 Objectives By the end of the module, you.
NMD202 Web Scripting Week5. What we will cover today PHPmyAdmin Debugging – using print_r Modifying Data PHP (cont.) 4D Methodology File and IO operations.
Chapter 12: Using ADO.NET 2.0 Programming with Microsoft Visual Basic 2005, Third Edition.
Guide to Oracle10G1 Introduction To Forms Builder Chapter 5.
PHP (2) – Functions, Arrays, Databases, and sessions.
Chapter 12: ADO.NET and ASP.NET Programming with Microsoft Visual Basic.NET, Second Edition.
Introduction to Structured Query Language (SQL)
Fast Track to ColdFusion 9. Getting Started with ColdFusion Understanding Dynamic Web Pages ColdFusion Benchmark Introducing the ColdFusion Language Introducing.
Using Objects and Properties
Manipulating MySQL Databases with PHP. PHP and mySQL2 Objectives Connect to MySQL from PHP Learn how to handle MySQL errors Execute SQL statements with.
1 Pertemuan 09 Database Matakuliah: D0524 / Algoritma dan Pemrograman Komputer Tahun: 2005 Versi:
Introduction to Structured Query Language (SQL)
Chapter 14: Advanced Topics: DBMS, SQL, and ASP.NET
Simple Web SQLite Manager/Form/Report
DAY 21: MICROSOFT ACCESS – CHAPTER 5 MICROSOFT ACCESS – CHAPTER 6 MICROSOFT ACCESS – CHAPTER 7 Akhila Kondai October 30, 2013.
Advance Computer Programming Java Database Connectivity (JDBC) – In order to connect a Java application to a database, you need to use a JDBC driver. –
Lecture 3 – Data Storage with XML+AJAX and MySQL+socket.io
1Computer Sciences Department Princess Nourah bint Abdulrahman University.
A Guide to SQL, Eighth Edition Chapter Three Creating Tables.
Module 3: Table Selection
Session 5: Working with MySQL iNET Academy Open Source Web Development.
Programming with Microsoft Visual Basic 2012 Chapter 13: Working with Access Databases and LINQ.
Copyright © 2003 by Prentice Hall Computers: Tools for an Information Age Chapter 13 Database Management Systems: Getting Data Together.
ASP.NET Programming with C# and SQL Server First Edition
PHP Programming with MySQL Slide 8-1 CHAPTER 8 Working with Databases and MySQL.
AL-MAAREFA COLLEGE FOR SCIENCE AND TECHNOLOGY INFO 232: DATABASE SYSTEMS CHAPTER 7 INTRODUCTION TO STRUCTURED QUERY LANGUAGE (SQL) Instructor Ms. Arwa.
Web Application Development. Define ER model in QSEE Generate SQL Create Database mySQL Write Script to use TableEditor class Process to create A simple.
Web Application Development. Tools to create a simple web- editable database QSEE MySQL (or PHPMyAdmin) PHP TableEditor.
Concepts of Database Management Seventh Edition
Part 06 – A More Complex Data Model Entity Framework and MVC NTPCUG Tom Perkins.
1 MySQL and phpMyAdmin. 2 Navigate to and log on (username: pmadmin)
W EB A PPLICATIONS & W EB S ERVICES DEVELOPMENT USING Z END F RAMEWORK Sayed Ahmed B. Sc. Engineering in Computer Science and Engineering M. Sc. in Computer.
1 Overview of Databases. 2 Content Databases Example: Access Structure Query language (SQL)
Chapter 15: Using LINQ to Access Data in C# Programs.
Introduction to Microsoft Access 2003 Mr. A. Craig Dixon CIS 100: Introduction to Computers Spring 2006.
Hive Facebook 2009.
Chapter 7 Working with Databases and MySQL PHP Programming with MySQL 2 nd Edition.
Chapter 7 Working with Databases and MySQL PHP Programming with MySQL 2 nd Edition.
Sayed Ahmed Computer Engineering, BUET, Bangladesh MSc., Computer Science, Canada
Web Scripting [PHP] CIS166AE Wednesdays 6:00pm – 9:50pm Rob Loy.
Kirkwood Center for Continuing Education Introduction to PHP and MySQL By Fred McClurg, Copyright © 2015, Fred McClurg, All Rights.
7 1 Chapter 7 Introduction to Structured Query Language (SQL) Database Systems: Design, Implementation, and Management, Seventh Edition, Rob and Coronel.
CSCI 6962: Server-side Design and Programming Database Manipulation in ASP.
CHAPTER 9 PHP AND MYSQL. A POSSIBLE SITE CONFIGURATION Application Folder index.php includes (folder)header.phpfooter.phpstyle.cssmodel (folder)mysqli_connect.php.
CS 1308 Computer Literacy and the Internet
6 1 Lecture 8: Introduction to Structured Query Language (SQL) J. S. Chou, P.E., Ph.D.
Database Systems Design, Implementation, and Management Coronel | Morris 11e ©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or.
SQL Basics. What is SQL? SQL stands for Structured Query Language. SQL lets you access and manipulate databases.
F UNCTIONAL T ESTS IN S YMFONY Sayed Ahmed B.Sc. Eng. in Computer Science & Engineering M. Sc. in Computer Science Exploring Computing for 14+ years
SQL Jan 20,2014. DBMS Stores data as records, tables etc. Accepts data and stores that data for later use Uses query languages for searching, sorting,
3 Copyright © 2004, Oracle. All rights reserved. Working in the Forms Developer Environment.
Chapter 8 Manipulating MySQL Databases with PHP PHP Programming with MySQL 2 nd Edition.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Address Book Application Introducing Database Programming.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 14 Web Database Programming Using PHP.
Chapter 5 Introduction To Form Builder. Lesson C Objectives  Use sequences to automatically generate primary key values in a form  Create lists of values.
Unit-8 Introduction Of MySql. Types of table in PHP MySQL supports various of table types or storage engines to allow you to optimize your database. The.
CSC314 DAY 8 Introduction to SQL 1. Chapter 6 © 2013 Pearson Education, Inc. Publishing as Prentice Hall SQL OVERVIEW  Structured Query Language  The.
MICROSOFT ACCESS – CHAPTER 5 MICROSOFT ACCESS – CHAPTER 6 MICROSOFT ACCESS – CHAPTER 7 Sravanthi Lakkimsety Mar 14,2016.
CHAPTER 9 File Storage Shared Preferences SQLite.
Software-Projekt 2008 Seminarvortrag“Short tutorial of MySql“ Wei Chen Verena Honsel.
1 Copyright © 2008, Oracle. All rights reserved. Repository Basics.
1 Section 1 - Introduction to SQL u SQL is an abbreviation for Structured Query Language. u It is generally pronounced “Sequel” u SQL is a unified language.
16 Copyright © 2004, Oracle. All rights reserved. Testing the Migrated Oracle Database.
Introduction to Database Programming with Python Gary Stewart
COM621: Advanced Interactive Web Development Lecture 10 PHP and MySQL.
Dept. of Computer & Information Sciences
Chapter # 7 Introduction to Structured Query Language (SQL) Part I.
Presentation transcript:

S YMFONY ORM - D OCTRINE Sayed Ahmed B.Sc. Eng. in Computer Science & Engineering M. Sc. in Computer Science Exploring Computing for 14+ years 10/8/2011 1

S YMFONY - ORM Instead of writing SQL statements to retrieve records from the database, we can use objects Doctrine and Propel can help We will discuss Doctrine The ORM needs a description of the tables and their relationships to create the related classes Can be done using tools or by hand You can define the schema in the file config/doctrine/schema.yml $ php symfony doctrine:build-schema It will generate the schema if database schema is defined in databases.yml Configuration files are written in YAML YAML Format: 10/8/

T HE R ELATIONAL M ODEL 10/8/

YAML S CHEMA # config/doctrine/schema.yml JobeetCategory: actAs: { Timestampable: ~ } columns: name: { type: string(255), notnull: true, unique: true } 10/8/

YAML S CHEMA JobeetJob: actAs: { Timestampable: ~ } columns: category_id: { type: integer, notnull: true } type: { type: string(255) } c ompany: { type: string(255), notnull: true } logo: { type: string(255) } url: { type: string(255) } position: { type: string(255), notnull: true } location: { type: string(255), notnull: true } description: { type: string(4000), notnull: true } how_to_apply: { type: string(4000), notnull: true } token: { type: string(255), notnull: true, unique: true } is_public: { type: boolean, notnull: true, default: 1 } is_activated: { type: boolean, notnull: true, default: 0 } { type: string(255), notnull: true } expires_at: { type: timestamp, notnull: true } relations: JobeetCategory: { onDelete: CASCADE, local: category_id, foreign: id, foreignAlias: JobeetJobs } 10/8/

YAML S CHEMA JobeetAffiliate: actAs: { Timestampable: ~ } columns: url: { type: string(255), notnull: true } { type: string(255), notnull: true, unique: true } token: { type: string(255), notnull: true } is_active: { type: boolean, notnull: true, default: 0 } relations: JobeetCategories: class: JobeetCategory refClass: JobeetCategoryAffiliate local: affiliate_id foreign: category_id foreignAlias: JobeetAffiliates 10/8/

YAML S CHEMA JobeetCategoryAffiliate: columns: category_id: { type: integer, primary: true } affiliate_id: { type: integer, primary: true } relations: JobeetCategory: { onDelete: CASCADE, local: category_id, foreign: id } JobeetAffiliate: { onDelete: CASCADE, local: affiliate_id, foreign: id } 10/8/

C ONFIGURE D ATABASE Configure database in Symfony php symfony configure:database "mysql:host=localhost;dbname=jobeet" root mYsEcret it might be better to edit the config/databases.yml to change the password. Of course, to keep the password safe, the configuration file access mode should also be restricted 10/8/

C REATING THE M ODEL & D ATABASE Using the database description from the schema.yml file we can use some Doctrine built-in tasks to generate the SQL statements needed to create the database tables to generate the SQL you must build your models from your schema files $ php symfony doctrine:build –model Now that your models are present you can generate and insert the SQL. $ php symfony doctrine:build –sql The doctrine:build --sql task generates SQL statements in the data/sql/ directory optimized for the database engine we have configured 10/8/

C REATING THE M ODEL & D ATABASE To actually create the tables in the database, you need to run the doctrine:insert-sql task $ php symfony doctrine:insert-sql Syntax: Symfony commands: $ php symfony help doctrine:insert-sql The ORM also generates PHP classes that map table records to objects: $ php symfony doctrine:build –model The doctrine:build --model task generates PHP files in the lib/model/ directory that can be used to interact with the database 10/8/

C REATING THE M ODEL & D ATABASE Doctrine generates three classes per table. For the jobeet_job table: JobeetJob: An object of this class represents a single record of the jobeet_job table. The class is empty by default. BaseJobeetJob: The parent class of JobeetJob. Each time you run doctrine:build --model, this class is overwritten, so all customizations must be done in the JobeetJob class. JobeetJobTable: The class defines methods that mostly return collections of JobeetJob objects. The class is empty by default. 10/8/

A CCESSORS & M UTATORS $job = new JobeetJob(); $job->setPosition('Web developer'); $job->save(); echo $job->getPosition(); $job->delete(); 10/8/

D EFINE F OREIGN KEYS $category = new JobeetCategory(); $category->setName('Programming'); $job = new JobeetJob(); $job->setCategory($category); 10/8/

DOCTRINE : BUILD -- ALL The doctrine:build --all is a shortcut for the tasks we have run in this section and some more run this task now to generate forms and validators for the Jobeet model classes: $ php symfony doctrine:build --all --no-confirmation 10/8/

T HE D ATA The Data Initial data : Test data User data Each time symfony creates the tables in the database, all the data are lost. We can create YAML files in the data/fixtures/ directory to define initial data and use the doctrine:data-load task to load data into the database. 10/8/

D ATA FIXTURE FILES # data/fixtures/categories.yml JobeetCategory: design: name: Design programming: name: Programming manager: name: Manager administrator: name: Administrator 10/8/

L OAD I NITIAL DATA $ php symfony doctrine:data-load $ php symfony doctrine:build --all --and-load 10/8/

M ODULES – A UTO G ENERATE symfony project is made of applications Each application is further divided into modules. A module is a self-contained set of PHP code that represents a feature of the application (the API module for example) or a set of manipulations the user can do on a model object (a job module for example) Symfony is able to automatically generate a module for a given model that provides basic manipulation features: $ php symfony doctrine:generate-module --with-show --non-verbose-templates frontend job JobeetJob 10/8/

M ODULES – A UTO G ENERATE the apps/frontend/modules/job/ directory: actions/ The module actions templates/ The module templates The actions/actions.class.php file defines all the available action for the job module: index Displays the records of the table show Displays the fields and their values for a given record new Displays a form to create a new record create Creates a new record edit Displays a form to edit an existing record update Updates a record according to the user submitted values delete Deletes a given record from the table 10/8/

T EST M ODULES You can now test the job module in a browser: 10/8/

A PPENDIX - YAML YAML is "a human friendly data serialization standard for all programming languages“ YAML is a simple language to describe data (strings, integers, dates, arrays, and hashes). Structure is shown through indentation, sequence items are denoted by a dash, and key/value pairs within a map are separated by a colon. arrays are explicitly shown with [] and hashes with {}. symfony framework uses it extensively for its configuration files. indentation must be done with one or more spaces, but never with tabulations. 10/8/

R EFERENCES project.org/jobeet/1_4/Doctrine/en/ 10/8/