810 likes | 927 Vues
Web Technology Solutions. Class: Three-Tier Application Architecture and more PHP Programming Practice. Date : 1/12/2012. Tonight. Three Tier Architecture PHP and its oppositionPHP Syntax Review and Simple Debugging Techniques.Lab. Lab Preview.
E N D
Web Technology Solutions • Class: Three-Tier Application Architecture and more PHP Programming Practice Date : 1/12/2012
Tonight • Three Tier Architecture PHP and its oppositionPHP Syntax Review and Simple Debugging Techniques.Lab
Lab Preview • PHP Basics: Working with variables, conditionals, managing arrays, clean commenting, and debugging. • Homework: documentation and design.
System Recap • software system is a collection of interacting software components. Recall that the components of a system can also be considered as systems, called subsystems. Those subsystems (components) of a system that directly interact with each other do so through interfaces
Server Side Systems • Allow for High Availability(HA), Dynamic Data Interaction, Data Storage Modern web apps excel at all three - twitter, Facebook, digg, flickr, etc
Selecting Systems • Being a technologist is understanding which system offers their client the maximum of benefits. How do you choose? • Modern Web Applications collect various subsystems and make them their own system. • Solves for HA, Interaction, Storage and Retrieval.
System Models • An Architecture Defines: What Important Systems are Needed and their Interfaces. • A model is a simplified way to represent or think about a system of interest. Models are often represented using diagrams to show how components are related and organized. • Two System Examples: Web App, Databases.
Common Models • Database
Common Models • Web Servers
Common Models • Internet
Common Models • Load Balancer
Web Systems • Web Applications should scale gracefully. LAMP allows for that • Note: the load balancer • Multiple Redundant Web Servers • Multiple DBs (master and slave) • What is missing? CDN’s
MySQL Example • MySQL comes with many sub-systems
How to Document a Model • Models and Architecture add value as design documents. • Include only the most important components of a system. • Hide Details
How to Document a Model • Hide the details • Reduce complexity and increases conceptualization making for easy buy-off. • Avoid information overload • Stakeholders and non-techies don’t care. • Example: Three Tier system
3-Tier Web System • Typical Web solution where each tier provides specific types of service. • 1. Presentation Layer: produces the user interface • 2. Business Logic Layer: implements applications functionality • 3. Data services Layer: provides data storage for the application • Example: Detailed Model (note subsystems)
PHP • PHP: Ubiquitous. Easy to host and learn. • PHP: tied in harmony to Linux, Apache, MySQL. Loads of devs and huge community. • PHP is criticized because it is not strict in its promotion of best-of-breed coding practices. See php.net comments. • PHP and PECL extend PHP • PHP is liberating to rapidly develop ‘simple sites’ but scalable web apps?
PHP vs. Other • The debate with PHP vs. others. Understand each has their benefit. • Ruby • C# • Java • Python
PHP vs. Ruby • PHP vs. Ruby (Rails) • Syntax akin to smalltalk. PHP is C based. • PHP easier to host (rails ssh, root) • PHP not strict. Ruby all OOP (everything object) • PHP has many frameworks, • Rails is MVC
PHP vs. C# • PHP vs. C# (.net) • C# tied to the .NET framework • C# bindings to allow for desktop apps • Akin to Java in ability and behavior. • has an MVC framework.
PHP vs. Python • PHP vs. Python (Django) • Python has strict syntax control structure • Python benchmarks • PHP primarily web based - python extends beyond the web. • Bad programmers are able to write bad programs in any language
Best Practice • Bad PHP: Three layers all in one (spaghetti code) • Good PHP (MVC Design Pattern) • Presentation: Templates (minimal PHP) • Logic: All PHP to handle data transaction and state • Business: PHP is used to abstract the Database. No real native SQL calls. PHP can be used for good or bad.
Best Practice Tip • Always develop a high level system architecture as part of the documentation deliverable. • Clients love to know you’re taking care of the details.
Best Practice Tip • Prepare detailed low-level system and system diagrams for areas of risk or what I would be personally responsible for and will require prototyping. • risk: something I haven’t coded before
Best Practice Tip • Focus on Rapid Application Development Techniques • Be Agile • Update quickly • Verify assumptions • Ask questions, find improvements
Best Practice Tip • Keep Documentation Current. Things change!
Final Project Documentation Start now. Lesson 3: Start documentingLesson 4: Much prototyping.Lesson 5: Documentation Complete.You’re building a professional application.
FTP • Mac • Transmit • Cyberduck • Coda • PC • SmartFTP • FileZilla • Firefox
IDE • Mac • Coda • Eclipse • Textmate • Dreamweaver • PC • PHP Designer • Zend Developer • notepad++ \ dreamweaver
Firebug a preview
PHP on Linux: First Steps • Understanding how PHP is setup and configured on your installation of linux is critical to your success. • phpinfo() • php.ini • Denied function, extensions, modules.
PHP Basics • All php code must start with <? • All php code must end with ?> • You might see <?php which is fine as well.
PHP Basics • Every PHP statement must end in a semicolon? • echo “i love php”;
PHP Basics • if a webpage contains PHP, keep the extension as .php • do not name it html.
PHP Variables • Variables store basic units of data that can control an application • Variables in PHP start with a $ sign. Must start with char or _ • for example: $player • setting variable: $player = “poodle”; • variable reference: $player =& $music (points to same content in memory) • restricted: $this (used in classes) • destroy: unset();
PHP Restricted Keywords • Abstract, And, array(), As, Break, Case, catch, cfunction, Class, clone, Const, Continue, Declare, Default, die(), Do, echo(), Else, elseif, empty, enddeclare, endfor, endforeach, endif, endswitch, endwhile,final, for, foreach, function, global, if
HTTP GET • This method appends the form-data to the URL in name/value pairs • This method is useful for form submissions where a user want to bookmark the result • There is a limit to how much data you can place in a URL (varies between browsers), therefore, you cannot be sure that all of the form-data will be correctly transferred • Never use the "get" method to pass sensitive information! (password or other sensitive information will be visible in the browser's address bar)
HTTP POST • This method sends the form-data as an HTTP post transaction • Form submissions with the "post" method cannot be bookmarked • The "post" method is more robust and secure than "get", and "post" does not have size limitations
PHP Global Variables • Pre-Defined SuperGlobal Vars - available in all scope. • usually indicated by underscore and caps • $GLOBALS • $_SERVER • $_GET • $_POST • $_COOKIE • $_SESSION • $_FILES • $_ENV • old style from php3 $HTTP_COOKIE_VARS
PHP Variables • Typically a variable has a lifespan of the current page (including pages that are inserted within the page you’re working). • In OOP there are extended definitions of a variable that restrict usage. • Golden Rule: Avoid the urge to scope globally.
PHP Commenting • Super basic: • // this is a single line comment • /* this is a comment */ • /* • * this is a comment • */ • best practice: good commenting
PHP Commenting • /* • * Dev: Lincoln Mongillo • * Time Updated: 09.12.08 2:30pm • * File: email-validation.php • * Desc: validates a users email address • */
PHP Data Types • Booleans • Integers • Floats • Strings • Arrays • Objects • Resource