CAKEPHP Blog tutorial. what you’ll need examples/blog/blog.html 2  A running web server  A database server.

Slides:



Advertisements
Similar presentations
PHP + Framework + MVC. What is Framework? Common code - Generic functionality Extensible - Specific functionality Unlike library – Flow Dictated by.
Advertisements

MY NCBI (module 4.5). MODULE 4.5 PubMed/How to Use MY NCBI Instructions - This part of the: course is a PowerPoint demonstration intended to introduce.
Child Health Reporting System (CHRS) How to Submit VHSS Data
CakePHP. A framework for developing applications in PHP Inspired by Ruby on Rails Follows MVC design pattern Convention over configuration –No wheel reinventing.
Unicenter© ServicePlus Service Desk How to manage helpdesk tickets
MY NCBI (module 4.5). MODULE 4.5 PubMed/How to Use MY NCBI Instructions - This part of the:  course is a PowerPoint demonstration intended to introduce.
MY NCBI (module 4.5).
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.
Keys, Referential Integrity and PHP One to Many on the Web.
1.  Understanding about How to Working with Server Side Scripting using PHP Framework (CodeIgniter) 2.
Logging In Go to web site:
How to post to Wordpress Chruton Budd. Click on the Login link.
NMED 3850 A Advanced Online Design February 25, 2010 V. Mahadevan.
Manipulating MySQL Databases with PHP. PHP and mySQL2 Objectives Connect to MySQL from PHP Learn how to handle MySQL errors Execute SQL statements with.
New Student Orientation Registration System Stephen Nakamura EE496 Final Presentation Fall 2008.
Database Updates Made Easy In WebFocus Using SQL And HTML Painter Sept 2011 Lender Processing Services 1.
PHP & MySQL Mahak Arora Vivek Bangera. Outline How PHP works Basic scripting in PHP Forms in PHP(GET & POST Variables) SQL basics PHP and MySQL connection.
MVC in Trax.
Lecture 3 – Data Storage with XML+AJAX and MySQL+socket.io
PHP1-1 PHP & SQL Xingquan (Hill) Zhu
1Computer Sciences Department Princess Nourah bint Abdulrahman University.
A Guide to SQL, Eighth Edition Chapter Three Creating Tables.
Session 5: Working with MySQL iNET Academy Open Source Web Development.
Website Security ISYS 475. Authentication Authentication is the process that determines the identity of a user.
1 PHP and MySQL. 2 Topics  Querying Data with PHP  User-Driven Querying  Writing Data with PHP and MySQL PHP and MySQL.
PHP and MySQL for Client-Server Database Interaction Chapter 10.
WaveMaker Visual AJAX Studio 4.0 Training Authentication.
Mark Dixon Page 1 23 – Web applications: Writing data to Databases using PhP.
© 2003 By Default! A Free sample background from Slide 1 Week 2  Free PHP Hosting Setup  PHP Backend  Backend Security 
12/6/2012ISC329 Isabelle Bichindaritz1 The Dreamhome Online Real- estate Company Management System.
Dbwebsites 2.1 Making Database backed Websites Session 2 The SQL… Where do we put the data?
Sayed Ahmed Computer Engineering, BUET, Bangladesh MSc., Computer Science, Canada
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.
Introduction to Entity Framework Part 2 CRUD Scaffolding Tom Perkins NTPCUG.
Introduction to MySQL Lab no. 10 Advance Database Management System.
Installing and Using MySQL and phpMyAdmin. Last Time... Installing Apache server Installing PHP Running basic PHP scripts on the server Not necessary.
Web Scripting [PHP] CIS166AE Wednesdays 6:00pm – 9:50pm Rob Loy.
SYST Web Technologies SYST Web Technologies Databases & MySQL.
Database and mySQL Week 07 Dynamic Web TCNJ Jean Chu.
Web Scripting [PHP] CIS166AE Wednesdays 6:00pm – 9:50pm Rob Loy.
ASP.NET The Clock Project. The ASP.NET Clock Project The ASP.NET Clock Project is the topic of Chapter 23. By completing the clock project, you will learn.
PHP MySQL Image Gallery. The admin section contain the following : Add New Album Album List Edit & Delete Album Add Image Image List Edit & Delete Image.
Keywords Searching and Analysis System Member Student ID Role 刘亮 Liu Liang System Analyst 顾子俊 Gu Zijun Developer 杜菡菡 Du Hanhan
MVC Concepts Basics Model-View-Controller (MVC) Concepts for Web Developers SoftUni Team Technical Trainers Software University
Global Teacher Blogs. Blogs – (Web log) a blog is a web site that is usually used as an individual journal and is publicly accessible. (
XRX Basic CRUDS Create, Read, Update and Delete and Search XML Data Date: May 2011 Dan McCreary President Dan McCreary & Associates
GOAL User Interactive Web Interface Update Pages by Club Officers Two Level of Authentication.
How does Drupal Work? Information Systems 337 Prof. Harry Plantinga.
Creating a simple database This shows you how to set up a database using PHPMyAdmin (installed with WAMP)
Lecture Capture and. Goal Link to D2L D2L Website
Chapter 8 Manipulating MySQL Databases with PHP PHP Programming with MySQL 2 nd Edition.
Date : 3/04/2010 Web Technology Solutions Class: PHP Web Application Frameworks.
Information Management System “Institutions Module" Information Management System “Institutions Module" The System management module is an integrated part.
MySQL MySQL and PHP – interacting with a database.
Introduction to MySQL Ullman Chapter 4. Introduction MySQL most popular open-source database application Is commonly used with PHP We will learn basics.
Web Application Design. Data –What data is available? –How do we store it or how is it stored in the DB? Schema Data types Etc. –Where is the data?
Introduction to MySQL  Working with MySQL and MySQL Workbench.
BIT 286: Web Applications Lecture 04 : Thursday, January 15, 2015 ASP.Net MVC -
Top 50 Interview Questions & Answers in CakePHP. 2 Question : 1 What is CakePHP?  CakePHP is a free, open-source, rapid development framework for PHP.
COM621: Advanced Interactive Web Development Lecture 10 PHP and MySQL.
Flash Board MX PHP Files CISC 254. Fix for Global Variables foreach($HTTP_GET_VARS as $name => $value) { $$name = $value;} foreach($HTTP_POST_VARS as.
IS232 Lab 9. CREATE USER Purpose: Use the CREATE USER statement to create and configure a database user, which is an account through which you can log.
CakePHP.
Intro to WordPress (Using XAMPP)
Introduction to Dynamic Web Programming
Storing Images Connect to the server using the correct username and password. $conn = mysql_connect(“yourserver”, “joeuser”, “yourpass”); Create the database.
Quickr Places & Templates Introduction
Presentation transcript:

CAKEPHP Blog tutorial

what you’ll need examples/blog/blog.html 2  A running web server  A database server  Basic PHP knowledge  basic knowledge of the MVC

Database /* First, create our posts table: */ CREATE TABLE posts ( id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY, title VARCHAR(50), body TEXT, created DATETIME DEFAULT NULL, modified DATETIME DEFAULT NULL ); /* Then insert some posts for testing: */ INSERT INTO posts (title,body,created) VALUES ('The title', 'This is the post body.', NOW()); INSERT INTO posts (title,body,created) VALUES ('A title once again', 'And the post body follows.', NOW()); INSERT INTO posts (title,body,created) VALUES ('Title strikes back', 'This is really exciting! Not.', NOW());

First ugly Look examples/blog/blog.html 4

A Note on mod_rewrite examples/blog/blog.html 5  Make sure that an.htaccess override is allowed  Make sure you are editing the correct httpd.conf  Make sure Apache is loading up mod_rewrite  LoadModule rewrite_module

Half Done examples/blog/blog.html 6

Cake Database Configuration examples/blog/blog.html 7  /app/Config/database.php.default  Rename to database.php  Fill in your own DB configurations  /app/Config/core.php  Configure::write('Security.salt',  Configure::write('Security.cipherSeed', ' ');

Ready to Go examples/blog/blog.html 8

Controller examples/blog/blog.html 9 class PostsController extends AppController { public $helpers = array('Html', 'Form'); public function index() { $this->set('posts', $this->Post->find('all')); }

Index View examples/blog/blog.html 10 Html->link($post['Post']['title'], array('controller' => 'posts', 'action' => 'view', $post['Post']['id'])); ?>

Add Action examples/blog/blog.html 11 public function add() { if ($this->request->is('post')) { $this->Post->create(); if ($this->Post->save($this->request->data)) { $this->Session->setFlash('Your post has been saved.'); $this->redirect(array('action' => 'index')); } else { $this->Session->setFlash('Unable to add your post.'); }

Add View examples/blog/blog.html 12 Add Post <?php echo $this->Form->create('Post'); echo $this->Form->input('title'); echo $this->Form->input('body', array('rows' => '3')); echo $this->Form->end('Save Post'); ?>

What Helpers do examples/blog/blog.html 13  $this->Form->create()   $this->Html->link('Add Post', array('controller' => 'posts', 'action' => 'add'));  Hyper Link  echo $this->Form->postLink( 'Delete', array('action' => 'delete', $post['Post']['id']), array('confirm' => 'Are you sure?')); ?

Edit Action examples/blog/blog.html 14 public function edit($id = null) { $this->Post->id = $id; if ($this->request->is('get')) { $this->request->data = $this->Post->read(); } else { if ($this->Post->save($this->request->data)) { $this->Session->setFlash('Your post has been updated.'); $this->redirect(array('action' => 'index')); } else { $this->Session->setFlash('Unable to update your post.'); }

Delete Action examples/blog/blog.html 15 public function delete($id) { if ($this->request->is('get')) { throw new MethodNotAllowedException(); } if ($this->Post->delete($id)) { $this->Session->setFlash('The post with id: '. $id. ' has been deleted.'); $this->redirect(array('action' => 'index')); }

Routes, /app/Config/routes.php examples/blog/blog.html 16  Router::connect('/', array('controller' => 'pages', 'action' => 'display', 'home'));  Router::connect('/', array('controller' => 'posts', 'action' => 'index'));

Layout examples/blog/blog.html 17  fetch('content'); ?>  echo $this->fetch('meta');  echo $this->fetch('css');  echo $this->fetch('script');

Switch layouts examples/blog/blog.html 18 public function admin_view() { // stuff $this->layout = 'admin'; }

Elements /app/View/Elements/helpbox.ctp examples/blog/blog.html 19  element('helpbox'); ?>  echo $this->element('helpbox', array( "helptext" => "Oh, this text is very helpful." ));

Scaffolding examples/blog/blog.html 20 <?php class CategoriesController extends AppController { public $scaffold; }

Simple Authentication and Authorization Application examples/blog/blog.html 21 CREATE TABLE users ( id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY, username VARCHAR(50), password VARCHAR(50), role VARCHAR(20), created DATETIME DEFAULT NULL, modified DATETIME DEFAULT NULL );

User Model examples/blog/blog.html 22 class User extends AppModel { public $validate = array( 'username' => array( 'required' => array( 'rule' => array('notEmpty'), 'message' => 'A username is required' ) ), 'password' => array( 'required' => array( 'rule' => array('notEmpty'), 'message' => 'A password is required' ) ), ); }

ByPass Some Views examples/blog/blog.html 23 public function beforeFilter() { parent::beforeFilter(); $this->Auth->allow('add', 'logout'); }

AppController examples/blog/blog.html 24 public $components = array( 'Session', 'Auth' => array( 'loginRedirect' => array('controller' => 'posts', 'action' => 'index'), 'logoutRedirect' => array('controller' => 'pages', 'action' => 'display', 'home') ) ); public function beforeFilter() { $this->Auth->allow('index', 'view'); }

Login Logout examples/blog/blog.html 25 public function login() { if ($this->request->is('post')) { if ($this->Auth->login()) { $this->redirect($this->Auth->redirect()); } else { $this->Session->setFlash(__('Invalid username or password, try again')); } public function logout() { $this->redirect($this->Auth->logout()); }

Encrypt password examples/blog/blog.html 26 public function beforeSave($options = array()) { if (isset($this->data[$this->alias]['password'])) { $this->data[$this->alias]['password'] = AuthComponent::password($this->data[$this- >alias]['password']); } return true; }

Login View examples/blog/blog.html 27 Session->flash('auth'); ?> Form->create('User'); ?> <?php echo $this->Form->input('username'); echo $this->Form->input('password'); ?> Form->end(__('Login')); ?>

Who is Login? examples/blog/blog.html 28  $this->Auth->user('id')  Null if not logged in  Another Way public function isAuthorized($user) { // Admin can access every action if (isset($user['role']) && $user['role'] === 'admin') { return true; }