1 / 7

CodeIgniter

CodeIgniter. Database Brugerinput Form Validation. Database Library. http://codeigniter.com/user_guide/database/index.html For bruge den skal det enten være autoloaded ( config/autoload.php ) eller $ this->load->database ();. To måder at hente data. OO-versionen

Download Presentation

CodeIgniter

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. CodeIgniter • Database • Brugerinput • Form Validation JFH

  2. Database Library • http://codeigniter.com/user_guide/database/index.html • For bruge den skal det enten være autoloaded (config/autoload.php)eller$this->load->database(); JFH

  3. To måder at hente data • OO-versionen $query = $this->db->query( 'SELECT name, email FROM my_table');foreach ($query->result() as $row){    echo $row->name;    echo $row->email;} • Som vi er vant til, næsten $query = mysql_query( 'SELECT name, email FROM my_table');while (row=mysql_fetch_array($query){echo $row['name'];echo $row['email'];} JFH

  4. Query bindings • Hver gang vi bruger noget der kommer fra brugeren i vores SQL skal/bør vi QB’e • Alt hvad vi henter med $_REQUEST, $_GET, $_POST, $_COOKIE kommer fra brugeren og er potentielt farligt (også selvom det kommer fra SELECT elementer eller lignende som vi selv har lavet) JFH

  5. Query bindings, del 2 • Vi snakkede lidt om det sidst: $sql = "SELECT * FROM some_table WHERE id = ? AND status = ? AND author = ?"; $params = array(3, 'live', 'Rick'); $this->db->query($sql, $params); JFH

  6. Brugerinput • http://codeigniter.com/user_guide/libraries/input.html • CI bruger stort set ikke $_GET (det ligger i URL’en) • I stedet for $_POST[’var’] bruger vi $this->input->post(’var’) • $this->input->post(’x’) tjekker om variablen findes og returnerer false hvis den ikke gør JFH

  7. Brugerinput $_POST $this->input->post If($x=$this->input->post(’x’)){ //gør noget } If(isset($_POST[’x’])){ $x=$_POST[’x’]; //gør noget } JFH

More Related