Comp4711 – Internet Development CodeIgniter Cookbook Comp4711 #2 – Sept 14, 2011.

Slides:



Advertisements
Similar presentations
JQuery MessageBoard. Lets use jQuery and AJAX in combination with a database to update and retrieve information without refreshing the page. Here we will.
Advertisements

PHP + Framework + MVC. What is Framework? Common code - Generic functionality Extensible - Specific functionality Unlike library – Flow Dictated by.
LIS651 lecture 3 taming PHP Thomas Krichel
PHP II Interacting with Database Data. The whole idea of a database-driven website is to enable the content of the site to reside in a database, and to.
Struts Portlet Copyright © Liferay, Inc. All Rights Reserved. No material may be reproduced electronically or in print without written permission.
Presenter: James Huang Date: Sept. 29,  HTTP and WWW  Bottle Web Framework  Request Routing  Sending Static Files  Handling HTML  HTTP Errors.
Apache Struts Technology
1.  Understanding about How to Working with Server Side Scripting using PHP Framework (CodeIgniter) 2.
Chapter 10 Database Applications Copyright © 2011 by The McGraw-Hill Companies, Inc. All Rights Reserved. McGraw-Hill.
Ruby on Rails by Manik Juneja Ruby On Rails. Ruby on Rails by Manik Juneja Rails is a Web Application development framework. Based on the MVC pattern.
Configuring web servers and web applications 1. 2 Server configuration vs. application configuration A web server may run several web application Server.
Fast Track to ColdFusion 9. Getting Started with ColdFusion Understanding Dynamic Web Pages ColdFusion Benchmark Introducing the ColdFusion Language Introducing.
DT228/3 Web Development Databases. Database Almost all web application on the net access a database e.g. shopping sites, message boards, search engines.
A02 Creating my website NAME ______________. UNIT 2 – A02 – Creating my Website The purpose of this assessment objective is to create 5 web pages containing.
Sys Prog & Scripting - HW Univ1 Systems Programming & Scripting Lecture 15: PHP Introduction.
MVC in Trax.
Windows.Net Programming Series Preview. Course Schedule CourseDate Microsoft.Net Fundamentals 01/13/2014 Microsoft Windows/Web Fundamentals 01/20/2014.
Java Frameworks Indy Java Users Group January 29, 2003.
Introduction to the Enterprise Library. Sounds familiar? Writing a component to encapsulate data access Building a component that allows you to log errors.
CodeIgniter - [Overview]
Joel Bapaga on Web Design Strategies Technologies Commercial Value.
INTRODUCTION TO DREAMWEAVER 8. What we already know…  Design basics  Contrast  Repetition  Alignment  Repetition  HTML.
INTERNET APPLICATION DEVELOPMENT For More visit:
Welcome  30 Question & 30 Minutes  Question Will Move Automatically After 1 Min Your Exam Start Now Lecturer : Zalak Thakrar.
10-1 aslkjdhfalskhjfgalsdkfhalskdhjfglaskdhjflaskdhjfglaksjdhflakshflaksdhjfglaksjhflaksjhf.
Using JavaBeans and Custom Tags in JSP Lesson 3B / Slide 1 of 37 J2EE Web Components Pre-assessment Questions 1.The _____________ attribute of a JSP page.
LiveCycle Data Services Introduction Part 2. Part 2? This is the second in our series on LiveCycle Data Services. If you missed our first presentation,
PHP meets MySQL.
Introduction to ASP.NET MVC Information for this presentation was taken from Pluralsight Building Applications with ASP.NET MVC 4.
Introduction to Model-Glue Rachel Lehman Perpetual Intermediate Designer-Developer Introduction to Model-Glue.
CAKEPHP Blog tutorial. what you’ll need examples/blog/blog.html 2  A running web server  A database server.
Lecture 11 Rails Topics SaaSSaaS Readings: SaaS book Ch February CSCE 740 Software Engineering.
 2004 Prentice Hall, Inc. All rights reserved. 1 Segment – 6 Web Server & database.
JSTL Lec Umair©2006, All rights reserved JSTL (ni) Acronym of  JavaServer Pages Standard Tag Library JSTL (like JSP) is a specification, not an.
Drupal Overview Prepared by : Agustin D. Gumogda Jr. Instructor.
Database Design and Management CPTG /23/2015Chapter 12 of 38 Functions of a Database Store data Store data School: student records, class schedules,
Mr. Justin “JET” Turner CSCI 3000 – Fall 2015 CRN Section A – TR 9:30-10:45 CRN – Section B – TR 5:30-6:45.
HTML Basics BCIS 3680 Enterprise Programming. Web Client/Server Architecture 2  Your browser (the client) requests a Web page from a remote computer.
CSC 2720 Building Web Applications Server-side Scripting with PHP.
MVC Concepts Basics Model-View-Controller (MVC) Concepts for Web Developers SoftUni Team Technical Trainers Software University
Copyright © 2002 ProsoftTraining. All rights reserved. JavaServer Pages.
Mr. Justin “JET” Turner CSCI 3000 – Fall 2015 CRN Section A – TR 9:30-10:45 CRN – Section B – TR 5:30-6:45.
.htaccess Apache server directives BTM 395: Internet Programming.
How does Drupal Work? Information Systems 337 Prof. Harry Plantinga.
Looking at various Rich Message options in KRAD Kuali University: Apply Now Lab : Rich Messages Lab Objectives Understand what Rich Messages are and how.
ICM – API Server & Forms Gary Ratcliffe.
Preface IIntroduction Objectives I-2 Course Overview I-3 1Oracle Application Development Framework Objectives 1-2 J2EE Platform 1-3 Benefits of the J2EE.
Advanced Web 2012 Lecture 11 Sean Costain 2012.
Date : 3/04/2010 Web Technology Solutions Class: PHP Web Application Frameworks.
Peter Peng. Agenda Introducing A simple example More complex examples (in part 2) Developing (in part 3)
CSC 2720 Building Web Applications Basic Frameworks for Building Dynamic Web Sites / Web Applications.
CSC 405: Web Application Engineering II8.1 Web programming using PHP What have we learnt? What have we learnt? Underlying technologies of database supported.
Chapter 12© copyright Janson Industries Java Server Faces ▮ Explain the JSF framework ▮ SDO (service data objects) ▮ Facelets ▮ Pagecode classes.
1 Java Server Pages A Java Server Page is a file consisting of HTML or XML markup into which special tags and code blocks are inserted When the page is.
Mr. Justin “JET” Turner CSCI 3000 – Fall 2015 CRN Section A – TR 9:30-10:45 CRN – Section B – TR 5:30-6:45.
Working With Database Library And Helpers. Connecting to your Database First you need to set parameters in you database.php file residing in config folder.
Module 6: Administering Reporting Services. Overview Server Administration Performance and Reliability Monitoring Database Administration Security Administration.
Final Exam... Comp4711 Fall When & Where Date? Tue Dec 13 When? 08:00-10:00 Where? SE How Long? Two hours How long minimum? 1 hour Aids: None.
Session 11: Cookies, Sessions ans Security iNET Academy Open Source Web Development.
Preface IIntroduction Course Objectives I-2 Course Content I-3 1Introduction to Oracle Reports Developer Objectives 1-2 Business Intelligence 1-3 Enterprise.
For Rapid Application Development Developed By
Intro to WordPress (Using XAMPP)
What is Laravel ? By Georgi Genov.
z/Ware 2.0 Technical Overview
Introduction to CodeIgniter (CI)
PHP Training at GoLogica in Bangalore
Ruby on Rails by Manik Juneja
WEB API.
Ruby on Rails by Manik Juneja
Controllers.
Presentation transcript:

Comp4711 – Internet Development CodeIgniter Cookbook Comp4711 #2 – Sept 14, 2011

Comp4711 – Internet Development W4L1 JSP Introduction CodeIgniter Cookbook 1)Infrastructure 2)Development vs Deployment 3)Fixing the URL 4)Models 5)Controllers 6)Authentication 7)Views 8)Templates 9)Helpers 10)Libraries 11)Error Handling

Comp4711 – Internet Development W1L1 XML Introduction 1. Infrastructure Goals: –Reduce complexity of webapp (not inc CI) –Reuse CI across webapps (only 1 copy) –Improve security (not accessible) Solution: –Move CI folder up 1 or 2 levels (outside of htdocs) –Keep application folder inside webapp –Fix configuration in index.php –Move assets out of webapp folder

1. index.php $system_folder = "system"; $system_folder = "../CI"; Note: Some hosting companies make it awkward to reference outside htdocs Note: above assumes webapp is a subfolder of htdocs Note: might have to use something like realpath($_SERVER['DOCUM ENT_ROOT']."/../.."); $application_folder = "application"; $application_folder = "./application"; Net result: application is a folder directly under webapp root

2. Development vs Production Goals: –Accommodate different passwords & folder structures for different environments –Facilitate deployment without mods Solution: –$config[][] –Test server name

2.1 config/config.php $config['base_url']= " //JLP Adjust for development environment //NOTE Still have to set port properly in NetBeans project properties (run configuration) if ($_SERVER['SERVER_NAME'] == "localhost") { $config['base_url'] = " }

2.2 config/database.php $active_group = "default"; $active_record = TRUE; $db['default']['hostname'] = "localhost"; $db['default']['username'] = "root"; $db['default']['password'] = ""; $db['default']['database'] = "heritage"; $db['prod']['hostname'] = " $db['prod']['username'] = "master"; $db['prod']['password'] = "secret"; $db['prod']['database'] = "ourg_5149";

Comp4711 – Internet Development 3. Fixing the URL Goal: –Make the URL short & friendly Solutions: –mod_rewrite inside.htaccess –config/routing.php

Comp4711 – Internet Development 3.1.htaccess sample DirectoryIndex index.php index.html RewriteEngine on # Allow requests for valid file or folder names, or some that should be RewriteCond %{REQUEST_FILENAME} -f [OR] RewriteCond %{REQUEST_FILENAME} -d [OR] RewriteCond $1 ^(robots\.txt|favicon\.ico|style\.css) RewriteRule ^(.*)$ - [L] # Change any JSP requests into PHP ones RewriteRule ^(.*)\.jsp$./index.php/$1 [L] # use index.php as front controller... RewriteRule ^(.*)$./index.php/welcome/$1 [L]

Comp4711 – Internet Development 3.2.htaccess DirectoryIndex index.php index.html RewriteEngine on # Allow requests for valid file or folder names, or some that should be RewriteCond %{REQUEST_FILENAME} -f [OR] RewriteCond %{REQUEST_FILENAME} -d [OR] RewriteCond $1 ^(robots\.txt|favicon\.ico|style\.css) RewriteRule ^(.*)$ - [L] # # use index.php as front controller... RewriteRule ^(.*)$./index.php/$1 [L]

Comp4711 – Internet Development 3.3 config/config.php $config['base_url']= " OR set RewriteBase in.htaccess $config['index_page'] = "";

Comp4711 – Internet Development 3.4 config/routes.php $route['default_controller'] = "welcome"; $route['blog/joe'] = "blogs/users/34"; $route['products/([a-z]+)/(\d+)'] = "$1/id_$2";

Comp4711 – Internet Development 4. Models Goal: –Make life easier Solution: –Understand Active Record pattern –MY_Model for RDB –MY_Model2 … –Others

Comp4711 – Internet Development 4.1 Active Record Pattern Active record is an approach to accessing data in a database. A database table or view is wrapped into a class. The interface to such an object would include functions such as Insert, Update, and Delete, plus properties that correspond more or less directly to the columns in the underlying database table. Normal: updates happen automatically; CI: use database class

Comp4711 – Internet Development 4.2 core/MY_Model (or models/my_model.php & autoload) class MyModel extends Model { var $_tableName; // Which table is this a model for a row of? var $_keyField; // name of the primary key field var $_data; // placeholder for retrieved values … create() get($key) add($record) update() delete($key) Exists()

Comp4711 – Internet Development 4.3 models/MyModel2 class MyModel2 extends MyModel { var $_keyField2; // second part of composite primary key … get($key1,$key2) getSome($key)

Comp4711 – Internet Development 4.4 models/Properties class Properties extends Model { // Fields var $_data = array(); // Container for the data from persistent storage (the database). var $_tableName; // name of the DB table holding the data var $_keyField; // name of the primary key field var $_valueField; // name of the data field … loadtable(...) get($key) put($key,$value) remove($key)

Comp4711 – Internet Development 4.5 XML models! Same/similar API to “conventional” model Intent is to arrive at bridge/adapters $64 question: use SimpleXmlModel, domain model classes, or associative arrays??

Comp4711 – Internet Development 5. Controllers Goals: –Routing –Templating –Modular MVC –Business logic in controller –Business logic in model Solution: –MY_Controller –Strategies...

Comp4711 – Internet Development 5.1 Single welcome.php Welcome extends Controller{ Function index() {…} Function page2() {…} Function page3() {...}

Comp4711 – Internet Development 5.2 Multiple controllers Welcome extends Controller... Page1 extends Controller... Page2 extends Controller...

Comp4711 – Internet Development 5.3 Form gen/handling Form handling class?

Comp4711 – Internet Development 5.4 core/MY_Controller.php class Application extends CI_Controller { // Constructor - establish session variables function Application() { parent::Controller(); // make sure we play the game nicely $this->load->helper('common'); $this->load->helper('url'); } // No restrictions for the front-end function restrict($roleNeeded=null) { }

Comp4711 – Internet Development 6. Authentication Goal: –Restrict access to parts of site Solution: –Role-based authentication –Hooks –Custom controller

Comp4711 – Internet Development 6.1 Authentication package // Restrict the current page to a specific role or to a set of roles function restrict($roleNeeded=null) { if ($roleNeeded != null) { // handle the case of a set of allowed roles if (is_array($roleNeeded) ) { if (!in_array($this->gicc- >userRole,$roleNeeded)) { // Not authorized. Redirect to home page redirect("/"); exit; } else // handle the case of a single applicable role if ($this->gicc->userRole != $roleNeeded) { // Not authorized. Redirect to home page redirect("/"); exit; }

Comp4711 – Internet Development 7. Views Goals: –Easy page assembly Solutions: –Page template –Page components –Business logic in view?

Comp4711 – Internet Development 7.1 template.php load->view('_meta'); ?> load->view('header'); ?> load->view($bodypage); ?>

Comp4711 – Internet Development 7.2 _xxx.php _meta.php CSS style sheets, metadata, titles, etc _header.php site-wide header, perhaps with banner _sidebar.php site-wide navigation _footer.php copyright, contact, text navbar

Comp4711 – Internet Development 8. Templates Goals: –Page consistency –Page pre-processing Solutions: –Template package

Comp4711 – Internet Development 8.1 template package Template parser class? $data['bulkbody'] = $bulkbody; $data['bulkfrom'] = $bulkfrom; $data['bulkopening'] = $bulkopening;... // let's generate the letter now $this->load->library('parser'); // get the template helper $preview = ""; $choices = $_SESSION['openings']; $template = "templates/opening_".$choices[$bulkopening]; $preview.= $this->parser->parse($template,$data,true); // apply template, capture output $template = "templates/bulk_mailout"; $preview.= $this->parser->parse($template,$data,true); // apply template, capture output

Comp4711 – Internet Development 8.2 “view template” pattern View/template.php Includes views _meta, _header, _footer, _navbar and $body Set “body” parameter and $this->load->view(“template”,$body);

Comp4711 – Internet Development 9. Helpers Goals: –Reuse common code Solutions: –Helpers –Be careful of naming conventions

Comp4711 – Internet Development 9.1 Example: common_helper Form field handling, using associative array as data transfer object/buffer fieldExtract($source,$target,$fields) –$source – assoc array from form –$target – corresponding object –$fields – names of fields in this form fieldInject($source,$target,$fields) –$source – original data object –$target – assoc array for parameters to view –$fields – names of fields in this form

Comp4711 – Internet Development 10. Libraries Goals: –Encapsulate useful things Solutions: –Libraries –MY_ controller or MY_model go in application/core –Object models … libraries? Or models?

Comp4711 – Internet Development 10.1 Example: GICC Libraries/GICC.php Used to hold “global” constants & app config data Just one way to do this

Comp4711 – Internet Development 10.2 Example: Product Libraries/product.php Use for object model for entities stored in an XML document “models/products” would be the aggregation of these Again, just one way to do this Will revisit this at half-way point

Comp4711 – Internet Development 11. Error Handling Goals: Determine what went wrong Solutions: index.php … error_reporting(E_ALL); application/errors/... UhOh extension to override CI error handling with better description & backtrace routing/htaccess for common problems