Framework

787 views
736 views

Published on

Published in: Technology
0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
787
On SlideShare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
30
Comments
0
Likes
2
Embeds 0
No embeds

No notes for slide

Framework

  1. 1. PHP Frameworks Using PHP framework for development process
  2. 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. 3. <ul><ul><li>Save times </li></ul></ul><ul><ul><li>Unify Development Process </li></ul></ul><ul><ul><li>Reusable </li></ul></ul><ul><ul><li>Modularity </li></ul></ul><ul><ul><li>Scalable Software </li></ul></ul><ul><ul><li>Easy Maintenance </li></ul></ul>Enterprise Softwares
  4. 5. <ul><ul><li>Maintain by Zend - The PHP Company </li></ul></ul><ul><ul><li>Partners: Adobe, Google, IBM, Microsoft </li></ul></ul><ul><ul><li>Open source </li></ul></ul><ul><ul><li>Large community </li></ul></ul><ul><ul><li>Good documents </li></ul></ul>
  5. 6. <ul><ul><li>MVC Framework </li></ul></ul><ul><ul><li>Component base framework </li></ul></ul><ul><ul><li>Tons of components </li></ul></ul><ul><ul><li>Require PHP 5.2.x or higher </li></ul></ul>
  6. 8. <ul><ul><li>Controller </li></ul></ul><ul><ul><ul><li>Accept Request </li></ul></ul></ul><ul><ul><ul><li>Call Model </li></ul></ul></ul><ul><ul><ul><li>Pass model data to View </li></ul></ul></ul><ul><ul><li>Model </li></ul></ul><ul><ul><ul><li>Process business logic </li></ul></ul></ul><ul><ul><ul><li>Return result to Controller </li></ul></ul></ul><ul><ul><li>View </li></ul></ul><ul><ul><ul><li>Receive result from Controller </li></ul></ul></ul><ul><ul><ul><li>Display data </li></ul></ul></ul><ul><ul><ul><li>Call model (optional) </li></ul></ul></ul>
  7. 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
  8. 10. <ul><ul><li>Accept HTTP Request </li></ul></ul><ul><ul><li>Routing </li></ul></ul><ul><ul><li>Call Action Controller </li></ul></ul><ul><ul><li>Response to client </li></ul></ul>
  9. 11. <ul><ul><li>Find the target action base on request URL </li></ul></ul><ul><ul><li>Standard router: </li></ul></ul><ul><ul><ul><li>http: //example/news </li></ul></ul></ul><ul><ul><ul><ul><li>Module = news </li></ul></ul></ul></ul><ul><ul><ul><li>http: //example/foo </li></ul></ul></ul><ul><ul><ul><ul><li>In case of “foo” module does not exists: Module= Default Module, Controller = foo </li></ul></ul></ul></ul><ul><ul><ul><li>http: //example/blog/archive </li></ul></ul></ul><ul><ul><ul><ul><li>Module = Blog, Controller = archive </li></ul></ul></ul></ul><ul><ul><ul><li>http: //example/blog/archive/list </li></ul></ul></ul><ul><ul><ul><ul><li>Module = Blog, Controller = Archive, Action = List </li></ul></ul></ul></ul><ul><ul><ul><li>http: //example/blog/archive/list/sort/alpha/dir/desc </li></ul></ul></ul><ul><ul><ul><ul><li>Module = Blog, Controller = Archive, Action = List </li></ul></ul></ul></ul><ul><ul><ul><ul><li>Params: sort = alpha, dir=desc </li></ul></ul></ul></ul>
  10. 12. <?php /** * Index Controller */ class IndexController extends Zend_Controller_Action { /** * Index Action */ public function indexAction() { // action body } }
  11. 13. <ul><ul><li>Zend_Db_Adapter </li></ul></ul><ul><ul><ul><li>IBM DB2, MySQL, SQL Server, Oracle, PostgreSQL, SQLite, Firebird </li></ul></ul></ul><ul><ul><li>Zend_Db_Statement </li></ul></ul><ul><ul><li>Zend_Db_Profiler </li></ul></ul><ul><ul><li>Zend_Db_Select </li></ul></ul><ul><ul><li>Zend_Db_Table </li></ul></ul><ul><ul><li>Zend_Db_Table_Row </li></ul></ul><ul><ul><li>Zend_Db_Table_Rowset </li></ul></ul><ul><ul><li>Zend_Db_Table Relationships </li></ul></ul><ul><ul><li>Zend_Db_Table_Definition </li></ul></ul>
  12. 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 );
  13. 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 );
  14. 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] ’ ));
  15. 17. <?php //Update $user = new Users (); $data = array ( ‘ email ’ => ‘ [email_address] ’ ); $user -> update ( $data , ‘ user_id = 1234 ’); //Delete row $user -> delete (‘ user_id = 1234 ’);
  16. 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 );
  17. 19. <ul><ul><li>Scripts (templates) </li></ul></ul><ul><ul><ul><li>PHP-based script templates to present data </li></ul></ul></ul><ul><ul><ul><li>Should contain only display logic, not business logic </li></ul></ul></ul><ul><ul><ul><li>Default naming: “actionname.phtml” </li></ul></ul></ul><ul><ul><li>Helpers </li></ul></ul><ul><ul><ul><li>Classes and methods that provide reusable view functionality </li></ul></ul></ul><ul><ul><ul><li>Examples of built in view helpers: escape(), formText(), partial(), partialLoop(), headTitle() </li></ul></ul></ul><ul><ul><ul><li>Write your own, too </li></ul></ul></ul><ul><ul><li>Layout </li></ul></ul><ul><ul><ul><li>Define application/page layout </li></ul></ul></ul><ul><ul><ul><li>Using Two Step View pattern </li></ul></ul></ul><ul><ul><li>Placeholders </li></ul></ul>
  18. 20. <?php /** * Index Controller */ class IndexController extends Zend_Controller_Action { /** * Index Action */ public function indexAction() { $this -> view -> name = ‘ Dream Team ’; } }
  19. 21. <?php //index.phtml < h1 ><?php echo $this -> escape ( $this -> name ); ?></ h1 >
  20. 22. <ul><ul><li>Flexible solution for building forms </li></ul></ul><ul><ul><li>Create by PHP code, put it in model class </li></ul></ul><ul><ul><li>Or create in configuration file </li></ul></ul><ul><ul><li>Validation support </li></ul></ul><ul><ul><li>Auto restore input values when error occurs. </li></ul></ul><ul><ul><li>Using decorator for output form elements </li></ul></ul>
  21. 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 '); } }
  22. 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 ');           } } }
  23. 25. <ul><ul><li>Alnum </li></ul></ul><ul><ul><li>Alpha </li></ul></ul><ul><ul><li>Barcode </li></ul></ul><ul><ul><li>Between </li></ul></ul><ul><ul><li>CreditCard </li></ul></ul><ul><ul><li>Ccnum </li></ul></ul><ul><ul><li>Date </li></ul></ul><ul><ul><li>Db_RecordExists </li></ul></ul><ul><ul><li>Digits </li></ul></ul><ul><ul><li>EmailAddress </li></ul></ul><ul><ul><li>Float </li></ul></ul><ul><ul><li>GreaterThan </li></ul></ul><ul><ul><li>Hex </li></ul></ul><ul><ul><li>Hostname </li></ul></ul><ul><ul><li>Iban </li></ul></ul><ul><ul><li>Identical </li></ul></ul><ul><ul><li>InArray </li></ul></ul><ul><ul><li>Int </li></ul></ul><ul><ul><li>Ip </li></ul></ul><ul><ul><li>Isbn </li></ul></ul><ul><ul><li>LessThan </li></ul></ul><ul><ul><li>NotEmpty </li></ul></ul><ul><ul><li>PostCode </li></ul></ul><ul><ul><li>Regex </li></ul></ul><ul><ul><li>StringLength </li></ul></ul>
  24. 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 '),           ))); } }
  25. 27. <ul><ul><li>Main website: http://framework.zend.com </li></ul></ul><ul><ul><li>Quick Start: http://framework.zend.com/manual/en/learning.quickstart.intro.html </li></ul></ul><ul><ul><li>Manual: http://framework.zend.com/manual/manual </li></ul></ul>
  26. 28. <ul><ul><li>Create Module </li></ul></ul><ul><ul><li>Create Controller, Action </li></ul></ul><ul><ul><li>Create Layout, View </li></ul></ul><ul><ul><li>Create Form </li></ul></ul><ul><ul><li>Update data </li></ul></ul>

×