1 / 21

NMD202 Web Scripting

NMD202 Web Scripting. Week7. What we will cover today. Student List Exercise String manipulation Exercises MVC Patterns Exercises Assignment 1. Student List Exercise. Check the implementation at:

ryo
Download Presentation

NMD202 Web Scripting

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. NMD202 Web Scripting Week7

  2. What we will cover today Student List Exercise String manipulation Exercises MVC Patterns Exercises Assignment 1

  3. Student List Exercise Check the implementation at: http://learnline.cdu.edu.au/units/webscripting/classmaterials/source/student/listStudents.php

  4. String Manipulation PHP has several functions to manipulate strings: http://au.php.net/manual/en/ref.strings.php

  5. String Manipulation strlen ($string) - Length String strtolower($string) – Convert string to lower case strtoupper($string) – Convert string to upper case trim($string) - Strip whitespace from the beginning and end of a string

  6. String Manipulation Find strings within strings: strpos ($haystack , $needle); This will give you the index of the searched substring. Use stripos for case insensitive search

  7. String Manipulation Get a substring from string substr($string , $start, $length ) Returns the portion of $string specified by the $start and $length parameters.

  8. String Manipulation Split a string into segments Explode($delimiter , $string); Returns an array of strings, each of which is a substring of $string formed by splitting it on boundaries formed by the string $delimiter .

  9. String Manipulation Join a string from segments implode($glue, $pieces); Returns a string containing a string representation of all the array elements ($pieces) in the same order, with $glue between each element

  10. String Manipulation String replace: str_replace($search ,$replace , $subject); This function returns a string or an array (depending on $subject) with the replaced values.

  11. String Manipulation String Hashing: md5($string) crypt($string) sha($string)

  12. String Manipulation Regular Expressions: ereg_replace — Replace regular expression ereg— Regular expression match eregi_replace— Replace regular expression case insensitive eregi— Case insensitive regular expression match

  13. Exercises Write some code to make sure that student names have their first letter in uppercase when inserted in the database: ie: input:luissilva Stored: Luis Silva

  14. MVC Pattern

  15. MVC Pattern Implementation in php: Controller is called with parameters (post or get). Controller routes the request according to some parameters (task) and calls the model to collect, perform changes on the data View is built with data collected from the model and rendered to the user

  16. MVC Pattern View: <form method=“post” action=“controller.php”> <input type=“hidden” name=“task” value=“insert”>

  17. MVC Pattern Controller: $task = (isset($_POST[‘task’]))? $_POST[‘task’]:$_GET[‘task’]; switch ($task) { case “insert”: doInsert(); case “update”: doUpdate(); case “addNew”: renderAddForm(); default: renderList (); }

  18. MVC Pattern Controller: function doInsert(); { insertStudent($_POST[‘name’], $_POST[‘email’]); renderList (); }

  19. MVC Pattern Controller: function renderList(); { $students = getStudentsList(); require_once(‘studentList.php’); }

  20. MVC Pattern view: <table> <?php While ($student = mysql_fetch_array($students)) { echo ...

  21. Exercises Redo the student list exercise implementing it as an MVC pattern

More Related