Amit Kumar Singh ITBrainShapers. MVC Model Data layer View Presentation layer Controller Logic layer.

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.
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 15 Introduction to Rails.
CakePHP. A framework for developing applications in PHP Inspired by Ruby on Rails Follows MVC design pattern Convention over configuration –No wheel reinventing.
The Librarian Web Page Carol Wolf CS396X. Create new controller  To create a new controller that can manage more than just books, type ruby script/generate.
Apache Struts Technology
Introduction to PHP MIS 3501, Fall 2014 Jeremy Shafer
Ruby on Rails Model of MVC. Model-View-Controller Paradigm A way of organizing a software system Benefits: Isolation of business logic from the user interface.
1.  Understanding about How to Working with Server Side Scripting using PHP Framework (CodeIgniter) 2.
CakePHP A PHP Framework. CakePHP A framework for developing applications in PHP Inspired by Ruby on Rails Follows MVC design pattern Convention over configuration.
Web Applications Development Using Coldbox Platform Eddie Johnston.
27-Jun-15 Rails. What is Rails? Rails is a framework for building web applications This involves: Getting information from the user (client), using HTML.
Application Architectures Vijayan Sugumaran Department of DIS Oakland University.
Chapter 7 Managing Data Sources. ASP.NET 2.0, Third Edition2.
Struts 2.0 an Overview ( )
UNIT-V The MVC architecture and Struts Framework.
Ruby on Rails: An Introduction JA-SIG Summer Conference 2007 Michael Irion The University of Tulsa.
Ruby on Rails. What is Ruby on Rails? Ruby on Rails is an open source full-stack web framework. It is an alternative to PHP/MySQL. It can render templates,
Dataface API Essentials Steve Hannah Web Lite Solutions Corp.
Lecture 3 – Data Storage with XML+AJAX and MySQL+socket.io
Rails and Grails. To get started Make sure you have java installed You can get the sdk and jre at:
Server-side Scripting Powering the webs favourite services.
Lecture 7 Interaction. Topics Implementing data flows An internet solution Transactions in MySQL 4-tier systems – business rule/presentation separation.
1 PHP and MySQL. 2 Topics  Querying Data with PHP  User-Driven Querying  Writing Data with PHP and MySQL PHP and MySQL.
MVC & ActiveRecord by Christian Mohr & Mohamed Souiai.
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,
Tutorial 121 Creating a New Web Forms Page You will find that creating Web Forms is similar to creating traditional Windows applications in Visual Basic.
Lecture 19 Web Application Frameworks Boriana Koleva Room: C54
1 Functions 1 Parameter, 1 Return-Value 1. The problem 2. Recall the layout 3. Create the definition 4. "Flow" of data 5. Testing 6. Projects 1 and 2.
1 Dr Alexiei Dingli Web Science Stream Introducing Rails.
Introduction to ASP.NET MVC Information for this presentation was taken from Pluralsight Building Applications with ASP.NET MVC 4.
Ruby on Rails Your first app. Rails files app/ Contains the controllers, models, views and assets for your application. You’ll focus on this folder for.
PHP + Framework + MVC CakePHP Lectures 1. What is Framework? CakePHP Lectures 2.
School of Computing and Information Systems CS 371 Web Application Programming PHP – Forms, Cookies, Sessions and Database.
CAKEPHP Blog tutorial. what you’ll need examples/blog/blog.html 2  A running web server  A database server.
Lecture 8 – Cookies & Sessions SFDV3011 – Advanced Web Development 1.
Mr. Justin “JET” Turner CSCI 3000 – Fall 2015 CRN Section A – TR 9:30-10:45 CRN – Section B – TR 5:30-6:45.
Arnold Geraldo Designing and Making of The Online Auction Website Using CakePHP Framework.
The Active Record Paradigm Databases in Database-Centric Web Site Development.
Overview: 1. Discussion of the basic architecture of a web application. 2. Discussion of the relevance of using MySQL and PHP in a web application.
Rails & Ajax Module 5. Introduction to Rails Overview of Rails Rails is Ruby based “A development framework for Web-based applications” Rails uses the.
 Registry itself is easy and straightforward in implementation  The objects of registry are actually complicated to store and manage  Objects of Registry.
David Lawrence 7/8/091Intro. to PHP -- David Lawrence.
© FPT SOFTWARE – TRAINING MATERIAL – Internal use 04e-BM/NS/HDCV/FSOFT v2/3 JSP Application Models.
ICM – API Server & Forms Gary Ratcliffe.
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
Date : 3/04/2010 Web Technology Solutions Class: PHP Web Application Frameworks.
Unit 1 – Web Concepts Instructor: Brent Presley.
Since you’ll need a place for the user to enter a search query. Every form must have these basic components: – The submission type defined with the method.
 An essential supporting structure of any thing  A Software Framework  Has layered structure ▪ What kind of functions and how they interrelate  Has.
ITM © Port,Kazman 1 ITM 352 Cookies. ITM © Port,Kazman 2 Problem… r How do you identify a particular user when they visit your site (or any.
Dr. Abdullah Almutairi Spring PHP is a server scripting language, and a powerful tool for making dynamic and interactive Web pages. PHP is a widely-used,
Ruby on Rails. Web Framework for Ruby Designed to make it easier to develop, deploy, and maintain web applications Design with Model-View-Controller –almost.
PHP Tutorial. What is PHP PHP is a server scripting language, and a powerful tool for making dynamic and interactive Web pages.
BIT 286: Web Applications ASP.Net MVC. Objectives Applied MVC overview Controllers Intro to Routing Views ‘Convention over configuration’ Layout files.
1 Copyright © 2008, Oracle. All rights reserved. Repository Basics.
Top 50 Interview Questions & Answers in CakePHP. 2 Question : 1 What is CakePHP?  CakePHP is a free, open-source, rapid development framework for PHP.
CakePHP.
Web Technology Solutions
Play Framework: Introduction
Play Framework: Introduction
Haritha Dasari Josue Balandrano Coronel -
PHP Training at GoLogica in Bangalore
Unit 6-Chapter 2 Struts.
PHP / MySQL Introduction
MVC Framework, in general.
Web Browser server client 3-Tier Architecture Apache web server PHP
Chapter 15 Introduction to Rails.
Developing a Model-View-Controller Component for Joomla
Web Application Development Using PHP
Presentation transcript:

Amit Kumar Singh ITBrainShapers

MVC Model Data layer View Presentation layer Controller Logic layer

Typical Flow Script Client Data base

MVC Flow MVC can vary depending on the framework with which you’re working, but generally it works as follows 1. The client sends a page request to the application, either by typing a URL or by clicking a link of some kind. By convention, a typical URL is usually structured like this: n}/{Parameter 1, etc.} 2. The dispatcher script parses the URL structure and determines which controller to execute. It also passes along any actions and parameters to the controller.

3. The function in the controller may need to handle more data than just the parameters forwarded by the dispatcher. It will send database requests to the model script. 4. The model script determines how to interact with the database using the requests submitted by the controller. It may run queries with the database and do all sorts of handy data-sorting instructions. 5. Once the model has pulled any data from or sent data to the database, it returns its output to the controller.

Continue.. 6. The controller processes the data and outputs to the view file. 7. The view adds any design or display data to the controller output and sends its output to the client’s browser

Model Task {task.php} DATABASE TasksController Table tasks Index Method Done Method Undo Method ToDo Method request for /tasks/index WEB SERVER Request 1 Index Metho d Called 2 Data Requested 3 Data returned 4 Tasks Index View Tasks Index View Views Layout Tasks Index View Response 7 Index View selected 5 {index.thtml todo.thtml done.thtml} {tasks_controll er.php} {tasks.th tml} View combined with layout 6

MVC FLOW

CakePHP A framework for developing applications in PHP Inspired by Ruby on Rails Follows MVC design pattern Convention over configuration

CakePHP follows the MVC software design pattern. Programming using MVC separates your application into three main parts:MVC The Model represents the application data The View renders a presentation of model data The Controller handles and routes requests made by the client

Typical Flow Of CakePHP

CakePHP (or, for short, Cake) is a framework, not a set of libraries, even though it contains dozens of functions and methods that simplify web development much like libraries do. The benefit of using MVC to develop web sites is that repeated functions or tasks can be separated, thus allowing for quicker edits.

CRUD Operations and the Bake Script CRUD operations: create, read, update, and delete Stop writing each CRUD operation by hand,. Use prebuilt classes provided to do that. Cake includes the Bake script, a handy command-line tool that generates editable CRUD code based on your database schema and customized parameters. Scaffolding it figures out how some standard interface views should work with your database and outputs the HTML forms, all without you having to write one bit of HTML.

Helpers  Cake comes with standard HTML, Ajax, and JavaScript helpers that make creating views much easier Customizable Elements  You can customize each of Cake’s features to fit your application. For example, you can bring FCKeditor, the popular WYSIWYG editor for web browsers, into Cake as a plug-in.  Using customized helpers, you can bring all the functionality of FCKeditor into your Cake application and actually trim out extra lines of PHP code to get it working.

Other Features Cake offers, its repository of other powerful resources such as built-in validation access control lists (ACLs) data sanitization(Data Sanitization is the process of making sensitive information in non-production databases safe for wider visibility.) security and session handling components view caching

CakePHP Framework app/ config/ controllers/ models/ plugins/ tmp/ vendors/ views/ webroot/ cake/ config/ docs/ libs/ vendors/

The app folder will be where you work your magic: it’s where your application’s files will be placed. The cake folder is where we’ve worked our magic. Make a personal commitment not to edit files in this folder. We can’t help you if you’ve modified the core. Finally, the vendors folder is where you’ll place third- party PHP libraries you need to use with your CakePHP applications.

FolderWhat it Contains config Holds the (few) configuration files CakePHP uses. Database connection details, bootstrapping, core configuration files and more should be stored here. controllersContains your application’s controllers and their components. localeStores string files for internationalization. modelsContains your application’s models, behaviors, and datasources. pluginsContains plugin packages.

tmp This is where CakePHP stores temporary data. The actual data it stores depends on how you have CakePHP configured, but this folder is usually used to store model descriptions, logs, and sometimes session information. Make sure that this folder exists and that it is writable, otherwise the performance of your application will be severely impacted. In debug mode, CakePHP will warn you if it is not the case. vendors Any third-party classes or libraries should be placed here. Doing so makes them easy to access using the App::import('vendor', 'name') function. Keen observers will note that this seems redundant, as there is also a vendors folder at the top level of our directory structure. We'll get into the differences between the two when we discuss managing multiple applications and more complex system setups. views Presentational files are placed here: elements, error pages, helpers, layouts, and view files. webroot In a production setup, this folder should serve as the document root for your application. Folders here also serve as holding places for CSS stylesheets, images, and JavaScript files.

Controller Extension A Component is a class that aids in controller logic. If you have some logic you want to share between controllers (or applications), a component is usually a good fit. Controllers are also fitted with callbacks.

View Extension A Helper is a class that aids in view logic. Much like a component used among controllers, helpers allow presentational logic to be accessed and shared between views. One of the core helpers, AjaxHelper, makes Ajax requests within views much easier.

Model Extension Behaviors work as ways to add common functionality between models. models are featured with callbacks as well: beforeFind() afterFind() beforeValidate() beforeSave() afterSave() beforeDelete() afterDelete()

Callbacks available include: beforeFilter(), executed before any controller action logic beforeRender(), executed after controller logic, but before the view is rendered afterFilter(), executed after all controller logic, including the view render. There may be no difference between afterRender() and afterFilter() unless you’ve manually made a call to render() in your controller action and have included some logic after that call.

Application Extension Controllers, helpers and models each have a parent class you can use to define application-wide changes. AppController (located at /app/app_controller.php), AppHelper (located at /app/app_helper.php) and AppModel (located at /app/app_model.php) are great places to put methods you want to share between all controllers, helpers or models.

Convention Over Configuration File and ClassName Convention In general, filenames are underscored while classnames are CamelCased. So if you have a class MyStudentClass, then in Cake, the file should be named my_student_class.php.

Model and Database Convention Model classnames are singular and CamelCased. Ex:-Person, BigPerson, and ReallyBigPerson Table names corresponding to CakePHP models are plural and underscored. The underlying tables for the above mentioned models would be people, big_people, and really_big_people, respectively.

Controller Convention Controller classnames are plural, CamelCased, and end in Controller. PeopleController and LatestArticlesController are both examples of conventional controller names.

Continue.. he first method you write for a controller might be the index() method. When a request specifies a controller but not an action, the default CakePHP behavior is to execute the index() method of that controller.

View convention View template files are named after the controller functions they display, in an underscored form. The getReady() function of the PeopleController class will look for a view template in /app/views/people/get_ready.ctp.

Example Here’s a final example that ties the conventions Database table: "people" Model class: "Person", found at /app/models/person.php Controller class: "PeopleController", found at /app/controllers/people_controller.php View template, found at /app/views/people/index.ctp

Flow CakePHP knows that a request to maps to a call on the index() function of the PeopleController, where the Person model is automatically available (and automatically tied to the ‘people’ table in the database), and renders to a file. None of these relationships have been configured by any means other than by creating classes and files that you’d need to create anyway.

Naming conventions Conventions Table names: “notes”, “my_notes” Model: “mynote.php”->“MyNote” Controller: “my_notes_controller.php”-> “MyNotesController” Views named after actions, organised in folders according to the related controller: views/my_notes/index.thtml views/my_notes/add.thtml

table name -students Model class Student save as student.php controller class StudentsController -students_controller.php view Create one folder in views folder named as controller name foldername =students view file extendsion must be.ctp or.thtml

Paths + parameters Cake uses url to pass parameters Apache mod_rewrite converts url into scriptname and parameters /controllername/action/param1/param2/… Uses paths to figure out views Views stored in “controllername” folder

OOP in PHP Limited support in PHP <5 Much better support in PHP >=5 Simpler than Java OOP class SomeClass { function func() { …. } SomeClass s = new someClass(); s->func();

Hello world… again Remember application is separated into model / view / controller Model: <?php /* /app/model/hello.php */ class Hello extends AppModel { var $name = 'Hello'; var $useTable = false; } ?>

Hello world… again View: <!-- /* /app/views/index.thtml */ -->

Controller: <?php /* app/controller/hello_controller.php */ class HelloController extends AppController { var $name = "Hello"; var $uses = 'Hello'; function index() { $data = 'Hello world!'; $this->set('data', $data); } ?>

Simple DB table app An online contact list We want to add, edit, view and delete names and phone numbers Uses a single table

Model Add table to DB: CREATE TABLE cake_contacts ( id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY, name VARCHAR(50), number VARCHAR(50), created DATETIME DEFAULT NULL, modified DATETIME DEFAULT NULL );

Model Add a script called contact.php to models/ <?php class Contact extends AppModel { var $name = ‘Contact'; } ?>

View views/contacts/index.thtml Contact list link('Add Contact', 'contacts/add') ?> Id Name Number

View views/contacts/index.thtml cntd… <?php echo $html->link($contact['Contact'][name'], "contacts/view/{$contact['Contact']['id']}")?> [ link('Edit', "contacts/edit/{$contact['Contact']['id']}")?>, link('Delete', "contacts/delete/{$contact['Contact']['id']}", null, 'Sure?')?>]

View views/contacts/view.thtml Created:

View views/contacts/add.thtml Add Contact url("contacts/add"); ?>" method="post"> Name: input('Contact/name', array('size' => '40')) ?> Number: input('Contact/number', array('size' => '40')) ?> submit('Save') ?>

View views/contacts/edit.thtml Edit Contact url('/contacts/edit')?>" method="post"> hidden('Contact/id'); ?> Name: input('Contact/name', array('size' => '40')) ?> Number: input('Contact/number', array('size' => '40')) ?> submit('Save') ?>

Controller /app/controllers/notes_controller.php: <?php class ContactsController extends AppController { var $name = 'Contacts'; function index() { $this->set('contacts', $this->Contact- >findAll()); } function view($id) { $this->Contact->id = $id; $this->set('data', $this->Contact->read()); }

Controller /app/controllers/notes_controller.php: function add() { if (!empty($this->data['Contact'])) { if($this->Contact->save($this->data['Contact'])) { $this->flash('Your contact has been added.', ‘/contacts/'); } function delete($id) { if ($this->Contact->del($id)) { $this->flash('The contact with id: '.$id.' has been deleted.', ‘/contacts/'); }

Controller /app/controllers/notes_controller.php: function edit($id = null) { if (empty($this->data['Contact'])) { $this->Contact->id = $id; $this->data = $this->Contact->read(); } else { if($this->Contact->save($this->data['Contact'])) { $this->flash('Your contact has been updated.',‘/contacts/'); } ?>

Resulting application …../cake/contacts/view/4…../cake/contacts/edit/1…../cake/contacts/add

Other benefits Bake script – command line script generator Uses LAMP common web platform (Linux, Apache, MySQL and PHP) Helpers for HTML, Forms, Pagination, AJAX, Javascript, XML, RSS Scaffolding (no need for views) Create controller with var $scaffold;

Disadvantages Mainly due to the limitations of PHP Clumsy OOP Access data through arrays not classes (which RoR does) – more code in view Create tables in separate SQL Not well documented yet