SlideShare a Scribd company logo
1 of 41
Beginning Zend Framework Or: How I learned to stop worrying and love the framework. Part 1: Setting up
Preparing Zend Framework ,[object Object]
Alternately, check out the framework into your pear directory.
Preparing ZF Contd. ,[object Object]
Rename zf.sh to zf and make it executable
Using Zend_Tool to set up your project ,[object Object]
Add project to apache ,[object Object]
Make the DocumentRoot the “public” directory within your  {projectname}  directory.
After reloading apache, you should be able to go to the site you just set up and see the default zend framework page!
Normal Application Setup ,[object Object]
NO php should go in public folder unless it’s simple and framework is overkill for it ,[object Object]
Directory Structure ,[object Object]
Extra classes/libraries used by the app ,[object Object],[object Object],[object Object],[object Object]
Application Directory ,[object Object]
Wrong, not classes, simple php+html files.
index.php ,[object Object]
Specifies application configuration
Load & run bootstrap
Create a database/table ,[object Object],CREATE TABLE `user` ( `user_id` INT NOT NULL AUTO_INCREMENT , `username` VARCHAR( 255 ) NOT NULL , `email` VARCHAR( 128 ) NOT NULL , `password` VARCHAR( 32 ) NOT NULL , `salt` VARCHAR( 32 ) NOT NULL , `api_key` VARCHAR( 32 ) NOT NULL , `api_secret` VARCHAR( 32 ) NOT NULL , `user_type` TINYINT NOT NULL , PRIMARY KEY ( `user_id` ), UNIQUE KEY `username` (`username`) )
Add database to app config ,[object Object],# Database resources.db.adapter = "pdo_mysql" resources.db.params.host = "localhost" resources.db.params.username = "zfclass" resources.db.params.password = "zfclass" resources.db.params.dbname =  "zfclass_ {yourname} " resources.db.isDefaultTableAdapter = true
application.ini ,[object Object]
Defined in .htaccess
Can be used to specify different databases for different environments
Configuring the layout ,[object Object]
View result html will be placed as “content” in layout
Layout can house dynamic links for header js, css, etc
Easily reached from controller or view.
Layout Contd. ,[object Object]
Add the following to your application.ini: #layout resources.layout.layout = "layout" resources.layout.layoutPath = APPLICATION_PATH "/layouts/scripts"
Module Layouts ,[object Object]
Let's load a specific admin layout for it
[object Object],{ public function preDispatch(Zend_Controller_Request_Abstract $request) { $module = strtolower($request->getParam('module')); $layout = Zend_Layout::getMvcInstance(); if ($layout->getMvcEnabled()) { switch($module) { case 'default': break; default: $layout->setLayoutPath(APPLICATION_PATH . '/modules/' . $module . '/layouts/scripts'); break; } } } } application/plugins/ModuleLayout.php
Enable the plugin ,[object Object],public function _initLayouts() { Zend_Layout::startMvc(); $this->getPluginResource('frontcontroller') ->getFrontController() ->registerPlugin(new Plugin_ModuleLayout()); }
Application general layout ,[object Object],<?php echo $this->doctype() ?> <html> <head>     <?php echo $this->headTitle() ?>     <?php echo $this->headLink() ?>     <?php echo $this->headStyle() ?>     <?php echo $this->headScript() ?> </head> <body>     <?php echo $this->layout()->content ?> </body> </html>
Create a User model ,[object Object],<?php class Model_DbTable_User extends Zend_Db_Table { protected $_name = 'user'; protected $_primary = 'user_id';
User Model Cont'd public function addUser($username, $email, $password, $user_type=1) { // generate unique id for the password salt $salt = strtolower(uniqid(rand(), true)); // and finally...one more for their initial api 'secret' key $api_secret_key = strtolower(uniqid(rand(), true)); // create a password hash to save in the database $hashed_pwd = strtolower(md5($password . $salt));
User Model... $data = array( 'username' => $username, 'email' => $email, 'password' => $hashed_pwd, 'salt' => $salt, 'user_type' => $user_type ); return $this->insert($data); }
User Model... function updateUser($id, $email, $password=null, $user_type=1) { $where = array('user_id = ?' => (int)$id); $data = array('email' => $email,'user_type'=>$user_type); if ($password !== null){ // generate unique id (again) for the password salt $salt = strtolower(uniqid(rand(), true)); $hashed_pwd = strtolower(md5($password . $salt)); $data['salt']=$salt; $data['password']=$hashed_pwd; } $this->update($data, $where); } } // End class
Autoloader ,[object Object],public function _initAutoload() { $autoloader = new Zend_Application_Module_Autoloader( array( 'namespace'=>'', 'basePath'=>APPLICATION_PATH ) ); return $autoloader; }
Database Profiling in Firebug! ,[object Object],public function _initDbprofile() { if($this->getEnvironment() == 'development') { $profiler = new Zend_Db_Profiler_Firebug('All DB  Queries'); $db = $this->getPluginResource('db'); $db = $db->getDbAdapter(); $profiler->setEnabled(true); $db->setProfiler($profiler); } }
URL Structure ,[object Object]

More Related Content

What's hot

Creating fast, dynamic ACLs in Zend Framework
Creating fast, dynamic ACLs in Zend FrameworkCreating fast, dynamic ACLs in Zend Framework
Creating fast, dynamic ACLs in Zend FrameworkWim Godden
 
Creating fast, dynamic ACLs in Zend Framework (Zend Webinar)
Creating fast, dynamic ACLs in Zend Framework (Zend Webinar)Creating fast, dynamic ACLs in Zend Framework (Zend Webinar)
Creating fast, dynamic ACLs in Zend Framework (Zend Webinar)Wim Godden
 
Rails 3 overview
Rails 3 overviewRails 3 overview
Rails 3 overviewYehuda Katz
 
Hack in the Box Keynote 2006
Hack in the Box Keynote 2006Hack in the Box Keynote 2006
Hack in the Box Keynote 2006Mark Curphey
 
Error Reporting in ZF2: form messages, custom error pages, logging
Error Reporting in ZF2: form messages, custom error pages, loggingError Reporting in ZF2: form messages, custom error pages, logging
Error Reporting in ZF2: form messages, custom error pages, loggingSteve Maraspin
 
Moving from Django Apps to Services
Moving from Django Apps to ServicesMoving from Django Apps to Services
Moving from Django Apps to ServicesCraig Kerstiens
 
Drupal 8 Services And Dependency Injection
Drupal 8 Services And Dependency InjectionDrupal 8 Services And Dependency Injection
Drupal 8 Services And Dependency InjectionPhilip Norton
 
The effective use of Django ORM
The effective use of Django ORMThe effective use of Django ORM
The effective use of Django ORMYaroslav Muravskyi
 
Getting Into Drupal 8 Configuration
Getting Into Drupal 8 ConfigurationGetting Into Drupal 8 Configuration
Getting Into Drupal 8 ConfigurationPhilip Norton
 
Content Driven Zend_Acl in the Model Layer
Content Driven Zend_Acl in the Model LayerContent Driven Zend_Acl in the Model Layer
Content Driven Zend_Acl in the Model LayerJeroen Keppens
 
深入淺出 MVC
深入淺出 MVC深入淺出 MVC
深入淺出 MVCJace Ju
 
OSCON Google App Engine Codelab - July 2010
OSCON Google App Engine Codelab - July 2010OSCON Google App Engine Codelab - July 2010
OSCON Google App Engine Codelab - July 2010ikailan
 

What's hot (20)

Creating fast, dynamic ACLs in Zend Framework
Creating fast, dynamic ACLs in Zend FrameworkCreating fast, dynamic ACLs in Zend Framework
Creating fast, dynamic ACLs in Zend Framework
 
Creating fast, dynamic ACLs in Zend Framework (Zend Webinar)
Creating fast, dynamic ACLs in Zend Framework (Zend Webinar)Creating fast, dynamic ACLs in Zend Framework (Zend Webinar)
Creating fast, dynamic ACLs in Zend Framework (Zend Webinar)
 
Django
DjangoDjango
Django
 
Ant
Ant Ant
Ant
 
Rails 3 overview
Rails 3 overviewRails 3 overview
Rails 3 overview
 
Hack in the Box Keynote 2006
Hack in the Box Keynote 2006Hack in the Box Keynote 2006
Hack in the Box Keynote 2006
 
Php frameworks
Php frameworksPhp frameworks
Php frameworks
 
Error Reporting in ZF2: form messages, custom error pages, logging
Error Reporting in ZF2: form messages, custom error pages, loggingError Reporting in ZF2: form messages, custom error pages, logging
Error Reporting in ZF2: form messages, custom error pages, logging
 
Moving from Django Apps to Services
Moving from Django Apps to ServicesMoving from Django Apps to Services
Moving from Django Apps to Services
 
Drupal 8 Services And Dependency Injection
Drupal 8 Services And Dependency InjectionDrupal 8 Services And Dependency Injection
Drupal 8 Services And Dependency Injection
 
The effective use of Django ORM
The effective use of Django ORMThe effective use of Django ORM
The effective use of Django ORM
 
Perl5i
Perl5iPerl5i
Perl5i
 
Drupal 8 Services
Drupal 8 ServicesDrupal 8 Services
Drupal 8 Services
 
Getting Into Drupal 8 Configuration
Getting Into Drupal 8 ConfigurationGetting Into Drupal 8 Configuration
Getting Into Drupal 8 Configuration
 
Zend ACL Basics
Zend ACL BasicsZend ACL Basics
Zend ACL Basics
 
Content Driven Zend_Acl in the Model Layer
Content Driven Zend_Acl in the Model LayerContent Driven Zend_Acl in the Model Layer
Content Driven Zend_Acl in the Model Layer
 
深入淺出 MVC
深入淺出 MVC深入淺出 MVC
深入淺出 MVC
 
PhpBB meets Symfony2
PhpBB meets Symfony2PhpBB meets Symfony2
PhpBB meets Symfony2
 
OSCON Google App Engine Codelab - July 2010
OSCON Google App Engine Codelab - July 2010OSCON Google App Engine Codelab - July 2010
OSCON Google App Engine Codelab - July 2010
 
Symfony2 - OSIDays 2010
Symfony2 - OSIDays 2010Symfony2 - OSIDays 2010
Symfony2 - OSIDays 2010
 

Similar to Zend Framework 1.9 Setup & Using Zend_Tool

CodeIgniter PHP MVC Framework
CodeIgniter PHP MVC FrameworkCodeIgniter PHP MVC Framework
CodeIgniter PHP MVC FrameworkBo-Yi Wu
 
Intro To Mvc Development In Php
Intro To Mvc Development In PhpIntro To Mvc Development In Php
Intro To Mvc Development In Phpfunkatron
 
Create a web-app with Cgi Appplication
Create a web-app with Cgi AppplicationCreate a web-app with Cgi Appplication
Create a web-app with Cgi Appplicationolegmmiller
 
Zend - Installation And Sample Project Creation
Zend - Installation And Sample Project Creation Zend - Installation And Sample Project Creation
Zend - Installation And Sample Project Creation Compare Infobase Limited
 
Exploring Symfony's Code
Exploring Symfony's CodeExploring Symfony's Code
Exploring Symfony's CodeWildan Maulana
 
Unit testing after Zend Framework 1.8
Unit testing after Zend Framework 1.8Unit testing after Zend Framework 1.8
Unit testing after Zend Framework 1.8Michelangelo van Dam
 
Utilization of zend an ultimate alternate for intense data processing
Utilization of zend  an ultimate alternate for intense data processingUtilization of zend  an ultimate alternate for intense data processing
Utilization of zend an ultimate alternate for intense data processingCareer at Elsner
 
Building Web Services with Zend Framework (PHP Benelux meeting 20100713 Vliss...
Building Web Services with Zend Framework (PHP Benelux meeting 20100713 Vliss...Building Web Services with Zend Framework (PHP Benelux meeting 20100713 Vliss...
Building Web Services with Zend Framework (PHP Benelux meeting 20100713 Vliss...King Foo
 
Drupal Day 2012 - Automating Drupal Development: Make!les, Features and Beyond
Drupal Day 2012 - Automating Drupal Development: Make!les, Features and BeyondDrupal Day 2012 - Automating Drupal Development: Make!les, Features and Beyond
Drupal Day 2012 - Automating Drupal Development: Make!les, Features and BeyondDrupalDay
 
Валентин Мацвейко та Владислав Мойсеєнко — D8: Migrate Yourself: code->module...
Валентин Мацвейко та Владислав Мойсеєнко — D8: Migrate Yourself: code->module...Валентин Мацвейко та Владислав Мойсеєнко — D8: Migrate Yourself: code->module...
Валентин Мацвейко та Владислав Мойсеєнко — D8: Migrate Yourself: code->module...LEDC 2016
 
Migrate yourself. code -> module -> mind
Migrate yourself. code -> module -> mindMigrate yourself. code -> module -> mind
Migrate yourself. code -> module -> mindValentine Matsveiko
 
Childthemes ottawa-word camp-1919
Childthemes ottawa-word camp-1919Childthemes ottawa-word camp-1919
Childthemes ottawa-word camp-1919Paul Bearne
 
Modular Test-driven SPAs with Spring and AngularJS
Modular Test-driven SPAs with Spring and AngularJSModular Test-driven SPAs with Spring and AngularJS
Modular Test-driven SPAs with Spring and AngularJSGunnar Hillert
 
Introduction to Zend framework
Introduction to Zend framework Introduction to Zend framework
Introduction to Zend framework Matteo Magni
 
WordPress Structure and Best Practices
WordPress Structure and Best PracticesWordPress Structure and Best Practices
WordPress Structure and Best Practicesmarkparolisi
 

Similar to Zend Framework 1.9 Setup & Using Zend_Tool (20)

CodeIgniter PHP MVC Framework
CodeIgniter PHP MVC FrameworkCodeIgniter PHP MVC Framework
CodeIgniter PHP MVC Framework
 
Introduction to Zend Framework
Introduction to Zend FrameworkIntroduction to Zend Framework
Introduction to Zend Framework
 
Intro To Mvc Development In Php
Intro To Mvc Development In PhpIntro To Mvc Development In Php
Intro To Mvc Development In Php
 
Create a web-app with Cgi Appplication
Create a web-app with Cgi AppplicationCreate a web-app with Cgi Appplication
Create a web-app with Cgi Appplication
 
Zend framework
Zend frameworkZend framework
Zend framework
 
Extend sdk
Extend sdkExtend sdk
Extend sdk
 
Zend - Installation And Sample Project Creation
Zend - Installation And Sample Project Creation Zend - Installation And Sample Project Creation
Zend - Installation And Sample Project Creation
 
Exploring Symfony's Code
Exploring Symfony's CodeExploring Symfony's Code
Exploring Symfony's Code
 
Having Fun with Play
Having Fun with PlayHaving Fun with Play
Having Fun with Play
 
Unit testing after Zend Framework 1.8
Unit testing after Zend Framework 1.8Unit testing after Zend Framework 1.8
Unit testing after Zend Framework 1.8
 
Utilization of zend an ultimate alternate for intense data processing
Utilization of zend  an ultimate alternate for intense data processingUtilization of zend  an ultimate alternate for intense data processing
Utilization of zend an ultimate alternate for intense data processing
 
Building Web Services with Zend Framework (PHP Benelux meeting 20100713 Vliss...
Building Web Services with Zend Framework (PHP Benelux meeting 20100713 Vliss...Building Web Services with Zend Framework (PHP Benelux meeting 20100713 Vliss...
Building Web Services with Zend Framework (PHP Benelux meeting 20100713 Vliss...
 
Drupal Day 2012 - Automating Drupal Development: Make!les, Features and Beyond
Drupal Day 2012 - Automating Drupal Development: Make!les, Features and BeyondDrupal Day 2012 - Automating Drupal Development: Make!les, Features and Beyond
Drupal Day 2012 - Automating Drupal Development: Make!les, Features and Beyond
 
Валентин Мацвейко та Владислав Мойсеєнко — D8: Migrate Yourself: code->module...
Валентин Мацвейко та Владислав Мойсеєнко — D8: Migrate Yourself: code->module...Валентин Мацвейко та Владислав Мойсеєнко — D8: Migrate Yourself: code->module...
Валентин Мацвейко та Владислав Мойсеєнко — D8: Migrate Yourself: code->module...
 
Migrate yourself. code -> module -> mind
Migrate yourself. code -> module -> mindMigrate yourself. code -> module -> mind
Migrate yourself. code -> module -> mind
 
Childthemes ottawa-word camp-1919
Childthemes ottawa-word camp-1919Childthemes ottawa-word camp-1919
Childthemes ottawa-word camp-1919
 
Zend Framework
Zend FrameworkZend Framework
Zend Framework
 
Modular Test-driven SPAs with Spring and AngularJS
Modular Test-driven SPAs with Spring and AngularJSModular Test-driven SPAs with Spring and AngularJS
Modular Test-driven SPAs with Spring and AngularJS
 
Introduction to Zend framework
Introduction to Zend framework Introduction to Zend framework
Introduction to Zend framework
 
WordPress Structure and Best Practices
WordPress Structure and Best PracticesWordPress Structure and Best Practices
WordPress Structure and Best Practices
 

Recently uploaded

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 MenDelhi Call girls
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
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 productivityPrincipled Technologies
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
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 2024The Digital Insurer
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
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 interpreternaman860154
 
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 MenDelhi Call girls
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsRoshan Dwivedi
 
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.pptxMalak Abu Hammad
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...gurkirankumar98700
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 

Recently uploaded (20)

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
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
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
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
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
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
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
 
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
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
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
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 

Zend Framework 1.9 Setup & Using Zend_Tool

  • 1. Beginning Zend Framework Or: How I learned to stop worrying and love the framework. Part 1: Setting up
  • 2.
  • 3. Alternately, check out the framework into your pear directory.
  • 4.
  • 5. Rename zf.sh to zf and make it executable
  • 6.
  • 7.
  • 8. Make the DocumentRoot the “public” directory within your {projectname} directory.
  • 9. After reloading apache, you should be able to go to the site you just set up and see the default zend framework page!
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15. Wrong, not classes, simple php+html files.
  • 16.
  • 18. Load & run bootstrap
  • 19.
  • 20.
  • 21.
  • 23. Can be used to specify different databases for different environments
  • 24.
  • 25. View result html will be placed as “content” in layout
  • 26. Layout can house dynamic links for header js, css, etc
  • 27. Easily reached from controller or view.
  • 28.
  • 29. Add the following to your application.ini: #layout resources.layout.layout = &quot;layout&quot; resources.layout.layoutPath = APPLICATION_PATH &quot;/layouts/scripts&quot;
  • 30.
  • 31. Let's load a specific admin layout for it
  • 32.
  • 33.
  • 34.
  • 35.
  • 36. User Model Cont'd public function addUser($username, $email, $password, $user_type=1) { // generate unique id for the password salt $salt = strtolower(uniqid(rand(), true)); // and finally...one more for their initial api 'secret' key $api_secret_key = strtolower(uniqid(rand(), true)); // create a password hash to save in the database $hashed_pwd = strtolower(md5($password . $salt));
  • 37. User Model... $data = array( 'username' => $username, 'email' => $email, 'password' => $hashed_pwd, 'salt' => $salt, 'user_type' => $user_type ); return $this->insert($data); }
  • 38. User Model... function updateUser($id, $email, $password=null, $user_type=1) { $where = array('user_id = ?' => (int)$id); $data = array('email' => $email,'user_type'=>$user_type); if ($password !== null){ // generate unique id (again) for the password salt $salt = strtolower(uniqid(rand(), true)); $hashed_pwd = strtolower(md5($password . $salt)); $data['salt']=$salt; $data['password']=$hashed_pwd; } $this->update($data, $where); } } // End class
  • 39.
  • 40.
  • 41.
  • 46.
  • 47. Regex
  • 49.
  • 50.
  • 51.
  • 52.
  • 53.
  • 54. Rename class in file to Admin_UserController
  • 55.
  • 56. Open User controller file in an editor...
  • 57. public function createuserAction() { // create form $form = new Zend_Form(); $form->setMethod('post'); $form->addElement('text','username', array( 'label' =>'User name', 'required'=>true, 'filters'=>array('StringTrim') )); $form->addElement('password','password',array( 'label'=>'Password', 'required'=>true, 'filters'=>array('StringTrim') )); $form->addElement('text','email',array( 'label'=>'Email address', 'required'=>true, 'filters'=>array('StringTrim'), 'validators'=>array('EmailAddress') )); Create a form programatically!
  • 58. $form->addElement('captcha','captcha',array( 'label'=>'Enter the letters below', 'required'=>true, 'captcha'=>array( 'captcha'=>'Figlet', 'wordLen'=>5, 'timeout'=>300 ) )); $form->addElement('submit','Save',array( 'ignore'=>true, 'label'=>'Save New User' )); // End form
  • 59. $request = $this->getRequest(); if($request->isPost()) { if($form->isValid($request->getPost())) { $data = $form->getValues(); $user = new Model_DbTable_User(); if($user->addUser( $data['username'], $data['email'], $data['password'],2)) // 2 for admin { $this->view->message = 'User created'; } else { $this->view->message = 'Something bad happened.'; } } } $this->view->form = $form; } // End function
  • 60. Create View application/modules/admin/views/scripts/user/createuser.php <?php if(isset($this->message)) { ?><h1><?=$this->message ?></h1><?php } ?> Create your new user. <?php $this->form->setAction($this->url()); echo $this->form; ?>
  • 61.
  • 63.
  • 64. zf create action login user 1 admin
  • 65. Open it back up and find the loginAction method
  • 66. public function loginAction() { $form = new Zend_Form(); $form->setMethod('post'); $form->addElement('text','username', array( 'label' =>'User name', 'required'=>true, 'filters'=>array('StringTrim') )); $form->addElement('password','password',array( 'label'=>'Password', 'required'=>true, 'filters'=>array('StringTrim') )); $form->addElement('submit','submit',array( 'label'=>'Login', 'ignore'=>true ));
  • 67. $request = $this->getRequest(); $data = $request->getPost(); if($request->isPost() && $form->isValid($data)) { $u = new Model_DbTable_User(); $auth = new Zend_Auth_Adapter_DbTable($u->getAdapter() ,'user','username','password', &quot;MD5(CONCAT(?,salt)) AND user_type=2&quot; ); $auth->setIdentity($data['username'])->setCredential( $data['password'] ); $mainauth = Zend_Auth::getInstance(); $result = $mainauth->authenticate($auth); if($result->isValid()) { $this->view->message = 'You are now logged in.'; } else { $m = $result->getMessages(); $this->view->message = $m[0]; } } $this->view->form = $form; }// End function
  • 68.
  • 69. Create a login “helper” Edit application/modules/admin/views/helpers/LoginLink.php <?php class Admin_View_Helper_LoginLink extends Zend_View_Helper_Abstract { public function loginLink() { $auth = Zend_Auth::getInstance(); $front = Zend_Controller_Front::getInstance(); if($auth->hasIdentity()) { $username = $auth->getIdentity(); return &quot;Hello, $username [<a href='&quot;.$front->getBaseUrl(). &quot;/admin/user/logout'>Logout</a>]&quot;; } else { return '[<a href=&quot;'.$front->getBaseUrl(). '/admin/user/login&quot;>Login</a>]'; } } }
  • 70.
  • 71.
  • 72. If not, I can continue at the next meeting.