Framework
Upcoming SlideShare
Loading in...5
×
 

Framework

on

  • 843 views

 

Statistics

Views

Total Views
843
Views on SlideShare
843
Embed Views
0

Actions

Likes
2
Downloads
29
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Framework Framework Presentation Transcript

    • PHP Frameworks Using PHP framework for development process
    • “ A software framework, in computer programming, is an abstraction in which  common code providing generic functionality  can be selectively overridden or specialized by user code providing specific functionality. Frameworks are a special case of software libraries in that they are  reusable abstractions of code  wrapped in a well-defined Application programming interface (API), yet they contain some key distinguishing features that separate them from normal libraries. ”
        • Save times
        • Unify Development Process
        • Reusable
        • Modularity
        • Scalable Software
        • Easy Maintenance
      Enterprise Softwares
    •  
        • Maintain by Zend - The PHP Company
        • Partners: Adobe, Google, IBM, Microsoft
        • Open source
        • Large community
        • Good documents
        • MVC Framework
        • Component base framework
        • Tons of components
        • Require PHP 5.2.x or higher
    •  
        • Controller
          • Accept Request
          • Call Model
          • Pass model data to View
        • Model
          • Process business logic
          • Return result to Controller
        • View
          • Receive result from Controller
          • Display data
          • Call model (optional)
    • Front Controller Action Controller Component Library Data Internationalization PDF Database JSON Date Translate Locale Webservices SOAP Amazon Google Core Log Cache ACL Plugins View Edit Del HTTP Request
        • Accept HTTP Request
        • Routing
        • Call Action Controller
        • Response to client
        • Find the target action base on request URL
        • Standard router:
          • http: //example/news
            • Module = news
          • http: //example/foo
            • In case of “foo” module does not exists: Module= Default Module, Controller = foo
          • http: //example/blog/archive
            • Module = Blog, Controller = archive
          • http: //example/blog/archive/list
            • Module = Blog, Controller = Archive, Action = List
          • http: //example/blog/archive/list/sort/alpha/dir/desc
            • Module = Blog, Controller = Archive, Action = List
            • Params: sort = alpha, dir=desc
    • <?php /** * Index Controller */ class IndexController extends Zend_Controller_Action { /** * Index Action */ public function indexAction() { // action body } }
        • Zend_Db_Adapter
          • IBM DB2, MySQL, SQL Server, Oracle, PostgreSQL, SQLite, Firebird
        • Zend_Db_Statement
        • Zend_Db_Profiler
        • Zend_Db_Select
        • Zend_Db_Table
        • Zend_Db_Table_Row
        • Zend_Db_Table_Rowset
        • Zend_Db_Table Relationships
        • Zend_Db_Table_Definition
    • <?php $params = array( ' host ' => ' 127.0.0.1 ', ' username ' => ' webuser ', ' password ' => ’ ******* ', ' dbname ' => ' test ', ); $db = Zend_Db::factory (' Pdo_Mysql ', $params ); $sql = ‘ SELECT * FROM users ’; $rows = $db ->fetchAll( $sql );
    • <?php $select = $db -> select ()                   -> from (‘ users ’,  array (‘username’, ‘email’))                       -> where (‘ username = ? ’, $username ) ; //Same as: // SELECT username, email FROM users // WHERE username = ‘…’ $user = $db -> fetchRow ( $select );
    • <?php class Users extends Zend_Db_Table_Abstract { protected $_name = ' users '; protected $_primaryKey = ' user_id '; } //Insert $user = new Users (); $user -> insert ( array ( ‘ username ’ => ‘ cusc ’ ‘ name ’ => ‘ CUSC Software ’, ‘ email ’ => ‘ [email_address] ’ ));
    • <?php //Update $user = new Users (); $data = array ( ‘ email ’ => ‘ [email_address] ’ ); $user -> update ( $data , ‘ user_id = 1234 ’); //Delete row $user -> delete (‘ user_id = 1234 ’);
    • <?php //Find rows by primary key $user = new Users (); $rows = $user -> find (1234); //Find by conditions $select = $user -> select ()                           -> where (“ email LIKE ‘%?’ ”, ‘musical .vn ’); $rows = $user -> fetchAll ( $select );
        • Scripts (templates)
          • PHP-based script templates to present data
          • Should contain only display logic, not business logic
          • Default naming: “actionname.phtml”
        • Helpers
          • Classes and methods that provide reusable view functionality
          • Examples of built in view helpers: escape(), formText(), partial(), partialLoop(), headTitle()
          • Write your own, too
        • Layout
          • Define application/page layout
          • Using Two Step View pattern
        • Placeholders
    • <?php /** * Index Controller */ class IndexController extends Zend_Controller_Action { /** * Index Action */ public function indexAction() { $this -> view -> name = ‘ Dream Team ’; } }
    • <?php //index.phtml < h1 ><?php echo $this -> escape ( $this -> name ); ?></ h1 >
        • Flexible solution for building forms
        • Create by PHP code, put it in model class
        • Or create in configuration file
        • Validation support
        • Auto restore input values when error occurs.
        • Using decorator for output form elements
    • class Admin_Form_Account extends Zend_Form { public function init()  { parent :: init (); $this -> setAction (' /admin/account/createPost '); $this -> addElement ( $this -> createElement (' text ', ' username ', array ( ' required ' => true, ' label '       => ' Username ', ))); $this -> addElement ( $this -> createElement (' text ', ' name ', array (           ' required ' => true,           ' label '       => ' Name ', ))); $this -> addElement ( $this -> createElement (' text ', ' email ', array (           ' required ' => true,           ' label ' => ' Email ', ))); $this -> addElement ( $this -> createElement (' password ', ' password ', array (           ' required ' => true,           ' label ' => ' Lastname ', ))); $this -> addElement (' submit ', ' Submit '); } }
    • <?php class Admin_Account_Controller extends Zend_Controller_Action { public function formAction() {           $form = new Admin_Form_Account ();           $this -> view -> form = $form ; } public function createPostAction() {           $form = new Admin_Form_Account ();           if (! $form -> isValid ( $this -> getRequest ()-> getPost ())) {                     $this -> view -> form = $form ;                     $this -> render (’ form ');           } else {                     $this -> _forward (’ success ');           } } }
        • Alnum
        • Alpha
        • Barcode
        • Between
        • CreditCard
        • Ccnum
        • Date
        • Db_RecordExists
        • Digits
        • EmailAddress
        • Float
        • GreaterThan
        • Hex
        • Hostname
        • Iban
        • Identical
        • InArray
        • Int
        • Ip
        • Isbn
        • LessThan
        • NotEmpty
        • PostCode
        • Regex
        • StringLength
    • class Admin_Form_Account extends Zend_Form { public function init()  {         parent :: init ();         $this -> addElement ( $this -> createElement (' text ', ' email ', array (                 ' required '   => true,                 ' label '         => ' Email ',                 ' validators ' => array (' emailaddress '),           ))); } }
        • Main website: http://framework.zend.com
        • Quick Start: http://framework.zend.com/manual/en/learning.quickstart.intro.html
        • Manual: http://framework.zend.com/manual/manual
        • Create Module
        • Create Controller, Action
        • Create Layout, View
        • Create Form
        • Update data