Framework

  • 618 views
Uploaded on

 

More in: Technology
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
No Downloads

Views

Total Views
618
On Slideshare
0
From Embeds
0
Number of Embeds
0

Actions

Shares
Downloads
29
Comments
0
Likes
2

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. PHP Frameworks Using PHP framework for development process
  • 2. “ 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. ”
  • 3.
      • Save times
      • Unify Development Process
      • Reusable
      • Modularity
      • Scalable Software
      • Easy Maintenance
    Enterprise Softwares
  • 4.  
  • 5.
      • Maintain by Zend - The PHP Company
      • Partners: Adobe, Google, IBM, Microsoft
      • Open source
      • Large community
      • Good documents
  • 6.
      • MVC Framework
      • Component base framework
      • Tons of components
      • Require PHP 5.2.x or higher
  • 7.  
  • 8.
      • 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)
  • 9. 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
  • 10.
      • Accept HTTP Request
      • Routing
      • Call Action Controller
      • Response to client
  • 11.
      • 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
  • 12. <?php /** * Index Controller */ class IndexController extends Zend_Controller_Action { /** * Index Action */ public function indexAction() { // action body } }
  • 13.
      • 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
  • 14. <?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 );
  • 15. <?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 );
  • 16. <?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] ’ ));
  • 17. <?php //Update $user = new Users (); $data = array ( ‘ email ’ => ‘ [email_address] ’ ); $user -> update ( $data , ‘ user_id = 1234 ’); //Delete row $user -> delete (‘ user_id = 1234 ’);
  • 18. <?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 );
  • 19.
      • 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
  • 20. <?php /** * Index Controller */ class IndexController extends Zend_Controller_Action { /** * Index Action */ public function indexAction() { $this -> view -> name = ‘ Dream Team ’; } }
  • 21. <?php //index.phtml < h1 ><?php echo $this -> escape ( $this -> name ); ?></ h1 >
  • 22.
      • 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
  • 23. 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 '); } }
  • 24. <?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 ');           } } }
  • 25.
      • 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
  • 26. 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 '),           ))); } }
  • 27.
      • 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
  • 28.
      • Create Module
      • Create Controller, Action
      • Create Layout, View
      • Create Form
      • Update data