SlideShare a Scribd company logo
SYMFONY
ORM - DOCTRINE
Sayed Ahmed
B.Sc. Eng. in Computer Science & Engineering
M. Sc. in Computer Science
Exploring Computing for 14+ years
sayed@justetc.net
http://sayed.justetc.net
10/8/2011sayed@justetc.net
1
SYMFONY - 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:
 http://components.symfony-project.org/yaml/trunk/book/02-YAML
10/8/2011
2
sayed@justetc.net
THE RELATIONAL MODEL
10/8/2011
3
sayed@justetc.net
YAML SCHEMA
 # config/doctrine/schema.yml
 JobeetCategory:
 actAs: { Timestampable: ~ }
 columns:
 name: { type: string(255), notnull: true, unique: true }
10/8/2011
4
sayed@justetc.net
YAML SCHEMA
 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 }
 email: { type: string(255), notnull: true }
 expires_at: { type: timestamp, notnull: true }
 relations:
 JobeetCategory: {
 onDelete: CASCADE,
 local: category_id,
 foreign: id,
 foreignAlias: JobeetJobs
 }
10/8/2011
5
sayed@justetc.net
YAML SCHEMA
 JobeetAffiliate:
 actAs: { Timestampable: ~ }
 columns:
 url: { type: string(255), notnull: true }
 email: { 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/2011
6
sayed@justetc.net
YAML SCHEMA
 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/2011
7
sayed@justetc.net
CONFIGURE DATABASE
 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/2011
8
sayed@justetc.net
CREATING THE MODEL & DATABASE
 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/2011
9
sayed@justetc.net
CREATING THE MODEL & DATABASE
 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/2011
10
sayed@justetc.net
CREATING THE MODEL & DATABASE
 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/2011
11
sayed@justetc.net
ACCESSORS & MUTATORS
 $job = new JobeetJob();
 $job->setPosition('Web developer');
 $job->save();
 echo $job->getPosition();
 $job->delete();
10/8/2011
12
sayed@justetc.net
DEFINE FOREIGN KEYS
 $category = new JobeetCategory();
 $category->setName('Programming');
 $job = new JobeetJob();
 $job->setCategory($category);
10/8/2011
13
sayed@justetc.net
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/2011
14
sayed@justetc.net
THE DATA
 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/2011
15
sayed@justetc.net
DATA FIXTURE FILES
 # data/fixtures/categories.yml
 JobeetCategory:
 design:
 name: Design
 programming:
 name: Programming
 manager:
 name: Manager
 administrator:
 name: Administrator
10/8/2011
16
sayed@justetc.net
LOAD INITIAL DATA
 $ php symfony doctrine:data-load
 $ php symfony doctrine:build --all --and-load
10/8/2011
17
sayed@justetc.net
MODULES – AUTO GENERATE
 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/2011
18
sayed@justetc.net
MODULES – AUTO GENERATE
 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/2011
19
sayed@justetc.net
TEST MODULES
 You can now test the job module in a browser:
 http://www.jobeet.com.localhost/frontend_dev.php/job
10/8/2011
20
sayed@justetc.net
APPENDIX - 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/2011
21
sayed@justetc.net
REFERENCES
 http://www.symfony-
project.org/jobeet/1_4/Doctrine/en/
10/8/2011
22
sayed@justetc.net

More Related Content

What's hot

Php-mysql by Jogeswar Sir
Php-mysql by Jogeswar SirPhp-mysql by Jogeswar Sir
Web technology html5 php_mysql
Web technology html5 php_mysqlWeb technology html5 php_mysql
Web technology html5 php_mysql
durai arasan
 
TOT PHP DAY 1
TOT PHP DAY 1TOT PHP DAY 1
TOT PHP DAY 1
Riza Nurman
 
An Introduction to Object-Oriented Programming (DrupalCamp London 2015)
An Introduction to Object-Oriented Programming (DrupalCamp London 2015)An Introduction to Object-Oriented Programming (DrupalCamp London 2015)
An Introduction to Object-Oriented Programming (DrupalCamp London 2015)
Bart Feenstra
 
Diving in OOP (Day 1) : Polymorphism and Inheritance (Early Binding/Compile T...
Diving in OOP (Day 1) : Polymorphism and Inheritance (Early Binding/Compile T...Diving in OOP (Day 1) : Polymorphism and Inheritance (Early Binding/Compile T...
Diving in OOP (Day 1) : Polymorphism and Inheritance (Early Binding/Compile T...
Akhil Mittal
 
Open Gurukul Language PL/SQL
Open Gurukul Language PL/SQLOpen Gurukul Language PL/SQL
Open Gurukul Language PL/SQL
Open Gurukul
 

What's hot (6)

Php-mysql by Jogeswar Sir
Php-mysql by Jogeswar SirPhp-mysql by Jogeswar Sir
Php-mysql by Jogeswar Sir
 
Web technology html5 php_mysql
Web technology html5 php_mysqlWeb technology html5 php_mysql
Web technology html5 php_mysql
 
TOT PHP DAY 1
TOT PHP DAY 1TOT PHP DAY 1
TOT PHP DAY 1
 
An Introduction to Object-Oriented Programming (DrupalCamp London 2015)
An Introduction to Object-Oriented Programming (DrupalCamp London 2015)An Introduction to Object-Oriented Programming (DrupalCamp London 2015)
An Introduction to Object-Oriented Programming (DrupalCamp London 2015)
 
Diving in OOP (Day 1) : Polymorphism and Inheritance (Early Binding/Compile T...
Diving in OOP (Day 1) : Polymorphism and Inheritance (Early Binding/Compile T...Diving in OOP (Day 1) : Polymorphism and Inheritance (Early Binding/Compile T...
Diving in OOP (Day 1) : Polymorphism and Inheritance (Early Binding/Compile T...
 
Open Gurukul Language PL/SQL
Open Gurukul Language PL/SQLOpen Gurukul Language PL/SQL
Open Gurukul Language PL/SQL
 

Viewers also liked

Keys to a Successful Nonprofit Brand
Keys to a Successful Nonprofit BrandKeys to a Successful Nonprofit Brand
Keys to a Successful Nonprofit Brand
Bill Reynolds
 
User interfaces
User interfacesUser interfaces
User interfaces
Sayed Ahmed
 
Auto call setup for xcal series 3.x.xx vod
Auto call setup for xcal series 3.x.xx vodAuto call setup for xcal series 3.x.xx vod
Auto call setup for xcal series 3.x.xx vod
Outsource Benchmarking Projectss
 
Herramientas de powerpoint - Daniel Albores
Herramientas de powerpoint - Daniel AlboresHerramientas de powerpoint - Daniel Albores
Herramientas de powerpoint - Daniel Albores
Daniel Albores Cuevas
 
Práctica 2b (análisis película la cenicienta)
Práctica 2b (análisis película la cenicienta)Práctica 2b (análisis película la cenicienta)
Práctica 2b (análisis película la cenicienta)
manumaestro19
 
Inspectierapportpolitieonderwijskwaliteitgeborgd
InspectierapportpolitieonderwijskwaliteitgeborgdInspectierapportpolitieonderwijskwaliteitgeborgd
InspectierapportpolitieonderwijskwaliteitgeborgdFrank Smilda
 
The Entrepreneurial Employee Workshop | Brochure for Colleges
The Entrepreneurial Employee Workshop | Brochure for CollegesThe Entrepreneurial Employee Workshop | Brochure for Colleges
The Entrepreneurial Employee Workshop | Brochure for Colleges
Tyrron Whyte
 
Codice della strada
Codice della stradaCodice della strada
Codice della strada
angerado
 
Caracteristicas del estado colombiano
Caracteristicas del estado colombianoCaracteristicas del estado colombiano
Caracteristicas del estado colombiano
Keytlin Brieva
 

Viewers also liked (10)

Keys to a Successful Nonprofit Brand
Keys to a Successful Nonprofit BrandKeys to a Successful Nonprofit Brand
Keys to a Successful Nonprofit Brand
 
Richmond hill pc
Richmond hill pcRichmond hill pc
Richmond hill pc
 
User interfaces
User interfacesUser interfaces
User interfaces
 
Auto call setup for xcal series 3.x.xx vod
Auto call setup for xcal series 3.x.xx vodAuto call setup for xcal series 3.x.xx vod
Auto call setup for xcal series 3.x.xx vod
 
Herramientas de powerpoint - Daniel Albores
Herramientas de powerpoint - Daniel AlboresHerramientas de powerpoint - Daniel Albores
Herramientas de powerpoint - Daniel Albores
 
Práctica 2b (análisis película la cenicienta)
Práctica 2b (análisis película la cenicienta)Práctica 2b (análisis película la cenicienta)
Práctica 2b (análisis película la cenicienta)
 
Inspectierapportpolitieonderwijskwaliteitgeborgd
InspectierapportpolitieonderwijskwaliteitgeborgdInspectierapportpolitieonderwijskwaliteitgeborgd
Inspectierapportpolitieonderwijskwaliteitgeborgd
 
The Entrepreneurial Employee Workshop | Brochure for Colleges
The Entrepreneurial Employee Workshop | Brochure for CollegesThe Entrepreneurial Employee Workshop | Brochure for Colleges
The Entrepreneurial Employee Workshop | Brochure for Colleges
 
Codice della strada
Codice della stradaCodice della strada
Codice della strada
 
Caracteristicas del estado colombiano
Caracteristicas del estado colombianoCaracteristicas del estado colombiano
Caracteristicas del estado colombiano
 

Similar to Symfony 2

Mvc in symfony
Mvc in symfonyMvc in symfony
Mvc in symfony
Sayed Ahmed
 
Symfony2 Introduction Presentation
Symfony2 Introduction PresentationSymfony2 Introduction Presentation
Symfony2 Introduction PresentationNerd Tzanetopoulos
 
Zend Framework And Doctrine
Zend Framework And DoctrineZend Framework And Doctrine
Zend Framework And Doctrine
isaaczfoster
 
Entity Framework 4
Entity Framework 4Entity Framework 4
Entity Framework 4
Stefano Paluello
 
Googleappengineintro 110410190620-phpapp01
Googleappengineintro 110410190620-phpapp01Googleappengineintro 110410190620-phpapp01
Googleappengineintro 110410190620-phpapp01Tony Frame
 
Rupicon 2014 Single table inheritance
Rupicon 2014 Single table inheritanceRupicon 2014 Single table inheritance
Rupicon 2014 Single table inheritance
rupicon
 
Intake 38 data access 5
Intake 38 data access 5Intake 38 data access 5
Intake 38 data access 5
Mahmoud Ouf
 
Principles of MVC for Rails Developers
Principles of MVC for Rails DevelopersPrinciples of MVC for Rails Developers
Principles of MVC for Rails Developers
Edureka!
 
Drupal Best Practices
Drupal Best PracticesDrupal Best Practices
Drupal Best Practices
manugoel2003
 
ChircuVictor StefircaMadalin rad_aspmvc3_wcf_vs2010
ChircuVictor StefircaMadalin rad_aspmvc3_wcf_vs2010ChircuVictor StefircaMadalin rad_aspmvc3_wcf_vs2010
ChircuVictor StefircaMadalin rad_aspmvc3_wcf_vs2010
vchircu
 
Choose'10: Ralf Laemmel - Dealing Confortably with the Confusion of Tongues
Choose'10: Ralf Laemmel - Dealing Confortably with the Confusion of TonguesChoose'10: Ralf Laemmel - Dealing Confortably with the Confusion of Tongues
Choose'10: Ralf Laemmel - Dealing Confortably with the Confusion of Tongues
CHOOSE
 
Learning MVC Part 3 Creating MVC Application with EntityFramework
Learning MVC Part 3 Creating MVC Application with EntityFrameworkLearning MVC Part 3 Creating MVC Application with EntityFramework
Learning MVC Part 3 Creating MVC Application with EntityFrameworkAkhil Mittal
 
.NET Portfolio
.NET Portfolio.NET Portfolio
.NET Portfoliomwillmer
 
JavaScript Miller Columns
JavaScript Miller ColumnsJavaScript Miller Columns
JavaScript Miller Columns
Jonathan Fine
 
Overview of entity framework by software outsourcing company india
Overview of entity framework by software outsourcing company indiaOverview of entity framework by software outsourcing company india
Overview of entity framework by software outsourcing company india
Jignesh Aakoliya
 
Object-oriented programming (OOP) with Complete understanding modules
Object-oriented programming (OOP) with Complete understanding modulesObject-oriented programming (OOP) with Complete understanding modules
Object-oriented programming (OOP) with Complete understanding modules
Durgesh Singh
 
Intake 37 ef2
Intake 37 ef2Intake 37 ef2
Intake 37 ef2
Mahmoud Ouf
 
Lab #9 and 10 Web Server ProgrammingCreate a New Folder I s.docx
Lab #9 and 10 Web Server ProgrammingCreate a New Folder  I s.docxLab #9 and 10 Web Server ProgrammingCreate a New Folder  I s.docx
Lab #9 and 10 Web Server ProgrammingCreate a New Folder I s.docx
DIPESH30
 

Similar to Symfony 2 (20)

Mvc in symfony
Mvc in symfonyMvc in symfony
Mvc in symfony
 
Symfony2 Introduction Presentation
Symfony2 Introduction PresentationSymfony2 Introduction Presentation
Symfony2 Introduction Presentation
 
Zend Framework And Doctrine
Zend Framework And DoctrineZend Framework And Doctrine
Zend Framework And Doctrine
 
Entity Framework 4
Entity Framework 4Entity Framework 4
Entity Framework 4
 
Googleappengineintro 110410190620-phpapp01
Googleappengineintro 110410190620-phpapp01Googleappengineintro 110410190620-phpapp01
Googleappengineintro 110410190620-phpapp01
 
Rupicon 2014 Single table inheritance
Rupicon 2014 Single table inheritanceRupicon 2014 Single table inheritance
Rupicon 2014 Single table inheritance
 
Intake 38 data access 5
Intake 38 data access 5Intake 38 data access 5
Intake 38 data access 5
 
Principles of MVC for Rails Developers
Principles of MVC for Rails DevelopersPrinciples of MVC for Rails Developers
Principles of MVC for Rails Developers
 
Dn D Custom 1
Dn D Custom 1Dn D Custom 1
Dn D Custom 1
 
Dn D Custom 1
Dn D Custom 1Dn D Custom 1
Dn D Custom 1
 
Drupal Best Practices
Drupal Best PracticesDrupal Best Practices
Drupal Best Practices
 
ChircuVictor StefircaMadalin rad_aspmvc3_wcf_vs2010
ChircuVictor StefircaMadalin rad_aspmvc3_wcf_vs2010ChircuVictor StefircaMadalin rad_aspmvc3_wcf_vs2010
ChircuVictor StefircaMadalin rad_aspmvc3_wcf_vs2010
 
Choose'10: Ralf Laemmel - Dealing Confortably with the Confusion of Tongues
Choose'10: Ralf Laemmel - Dealing Confortably with the Confusion of TonguesChoose'10: Ralf Laemmel - Dealing Confortably with the Confusion of Tongues
Choose'10: Ralf Laemmel - Dealing Confortably with the Confusion of Tongues
 
Learning MVC Part 3 Creating MVC Application with EntityFramework
Learning MVC Part 3 Creating MVC Application with EntityFrameworkLearning MVC Part 3 Creating MVC Application with EntityFramework
Learning MVC Part 3 Creating MVC Application with EntityFramework
 
.NET Portfolio
.NET Portfolio.NET Portfolio
.NET Portfolio
 
JavaScript Miller Columns
JavaScript Miller ColumnsJavaScript Miller Columns
JavaScript Miller Columns
 
Overview of entity framework by software outsourcing company india
Overview of entity framework by software outsourcing company indiaOverview of entity framework by software outsourcing company india
Overview of entity framework by software outsourcing company india
 
Object-oriented programming (OOP) with Complete understanding modules
Object-oriented programming (OOP) with Complete understanding modulesObject-oriented programming (OOP) with Complete understanding modules
Object-oriented programming (OOP) with Complete understanding modules
 
Intake 37 ef2
Intake 37 ef2Intake 37 ef2
Intake 37 ef2
 
Lab #9 and 10 Web Server ProgrammingCreate a New Folder I s.docx
Lab #9 and 10 Web Server ProgrammingCreate a New Folder  I s.docxLab #9 and 10 Web Server ProgrammingCreate a New Folder  I s.docx
Lab #9 and 10 Web Server ProgrammingCreate a New Folder I s.docx
 

More from Sayed Ahmed

Workplace, Data Analytics, and Ethics
Workplace, Data Analytics, and EthicsWorkplace, Data Analytics, and Ethics
Workplace, Data Analytics, and Ethics
Sayed Ahmed
 
Python py charm anaconda jupyter installation and basic commands
Python py charm anaconda jupyter   installation and basic commandsPython py charm anaconda jupyter   installation and basic commands
Python py charm anaconda jupyter installation and basic commands
Sayed Ahmed
 
[not edited] Demo on mobile app development using ionic framework
[not edited] Demo on mobile app development using ionic framework[not edited] Demo on mobile app development using ionic framework
[not edited] Demo on mobile app development using ionic framework
Sayed Ahmed
 
Sap hana-ide-overview-nodev
Sap hana-ide-overview-nodevSap hana-ide-overview-nodev
Sap hana-ide-overview-nodev
Sayed Ahmed
 
Invest wisely
Invest wiselyInvest wisely
Invest wisely
Sayed Ahmed
 
Will be an introduction to
Will be an introduction toWill be an introduction to
Will be an introduction to
Sayed Ahmed
 
Whm and cpanel overview hosting control panel overview
Whm and cpanel overview   hosting control panel overviewWhm and cpanel overview   hosting control panel overview
Whm and cpanel overview hosting control panel overview
Sayed Ahmed
 
Web application development using zend framework
Web application development using zend frameworkWeb application development using zend framework
Web application development using zend framework
Sayed Ahmed
 
Web design and_html_part_3
Web design and_html_part_3Web design and_html_part_3
Web design and_html_part_3
Sayed Ahmed
 
Web design and_html_part_2
Web design and_html_part_2Web design and_html_part_2
Web design and_html_part_2
Sayed Ahmed
 
Web design and_html
Web design and_htmlWeb design and_html
Web design and_html
Sayed Ahmed
 
Visual studio ide shortcuts
Visual studio ide shortcutsVisual studio ide shortcuts
Visual studio ide shortcuts
Sayed Ahmed
 
Virtualization
VirtualizationVirtualization
Virtualization
Sayed Ahmed
 
Unreal
UnrealUnreal
Unreal
Sayed Ahmed
 
Unit tests in_symfony
Unit tests in_symfonyUnit tests in_symfony
Unit tests in_symfony
Sayed Ahmed
 
Telerik this is sayed
Telerik this is sayedTelerik this is sayed
Telerik this is sayed
Sayed Ahmed
 
System analysis and_design
System analysis and_designSystem analysis and_design
System analysis and_design
Sayed Ahmed
 
Story telling and_narrative
Story telling and_narrativeStory telling and_narrative
Story telling and_narrative
Sayed Ahmed
 
Some skills required to be a computer hardware engineer professional
Some skills required to be a computer hardware engineer professionalSome skills required to be a computer hardware engineer professional
Some skills required to be a computer hardware engineer professional
Sayed Ahmed
 
Simple demonstration on
Simple demonstration onSimple demonstration on
Simple demonstration on
Sayed Ahmed
 

More from Sayed Ahmed (20)

Workplace, Data Analytics, and Ethics
Workplace, Data Analytics, and EthicsWorkplace, Data Analytics, and Ethics
Workplace, Data Analytics, and Ethics
 
Python py charm anaconda jupyter installation and basic commands
Python py charm anaconda jupyter   installation and basic commandsPython py charm anaconda jupyter   installation and basic commands
Python py charm anaconda jupyter installation and basic commands
 
[not edited] Demo on mobile app development using ionic framework
[not edited] Demo on mobile app development using ionic framework[not edited] Demo on mobile app development using ionic framework
[not edited] Demo on mobile app development using ionic framework
 
Sap hana-ide-overview-nodev
Sap hana-ide-overview-nodevSap hana-ide-overview-nodev
Sap hana-ide-overview-nodev
 
Invest wisely
Invest wiselyInvest wisely
Invest wisely
 
Will be an introduction to
Will be an introduction toWill be an introduction to
Will be an introduction to
 
Whm and cpanel overview hosting control panel overview
Whm and cpanel overview   hosting control panel overviewWhm and cpanel overview   hosting control panel overview
Whm and cpanel overview hosting control panel overview
 
Web application development using zend framework
Web application development using zend frameworkWeb application development using zend framework
Web application development using zend framework
 
Web design and_html_part_3
Web design and_html_part_3Web design and_html_part_3
Web design and_html_part_3
 
Web design and_html_part_2
Web design and_html_part_2Web design and_html_part_2
Web design and_html_part_2
 
Web design and_html
Web design and_htmlWeb design and_html
Web design and_html
 
Visual studio ide shortcuts
Visual studio ide shortcutsVisual studio ide shortcuts
Visual studio ide shortcuts
 
Virtualization
VirtualizationVirtualization
Virtualization
 
Unreal
UnrealUnreal
Unreal
 
Unit tests in_symfony
Unit tests in_symfonyUnit tests in_symfony
Unit tests in_symfony
 
Telerik this is sayed
Telerik this is sayedTelerik this is sayed
Telerik this is sayed
 
System analysis and_design
System analysis and_designSystem analysis and_design
System analysis and_design
 
Story telling and_narrative
Story telling and_narrativeStory telling and_narrative
Story telling and_narrative
 
Some skills required to be a computer hardware engineer professional
Some skills required to be a computer hardware engineer professionalSome skills required to be a computer hardware engineer professional
Some skills required to be a computer hardware engineer professional
 
Simple demonstration on
Simple demonstration onSimple demonstration on
Simple demonstration on
 

Recently uploaded

When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...
Elena Simperl
 
Elevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object CalisthenicsElevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object Calisthenics
Dorra BARTAGUIZ
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
Jemma Hussein Allen
 
Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
Frank van Harmelen
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Ramesh Iyer
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
Prayukth K V
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
DianaGray10
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
Guy Korland
 
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
Product School
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Thierry Lestable
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
Alison B. Lowndes
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
Product School
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
ControlCase
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
RTTS
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
Safe Software
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Product School
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Albert Hoitingh
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Jeffrey Haguewood
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
KatiaHIMEUR1
 

Recently uploaded (20)

When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...
 
Elevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object CalisthenicsElevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object Calisthenics
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
 
Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
 
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
 

Symfony 2

  • 1. SYMFONY ORM - DOCTRINE Sayed Ahmed B.Sc. Eng. in Computer Science & Engineering M. Sc. in Computer Science Exploring Computing for 14+ years sayed@justetc.net http://sayed.justetc.net 10/8/2011sayed@justetc.net 1
  • 2. SYMFONY - 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:  http://components.symfony-project.org/yaml/trunk/book/02-YAML 10/8/2011 2 sayed@justetc.net
  • 4. YAML SCHEMA  # config/doctrine/schema.yml  JobeetCategory:  actAs: { Timestampable: ~ }  columns:  name: { type: string(255), notnull: true, unique: true } 10/8/2011 4 sayed@justetc.net
  • 5. YAML SCHEMA  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 }  email: { type: string(255), notnull: true }  expires_at: { type: timestamp, notnull: true }  relations:  JobeetCategory: {  onDelete: CASCADE,  local: category_id,  foreign: id,  foreignAlias: JobeetJobs  } 10/8/2011 5 sayed@justetc.net
  • 6. YAML SCHEMA  JobeetAffiliate:  actAs: { Timestampable: ~ }  columns:  url: { type: string(255), notnull: true }  email: { 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/2011 6 sayed@justetc.net
  • 7. YAML SCHEMA  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/2011 7 sayed@justetc.net
  • 8. CONFIGURE DATABASE  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/2011 8 sayed@justetc.net
  • 9. CREATING THE MODEL & DATABASE  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/2011 9 sayed@justetc.net
  • 10. CREATING THE MODEL & DATABASE  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/2011 10 sayed@justetc.net
  • 11. CREATING THE MODEL & DATABASE  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/2011 11 sayed@justetc.net
  • 12. ACCESSORS & MUTATORS  $job = new JobeetJob();  $job->setPosition('Web developer');  $job->save();  echo $job->getPosition();  $job->delete(); 10/8/2011 12 sayed@justetc.net
  • 13. DEFINE FOREIGN KEYS  $category = new JobeetCategory();  $category->setName('Programming');  $job = new JobeetJob();  $job->setCategory($category); 10/8/2011 13 sayed@justetc.net
  • 14. 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/2011 14 sayed@justetc.net
  • 15. THE DATA  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/2011 15 sayed@justetc.net
  • 16. DATA FIXTURE FILES  # data/fixtures/categories.yml  JobeetCategory:  design:  name: Design  programming:  name: Programming  manager:  name: Manager  administrator:  name: Administrator 10/8/2011 16 sayed@justetc.net
  • 17. LOAD INITIAL DATA  $ php symfony doctrine:data-load  $ php symfony doctrine:build --all --and-load 10/8/2011 17 sayed@justetc.net
  • 18. MODULES – AUTO GENERATE  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/2011 18 sayed@justetc.net
  • 19. MODULES – AUTO GENERATE  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/2011 19 sayed@justetc.net
  • 20. TEST MODULES  You can now test the job module in a browser:  http://www.jobeet.com.localhost/frontend_dev.php/job 10/8/2011 20 sayed@justetc.net
  • 21. APPENDIX - 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/2011 21 sayed@justetc.net