SlideShare una empresa de Scribd logo
1 de 9
Building a site in 15 minutes
      With the Yii Framework
What is Yii?
• MVC Framework
   – Model, View, Controller
• PHP
• Built to be fast, secure and professional
   – Faster than Cake, Codeigniter, Zend1
• Lots of plumbing already in place
   – Build a site quickly, don’t reinvent the wheel
• Gii GUI for quickly creating application scaffolding
   – Web-based code generation
                                            1http://www.yiiframework.com/performance/
How do we start?
• Basic VM image provided – run with VirtualBox
   – Already set-up : CentOS 6, Nginx, PHP, MySQL, Yii
• Some initial personlisation
   – Login as root, (password yii)
   – Create a user
      • useradd -G wheel akelk
      • passwd akelk
      • visudo

      • Make sure wheel can run sudo
   – Login as yourself (using putty)
Creating our site with Yii
• Run yiic
   – Directory already in place, navigate to /var/www/html/yiisite
   – Initially we run using sudo as all files are owned by nginx
   – sudo ../../yii/framework/yiic webapp .

   – Then we’ll change ownership and give ourselves write
     permissions for easier development purposes
   – sudo chown -R nginx:wheel .; sudo chmod -R g+w .

• Now we’re ready to visit our site
   – Fire up your favourite browser
   – Visit the main Yii URL (e.g. http://192.168.0.107/)
   – Explore the site
Configuring our site
• Main config file is in protected/config/main.php
   – Set up access to the mysql database
      •    'db'=>array(
            'connectionString' => 'mysql:host=localhost;dbname=iproperty',
            'emulatePrepare' => true,
            'username' => 'iproperty',
            'password' => 'iproperty',
            'charset' => 'utf8',
          ),

   – Enable the Gii GUI
      • 'modules'=>array(
          'gii'=>array(
            'class'=>'system.gii.GiiModule',
            'password'=>'iproperty',
            'ipFilters'=>array('127.0.0.1','::1','192.168.*'),
          ),
        ),
Create the scaffolding
• Naïve SQL schema
   –   CREATE TABLE `listing` (
         `id` int(11) NOT NULL AUTO_INCREMENT,
         `title` varchar(255) DEFAULT NULL,
         `description` text,
         `state` varchar(50) DEFAULT NULL,
         `area` varchar(50) DEFAULT NULL,
         `price` decimal(10,0) DEFAULT NULL,
         `status` char(1) DEFAULT NULL,
         `issale` tinyint(1) DEFAULT NULL,
         `isrent` tinyint(1) DEFAULT NULL,
         PRIMARY KEY (`id`)
       ) ENGINE=InnoDB DEFAULT CHARSET=latin1;

• Fire up gii and login
   – http://192.168.0.107/index.php?r=gii
   – Password is iproperty
• Create model (named listing)
• Create CRUD (using Listing model and listing controller)
Try it out
• Add a new listing or two
   – Using the create action
• View the listings
   – Using the view action
• Manage listings
   – Using the manage action
• But no search?
   – Only accessible via manage when you’re logged in
   – Let’s create one!
Extending our site
• Create a search action
   – Very similar to admin
• Allow access to all
   – Edit the accessRules method
• Create a view to render it
   – Similar to admin but use a CLinkColumn for the grid display
   – array(
       'class'=>'CLinkColumn',
       'urlExpression'=>
       'Yii::app()->createUrl("listing/view",array("id"=>$data->id))',
     ),

   – Re-use _search.php from the admin action
Review
• For simple CRUD, all you need is a sensible database schema,
  ActiveRecord and Gii; relationships will help you navigate
  between objects.
• You can add new actions – remember to keep the controllers
  skinny, the models fat
• There’s loads of helper classes:
   –   HTTP Responses (including errors)
   –   Caching (File, MemCache, Opcode caching)
   –   Data structures (Maps, Iterators, Queues)
   –   Validators (String, URL, Number, Email, etc)
   –   Web widgets (grids, forms, inputs)
   –   Web services (SOAP, REST)
   –   I18n (Translating, Messages, Date formats, etc)
• Read the documentation

Más contenido relacionado

La actualidad más candente

Introduction to MVC Web Framework with CodeIgniter
Introduction to MVC Web Framework with CodeIgniterIntroduction to MVC Web Framework with CodeIgniter
Introduction to MVC Web Framework with CodeIgniter
Pongsakorn U-chupala
 

La actualidad más candente (20)

Codeigniter
CodeigniterCodeigniter
Codeigniter
 
Yii2 by Peter Jack Kambey
Yii2 by Peter Jack KambeyYii2 by Peter Jack Kambey
Yii2 by Peter Jack Kambey
 
Php Frameworks
Php FrameworksPhp Frameworks
Php Frameworks
 
Introduction To CodeIgniter
Introduction To CodeIgniterIntroduction To CodeIgniter
Introduction To CodeIgniter
 
Introduction to MVC Web Framework with CodeIgniter
Introduction to MVC Web Framework with CodeIgniterIntroduction to MVC Web Framework with CodeIgniter
Introduction to MVC Web Framework with CodeIgniter
 
Having fun with code igniter
Having fun with code igniterHaving fun with code igniter
Having fun with code igniter
 
Codeigniter Introduction
Codeigniter IntroductionCodeigniter Introduction
Codeigniter Introduction
 
Mainframe, the fast PHP framework
Mainframe, the fast PHP frameworkMainframe, the fast PHP framework
Mainframe, the fast PHP framework
 
Codeigniter, a MVC framework for beginner
Codeigniter, a MVC framework for beginnerCodeigniter, a MVC framework for beginner
Codeigniter, a MVC framework for beginner
 
Introduction to CodeIgniter
Introduction to CodeIgniterIntroduction to CodeIgniter
Introduction to CodeIgniter
 
PHP Indonesia Meetup - What's New in Yii2 and PHP5.5
PHP Indonesia Meetup - What's New in Yii2 and PHP5.5PHP Indonesia Meetup - What's New in Yii2 and PHP5.5
PHP Indonesia Meetup - What's New in Yii2 and PHP5.5
 
Apache Syncope 2.0 Enduser UI
Apache Syncope 2.0 Enduser UIApache Syncope 2.0 Enduser UI
Apache Syncope 2.0 Enduser UI
 
Yii 2.0 overview - 1 of 2
Yii 2.0 overview - 1 of 2Yii 2.0 overview - 1 of 2
Yii 2.0 overview - 1 of 2
 
Scaling Yii2 Application
Scaling Yii2 ApplicationScaling Yii2 Application
Scaling Yii2 Application
 
Identity in ASP.NET Core
Identity in ASP.NET CoreIdentity in ASP.NET Core
Identity in ASP.NET Core
 
PHP Framework Battle
PHP Framework BattlePHP Framework Battle
PHP Framework Battle
 
Panada: An Introduction by Iskandar Soesman
Panada: An Introduction by Iskandar SoesmanPanada: An Introduction by Iskandar Soesman
Panada: An Introduction by Iskandar Soesman
 
Build your own dev tools with salesforce cli plugin generator
Build your own dev tools with salesforce cli plugin generatorBuild your own dev tools with salesforce cli plugin generator
Build your own dev tools with salesforce cli plugin generator
 
Asp.Net Identity
Asp.Net IdentityAsp.Net Identity
Asp.Net Identity
 
Introduction to ASP.NET 5
Introduction to ASP.NET 5Introduction to ASP.NET 5
Introduction to ASP.NET 5
 

Destacado

YiiConf 2012 - Alexander Makarov - Yii2, what's new
YiiConf 2012 - Alexander Makarov - Yii2, what's newYiiConf 2012 - Alexander Makarov - Yii2, what's new
YiiConf 2012 - Alexander Makarov - Yii2, what's new
Alexander Makarov
 
1ST TECH TALK: "Yii : The MVC framework" by Benedicto B. Balilo Jr.
1ST TECH TALK: "Yii : The MVC framework" by Benedicto B. Balilo Jr.1ST TECH TALK: "Yii : The MVC framework" by Benedicto B. Balilo Jr.
1ST TECH TALK: "Yii : The MVC framework" by Benedicto B. Balilo Jr.
Bicol IT.org
 

Destacado (20)

Yii Framework
Yii FrameworkYii Framework
Yii Framework
 
Yii framework
Yii frameworkYii framework
Yii framework
 
Yii Introduction
Yii IntroductionYii Introduction
Yii Introduction
 
Introduction to Yii & performance comparison with Drupal
Introduction to Yii & performance comparison with DrupalIntroduction to Yii & performance comparison with Drupal
Introduction to Yii & performance comparison with Drupal
 
Introduce Yii
Introduce YiiIntroduce Yii
Introduce Yii
 
Yii Introduction
Yii IntroductionYii Introduction
Yii Introduction
 
Yii Training session-1
Yii Training session-1Yii Training session-1
Yii Training session-1
 
FUTEX 2015 Programme gb
FUTEX 2015 Programme gbFUTEX 2015 Programme gb
FUTEX 2015 Programme gb
 
YiiConf 2012 - Alexander Makarov - Yii2, what's new
YiiConf 2012 - Alexander Makarov - Yii2, what's newYiiConf 2012 - Alexander Makarov - Yii2, what's new
YiiConf 2012 - Alexander Makarov - Yii2, what's new
 
1ST TECH TALK: "Yii : The MVC framework" by Benedicto B. Balilo Jr.
1ST TECH TALK: "Yii : The MVC framework" by Benedicto B. Balilo Jr.1ST TECH TALK: "Yii : The MVC framework" by Benedicto B. Balilo Jr.
1ST TECH TALK: "Yii : The MVC framework" by Benedicto B. Balilo Jr.
 
PHP Unit Testing in Yii
PHP Unit Testing in YiiPHP Unit Testing in Yii
PHP Unit Testing in Yii
 
Introduction to YII framework
Introduction to YII frameworkIntroduction to YII framework
Introduction to YII framework
 
Devconf 2011 - PHP - How Yii framework is developed
Devconf 2011 - PHP - How Yii framework is developedDevconf 2011 - PHP - How Yii framework is developed
Devconf 2011 - PHP - How Yii framework is developed
 
Yii php framework_honey
Yii php framework_honeyYii php framework_honey
Yii php framework_honey
 
Yii workshop
Yii workshopYii workshop
Yii workshop
 
Cancer de mama
Cancer de mamaCancer de mama
Cancer de mama
 
Yii framework
Yii frameworkYii framework
Yii framework
 
Nram presentation 3
Nram presentation 3Nram presentation 3
Nram presentation 3
 
Futex Scaling for Multi-core Systems
Futex Scaling for Multi-core SystemsFutex Scaling for Multi-core Systems
Futex Scaling for Multi-core Systems
 
Slideshare ppt
Slideshare pptSlideshare ppt
Slideshare ppt
 

Similar a A site in 15 minutes with yii

Power on, Powershell
Power on, PowershellPower on, Powershell
Power on, Powershell
Roo7break
 
You must know about CodeIgniter Popular Library
You must know about CodeIgniter Popular LibraryYou must know about CodeIgniter Popular Library
You must know about CodeIgniter Popular Library
Bo-Yi Wu
 
Staging Drupal 8 31 09 1 3
Staging Drupal 8 31 09 1 3Staging Drupal 8 31 09 1 3
Staging Drupal 8 31 09 1 3
Drupalcon Paris
 

Similar a A site in 15 minutes with yii (20)

Icinga 2009 at OSMC
Icinga 2009 at OSMCIcinga 2009 at OSMC
Icinga 2009 at OSMC
 
Power on, Powershell
Power on, PowershellPower on, Powershell
Power on, Powershell
 
OSMC 2009 | Icinga by Icinga Team
OSMC 2009 | Icinga by Icinga TeamOSMC 2009 | Icinga by Icinga Team
OSMC 2009 | Icinga by Icinga Team
 
You must know about CodeIgniter Popular Library
You must know about CodeIgniter Popular LibraryYou must know about CodeIgniter Popular Library
You must know about CodeIgniter Popular Library
 
Get things done with Yii - quickly build webapplications
Get things done with Yii - quickly build webapplicationsGet things done with Yii - quickly build webapplications
Get things done with Yii - quickly build webapplications
 
Google App Engine
Google App EngineGoogle App Engine
Google App Engine
 
WordPress CLI in-depth
WordPress CLI in-depthWordPress CLI in-depth
WordPress CLI in-depth
 
Making Joomla Insecure - Explaining security by breaking it
Making Joomla Insecure - Explaining security by breaking itMaking Joomla Insecure - Explaining security by breaking it
Making Joomla Insecure - Explaining security by breaking it
 
Drupal 8 Configuration Management
Drupal 8 Configuration ManagementDrupal 8 Configuration Management
Drupal 8 Configuration Management
 
How to keep Drupal relevant in the Git-based and API-driven CMS era - BADCamp
How to keep Drupal relevant in the Git-based and API-driven CMS era - BADCampHow to keep Drupal relevant in the Git-based and API-driven CMS era - BADCamp
How to keep Drupal relevant in the Git-based and API-driven CMS era - BADCamp
 
Windows Server 2008 (PowerShell Scripting Uygulamaları)
Windows Server 2008 (PowerShell Scripting Uygulamaları)Windows Server 2008 (PowerShell Scripting Uygulamaları)
Windows Server 2008 (PowerShell Scripting Uygulamaları)
 
Rapid Application Development with CakePHP 1.3
Rapid Application Development with CakePHP 1.3Rapid Application Development with CakePHP 1.3
Rapid Application Development with CakePHP 1.3
 
Refresh Austin - Intro to Dexy
Refresh Austin - Intro to DexyRefresh Austin - Intro to Dexy
Refresh Austin - Intro to Dexy
 
Staging Drupal 8 31 09 1 3
Staging Drupal 8 31 09 1 3Staging Drupal 8 31 09 1 3
Staging Drupal 8 31 09 1 3
 
Cobbler, Func and Puppet: Tools for Large Scale Environments
Cobbler, Func and Puppet: Tools for Large Scale EnvironmentsCobbler, Func and Puppet: Tools for Large Scale Environments
Cobbler, Func and Puppet: Tools for Large Scale Environments
 
Cobbler, Func and Puppet: Tools for Large Scale Environments
Cobbler, Func and Puppet: Tools for Large Scale EnvironmentsCobbler, Func and Puppet: Tools for Large Scale Environments
Cobbler, Func and Puppet: Tools for Large Scale Environments
 
How to discover 1352 Wordpress plugin 0days in one hour (not really)
How to discover 1352 Wordpress plugin 0days in one hour (not really)How to discover 1352 Wordpress plugin 0days in one hour (not really)
How to discover 1352 Wordpress plugin 0days in one hour (not really)
 
HadoopCon 2016 - 用 Jupyter Notebook Hold 住一個上線 Spark Machine Learning 專案實戰
HadoopCon 2016  - 用 Jupyter Notebook Hold 住一個上線 Spark  Machine Learning 專案實戰HadoopCon 2016  - 用 Jupyter Notebook Hold 住一個上線 Spark  Machine Learning 專案實戰
HadoopCon 2016 - 用 Jupyter Notebook Hold 住一個上線 Spark Machine Learning 專案實戰
 
Drupal Security from Drupalcamp Bratislava
Drupal Security from Drupalcamp BratislavaDrupal Security from Drupalcamp Bratislava
Drupal Security from Drupalcamp Bratislava
 
Drupal Security Hardening
Drupal Security HardeningDrupal Security Hardening
Drupal Security Hardening
 

Último

IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
Enterprise Knowledge
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 

Último (20)

IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 

A site in 15 minutes with yii

  • 1. Building a site in 15 minutes With the Yii Framework
  • 2. What is Yii? • MVC Framework – Model, View, Controller • PHP • Built to be fast, secure and professional – Faster than Cake, Codeigniter, Zend1 • Lots of plumbing already in place – Build a site quickly, don’t reinvent the wheel • Gii GUI for quickly creating application scaffolding – Web-based code generation 1http://www.yiiframework.com/performance/
  • 3. How do we start? • Basic VM image provided – run with VirtualBox – Already set-up : CentOS 6, Nginx, PHP, MySQL, Yii • Some initial personlisation – Login as root, (password yii) – Create a user • useradd -G wheel akelk • passwd akelk • visudo • Make sure wheel can run sudo – Login as yourself (using putty)
  • 4. Creating our site with Yii • Run yiic – Directory already in place, navigate to /var/www/html/yiisite – Initially we run using sudo as all files are owned by nginx – sudo ../../yii/framework/yiic webapp . – Then we’ll change ownership and give ourselves write permissions for easier development purposes – sudo chown -R nginx:wheel .; sudo chmod -R g+w . • Now we’re ready to visit our site – Fire up your favourite browser – Visit the main Yii URL (e.g. http://192.168.0.107/) – Explore the site
  • 5. Configuring our site • Main config file is in protected/config/main.php – Set up access to the mysql database • 'db'=>array( 'connectionString' => 'mysql:host=localhost;dbname=iproperty', 'emulatePrepare' => true, 'username' => 'iproperty', 'password' => 'iproperty', 'charset' => 'utf8', ), – Enable the Gii GUI • 'modules'=>array( 'gii'=>array( 'class'=>'system.gii.GiiModule', 'password'=>'iproperty', 'ipFilters'=>array('127.0.0.1','::1','192.168.*'), ), ),
  • 6. Create the scaffolding • Naïve SQL schema – CREATE TABLE `listing` ( `id` int(11) NOT NULL AUTO_INCREMENT, `title` varchar(255) DEFAULT NULL, `description` text, `state` varchar(50) DEFAULT NULL, `area` varchar(50) DEFAULT NULL, `price` decimal(10,0) DEFAULT NULL, `status` char(1) DEFAULT NULL, `issale` tinyint(1) DEFAULT NULL, `isrent` tinyint(1) DEFAULT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1; • Fire up gii and login – http://192.168.0.107/index.php?r=gii – Password is iproperty • Create model (named listing) • Create CRUD (using Listing model and listing controller)
  • 7. Try it out • Add a new listing or two – Using the create action • View the listings – Using the view action • Manage listings – Using the manage action • But no search? – Only accessible via manage when you’re logged in – Let’s create one!
  • 8. Extending our site • Create a search action – Very similar to admin • Allow access to all – Edit the accessRules method • Create a view to render it – Similar to admin but use a CLinkColumn for the grid display – array( 'class'=>'CLinkColumn', 'urlExpression'=> 'Yii::app()->createUrl("listing/view",array("id"=>$data->id))', ), – Re-use _search.php from the admin action
  • 9. Review • For simple CRUD, all you need is a sensible database schema, ActiveRecord and Gii; relationships will help you navigate between objects. • You can add new actions – remember to keep the controllers skinny, the models fat • There’s loads of helper classes: – HTTP Responses (including errors) – Caching (File, MemCache, Opcode caching) – Data structures (Maps, Iterators, Queues) – Validators (String, URL, Number, Email, etc) – Web widgets (grids, forms, inputs) – Web services (SOAP, REST) – I18n (Translating, Messages, Date formats, etc) • Read the documentation