SlideShare une entreprise Scribd logo
1  sur  53
Télécharger pour lire hors ligne
GET THINGS DONE WITH

 QUICKLY BUILD A WEBAPP USING YII




  GIULIANO IACOBELLI - @Giuliano84 - me@giulianoiacobelli.com
WEB IS FULL OF AMAZING TOOLS
USUALLY EVERYTHING STARTS
      FROM AN IDEA
IF IT’S THE RIGHT ONE
AND IS WELL EXECUTED..
IF YOU HAVE GOOD IDEA, DO IT.
MOVE FAST AND
BREAK THINGS
SO LET ME INTRODUCE YOU TO
WHAT IS IT?

Yii is a high-performance component-based
PHP framework for developing large-scale
Webapplications. It enables maximum
reusability in Web programming and can
significantly accelerate the development
process.
IT’S EASY?
IT’S RAPID?
IT’S SECURE?

         YES IT IS (YII) !!!
THE MVC PATTERN
MVC is a design pattern
widely adopted in Web
programming that aims to
separate business logic from
user interface
considerations, so that
developers can more easily
change each part without
affecting the other.
THE MVC PATTERN
 Assume a Web application consists of several sub-
 applications:

• Front end: a public-facing website for normal end users;
• Back end: a website that exposes administrative
  functionality for managing the application.
• Console: an application consisting of console commands
  to be run in a terminal window or as scheduled jobs to
  support the whole application;
• Web API: providing interfaces to third parties for
  integrating with the application.
M for MODEL
 Models are used to keep data and their relevant business rules. A
 model represents a single data object that could be a row in a
 database table or a form of user inputs.


• should contain properties to represent specific data;
• should contain business logic (e.g. validation rules) to ensure
  the represented data fulfills the design requirement;
• may contain code for manipulating data. For example, a
  SearchForm model, besides representing the search input data,
  may contain a search method to implement the actual search.
C for CONTROLLER

Controllers are the glue that binds models, views and other
components together into a runnable application. They are
responsible for dealing directly with end user requests.

• may access $_GET, $_POST and other PHP variables that
  represent user requests;
• may create model instances and manage their life cycles.
• should avoid containing embedded SQL statements, which are
  better kept in models.
• should avoid containing any HTML or any other presentational
  markup. This is better kept in views.
V for VIEW

A view is a PHP script consisting of mainly elements of user interface
the spirit of seperation of logic and presentation, large chunk of logic
should be placed in controller or model instead of view.

• should mainly contain presentational code, such as HTML, and
  simple PHP code to traverse, format and render data;
• should avoid containing code that performs explicit DB queries.
  Such code is better placed in models.
• should avoid direct access to $_GET, $_POST, or other similar
  variables that represent the end user request. This is the
  controller's job.
STRUCTURE OF YII APPLICATION
THE ENTRY SCRIPT
This is a “bootstrap” file, meaning that all user interactions actually
go through it. For example, showing an employee record might be
through the URL. It is the only PHP script that end users can directly
request to execute.


  // remove the following line when in production mode
  defined('YII_DEBUG') or define('YII_DEBUG',true);
  // include Yii bootstrap file
  require_once('path/to/yii/framework/yii.php');
  // create application instance and run
  $configFile='path/to/config/file.php';
  Yii::createWebApplication($configFile)->run();
YII WORKFLOW
      1 - Request with the URL
      http://example.com/index.php?r=post/
      show&id=1 and the Web server handles the
      request by executing the bootstrap script
      index.php.

      2 - The bootstrap script creates an
      Application instance and runs it.

      3 - The Application obtains detailed user
      request information from an application
      component named request.

      4 - The application determines the requested
      controller and action with the help of an
      application component named urlManager.
YII WORKFLOW
      5 - The application creates an instance of the
      requested controller to further handle the
      user request. The controller determines that
      the action show refers to a method named
      actionShow in the controller class.

      6 - The action reads a Post model whose ID is
      1 from the database.

      7 - The action renders a view named show
      with the Post model.

      8 - The view reads and displays the attributes
      of the Post model.

      9,10,11 - The view executes some widgets,
      embed the rendering result in a layout and
      displays it to the user.
OK, OK, I GOT IT, TOO MUCH TALK..




LET’S HAVE AN IDEA TO BUILD..
AND THE AMAZING IDEA IS..
A BLOG!
OK, IT’S NOT THAT AMAZING BUT IN THIS
WAY I’M PRETTY SURE THAT ALL OF YOU
 KNOW WHAT WE ARE GOIN TO BUILD
WARM UP

 • CREATE A “BLOGDEMO” FOLDER
   IN YOUR APACHE DOCUMENT
   ROOT DIRECTORY
 • DOWNLOAD YiiBlogDemo.zip FILE
   FROM http://goo.gl/nOqef AND
   UNZIP IT
 • OPEN FRAMEWORK.ZIP AND
   PLACE ITS CONTENT IN YOUR
   “BLOGDEMO” FOLDER
YII PREPARATION

Run a simple console command
“blogdemo/framework/yiic         webapp ../“

to generate a skeleton Web application built with Yii.
This will create a skeleton Yii application under the
directory WebRoot/testdrive.
THE WEB APPLICATION




The application is fully functional, with nice features
including user login and contact form. It is a good starting
point for implementing more sophisticated features.
WHAT A BLOG USUALLY HAVE?


              •   POSTS
              •   USERS
              •   COMMENTS
              •   TAGS
DBSCHEMA.SQL
SETTING UP THE DATABASE
return array(
     ......
     'components'=>array(
          ......
         'db'=>array(
              'connectionString' => 'mysql:host=localhost;dbname=blog',
              'emulatePrepare' => true,
              'username' => 'root',
              'password' => '',
              'charset' => 'utf8',
              'tablePrefix' => 'tbl_',
         ),
     ),
   ......
);
GENERATING THE MODELS
We need to create a model class for each of our database
tables. Yii has an amazing component called Gii that totally
automates this process (known as scaffolding) for us.


 'modules'=>array(
         'gii'=>array(
             'class'=>'system.gii.GiiModule',
             'password'=>'pick up a password here',
         ),
     ),
GII MODEL GENERATOR
OUR MODELS
• User.php contains the User class and can be used to access
  the tbl_user database table;
• Post.php contains the Post class and can be used to access
  the tbl_post database table;
• Tag.php contains the Tag class and can be used to access the
  tbl_tag database table;
• Comment.php contains the Comment class and can be used
  to access the tbl_comment database table;
• Lookup.php contains the Lookup class and can be used to
  access the tbl_lookup database table.
CRUD OPERATIONS
After the model classes are created, we can use the Crud
Generator to generate the code implementing the CRUD
operations for these models. We will do this for the Post
and Comment models.
AUTHENTICATING USER

Our blog application needs to differentiate between
the system owner and guest users. Therefore, we need
to implement the user authentication feature
User authentication is performed in a class
implementing the IUserIdentity interface. The skeleton
application uses the UserIdentity class for this
purpose.

The class is stored in the file /wwwroot/blogdemo/
protected/components/UserIdentity.php.
AUTHENTICATING USER



Application already provides user authentication
by checking if the username and password are
both demo or admin.
Now we will modify the corresponding code so
that the authentication is done against the User
database table.
EDITING USERIDENTITY.PHP
public function authenticate()
{
    $username=strtolower($this->username);
    $user=User::model()->find('LOWER(username)=?',array($username));
    if($user===null)
        $this->errorCode=self::ERROR_USERNAME_INVALID;
    else if(!$user->validatePassword($this->password))
        $this->errorCode=self::ERROR_PASSWORD_INVALID;
    else
    {
        $this->_id=$user->id;
        $this->username=$user->username;
        $this->errorCode=self::ERROR_NONE;
    }
    return $this->errorCode==self::ERROR_NONE;
}

public function getId()
{
    return $this->_id;
}
RECAP
• Identified the requirements to be fulfilled;
• We installed the Yii framework and created a skeleton
  application;
• We designed and created the blog database;
• We generated basic CRUD operations;
• We modified the authentication method to check
  against the tbl_user table.
CUSTOMIZING POST MODEL
Post model generated is fine but now we need to specify
validation rules and related objects
• Validation rules ensure the attribute values entered by
  users are correct before they are saved to the database.
  For example, the status attribute of Post should be an
  integer 1, 2 or 3.
• Customizing the relations we can exploit the powerful
  Relational ActiveRecord (RAR) feature to access the
  related object information of a post, such as its author
  and comments, without the need to write complex SQL
  statements.
VALIDATION RULES
Based on the requirement analysis, we modify the
rules() method as follows:

public function rules()
{
    return array(
        array('title, content, status', 'required'),
        array('title', 'length', 'max'=>128),
        array('status', 'in', 'range'=>array(1,2,3)),
        array('tags', 'match', 'pattern'=>'/^[ws,]+$/',
            'message'=>'Tags can only contain word characters.'),
        array('tags', 'normalizeTags'),

         array('title, status', 'safe', 'on'=>'search'),
    );
}
MODEL RELATIONS
We customize relations() method as follow
public function relations()
{
    return array(
        'author' => array(self::BELONGS_TO, 'User', 'author_id'),
        'comments' => array(self::HAS_MANY, 'Comment', 'post_id',
            'condition'=>'comments.status='.Comment::STATUS_APPROVED,
            'order'=>'comments.create_time DESC'),
        'commentCount' => array(self::STAT, 'Comment', 'post_id',
            'condition'=>'status='.Comment::STATUS_APPROVED),
    );
}




We also introduce in the Comment      class Comment extends CActiveRecord
                                      {
model class two constants that are        const STATUS_PENDING=1;
used in the above method:                 const STATUS_APPROVED=2;
                                          ......
                                      }
REPRESENTING STATUS IN TEXT

Because the status of a post is stored as an integer in the
database, we need to provide a textual representation so that it
is more intuitive when being displayed to end users. In a large
system, the similar requirement is very common.
As a generic solution, we use the tbl_lookup table to store the
mapping between integer values and textual representations
that are needed by other data objects.

We modify the Lookup model class as follows to more easily
access the textual data in the table.
LOOKUP.PHP
class Lookup extends CActiveRecord
{
    private static $_items=array();
    public static function items($type)
    {
        if(!isset(self::$_items[$type]))
            self::loadItems($type);
        return self::$_items[$type];
    }

    public static function item($type,$code)
    {
        if(!isset(self::$_items[$type]))
            self::loadItems($type);
        return isset(self::$_items[$type][$code]) ? self::$_items[$type][$code] : false;
    }

    private static function loadItems($type)
    {
        self::$_items[$type]=array();
        $models=self::model()->findAll(array(
            'condition'=>'type=:type',
            'params'=>array(':type'=>$type),
            'order'=>'position',
        ));
        foreach($models as $model)
            self::$_items[$type][$model->code]=$model->name;
    }
}
POST POSSIBLE STATUSES

              class Post extends CActiveRecord
              {
                  const STATUS_DRAFT=1;
                  const STATUS_PUBLISHED=2;
                  const STATUS_ARCHIVED=3;
                  ......
              }




Now we can call Lookup::items('PostStatus') to get the
list of possible post statuses (text strings indexed by the
corresponding integer values), and call
Lookup::item('PostStatus', Post::STATUS_PUBLISHED) to
get the string representation of the published status.
CONFIGURING ACCESS RULES
public function accessRules()
{
    return array(
        array('allow', // allow all users to perform 'list' and 'show'
actions
            'actions'=>array('index', 'view'),
            'users'=>array('*'),
        ),
        array('allow', // allow authenticated users to perform any action
            'users'=>array('@'),
        ),
        array('deny', // deny all users
            'users'=>array('*'),
        ),
    );
}



  The rules state that all users can access the index and
  view actions, and authenticated users can access any
  actions, including the admin action.
CREATE AND UPDATE
The create and update operations are very similar. They both
need to display an HTML form to collect user inputs, validate
them, and save them into database.
Gii generates a partial view /wwwroot/blog/protected/views/
post/_form.php that is embedded in both the create and update
views to render the needed HTML form.
We want to add a dropdown list to collect user input for STATUS
attribute

echo $form->dropDownList($model,'status',Lookup::items('PostStatus'));
CREATE AND UPDATE
We then modify the Post class so that it can automatically set
some attributes (create_time, author_id) before a post is
saved to the database. We override the beforeSave() method
as follows
     protected function beforeSave() {
         if(parent::beforeSave())
         {
             if($this->isNewRecord)
             {
                 $this->create_time=$this->update_time=time();
                 $this->author_id=Yii::app()->user->id;
             }
             else
                 $this->update_time=time();
             return true;
         }
         else
             return false;
     }
STYLE MATTERS
HOW TO BORROW SOME STYLE?




  http://twitter.github.com/bootstrap
QUICKLY BUILD A NICE UI
WEB AS CONCEPT IS REALLY WIDE
MOBILE
FIRST!
LOOK AT THE NUMBERS




 http://www.phonecount.com/pc/count.jsp
RESPONSIVE DESIGN 101
BOOTSTRAP RESPONSIVENESS
It supports a handful of media queries in a single file to
help make your projects appropriate on different devices
and screen resolutions.




          @media (min-width:400px) {           }
Thanks

                                    Giuliano Iacobelli
                                         giuliano.iacobelli
                                         me@giulianoiacobelli.com
                                         http://giulianoiacobelli.com

                                     Connect with me:




Ps: slide 47 and 48 were borrowed from this amazing presentation of Brad Frost

Contenu connexe

Tendances

RichFaces 4: Rich Ajax Components For Your JSF Applications
RichFaces 4: Rich Ajax Components For Your JSF ApplicationsRichFaces 4: Rich Ajax Components For Your JSF Applications
RichFaces 4: Rich Ajax Components For Your JSF ApplicationsMax Katz
 
Ajax Applications with JSF 2 and New RichFaces 4 - TSSJS
Ajax Applications with JSF 2 and New RichFaces 4 - TSSJSAjax Applications with JSF 2 and New RichFaces 4 - TSSJS
Ajax Applications with JSF 2 and New RichFaces 4 - TSSJSMax Katz
 
An Introduction to Django Web Framework
An Introduction to Django Web FrameworkAn Introduction to Django Web Framework
An Introduction to Django Web FrameworkDavid Gibbons
 
Javascript framework and backbone
Javascript framework and backboneJavascript framework and backbone
Javascript framework and backboneDaniel Lv
 
How to Webpack your Django!
How to Webpack your Django!How to Webpack your Django!
How to Webpack your Django!David Gibbons
 
JoomlaDay Chicago 2017 Keynote Address
JoomlaDay Chicago 2017 Keynote AddressJoomlaDay Chicago 2017 Keynote Address
JoomlaDay Chicago 2017 Keynote Addressjdaychi
 
Rapid application development with FOF
Rapid application development with FOFRapid application development with FOF
Rapid application development with FOFNicholas Dionysopoulos
 
Learning C# iPad Programming
Learning C# iPad ProgrammingLearning C# iPad Programming
Learning C# iPad ProgrammingRich Helton
 
Testdrive AngularJS with Spring 4
Testdrive AngularJS with Spring 4Testdrive AngularJS with Spring 4
Testdrive AngularJS with Spring 4Oliver Wahlen
 
Getting Started With AngularJS
Getting Started With AngularJSGetting Started With AngularJS
Getting Started With AngularJSEdureka!
 
Implementing auto complete using JQuery
Implementing auto complete using JQueryImplementing auto complete using JQuery
Implementing auto complete using JQueryBhushan Mulmule
 
Angular tutorial
Angular tutorialAngular tutorial
Angular tutorialRohit Gupta
 
Introduction to jQuery
Introduction to jQueryIntroduction to jQuery
Introduction to jQueryAlek Davis
 
Building a Simple Mobile-optimized Web App Using the jQuery Mobile Framework
Building a Simple Mobile-optimized Web App Using the jQuery Mobile FrameworkBuilding a Simple Mobile-optimized Web App Using the jQuery Mobile Framework
Building a Simple Mobile-optimized Web App Using the jQuery Mobile FrameworkSt. Petersburg College
 
RichFaces 4 webinar #1: Everything You Need To Know
RichFaces 4 webinar #1: Everything You Need To KnowRichFaces 4 webinar #1: Everything You Need To Know
RichFaces 4 webinar #1: Everything You Need To KnowMax Katz
 
Developing a Joomla 3.x Component using RAD FOF- Part 2: Front-end + demo - J...
Developing a Joomla 3.x Component using RAD FOF- Part 2: Front-end + demo - J...Developing a Joomla 3.x Component using RAD FOF- Part 2: Front-end + demo - J...
Developing a Joomla 3.x Component using RAD FOF- Part 2: Front-end + demo - J...Peter Martin
 
Universal JS Web Applications with React - Luciano Mammino - Codemotion Rome ...
Universal JS Web Applications with React - Luciano Mammino - Codemotion Rome ...Universal JS Web Applications with React - Luciano Mammino - Codemotion Rome ...
Universal JS Web Applications with React - Luciano Mammino - Codemotion Rome ...Luciano Mammino
 

Tendances (20)

RichFaces 4: Rich Ajax Components For Your JSF Applications
RichFaces 4: Rich Ajax Components For Your JSF ApplicationsRichFaces 4: Rich Ajax Components For Your JSF Applications
RichFaces 4: Rich Ajax Components For Your JSF Applications
 
Ajax Applications with JSF 2 and New RichFaces 4 - TSSJS
Ajax Applications with JSF 2 and New RichFaces 4 - TSSJSAjax Applications with JSF 2 and New RichFaces 4 - TSSJS
Ajax Applications with JSF 2 and New RichFaces 4 - TSSJS
 
An Introduction to Django Web Framework
An Introduction to Django Web FrameworkAn Introduction to Django Web Framework
An Introduction to Django Web Framework
 
Javascript framework and backbone
Javascript framework and backboneJavascript framework and backbone
Javascript framework and backbone
 
How to Webpack your Django!
How to Webpack your Django!How to Webpack your Django!
How to Webpack your Django!
 
JoomlaDay Chicago 2017 Keynote Address
JoomlaDay Chicago 2017 Keynote AddressJoomlaDay Chicago 2017 Keynote Address
JoomlaDay Chicago 2017 Keynote Address
 
Rapid application development with FOF
Rapid application development with FOFRapid application development with FOF
Rapid application development with FOF
 
Learning C# iPad Programming
Learning C# iPad ProgrammingLearning C# iPad Programming
Learning C# iPad Programming
 
Fame
FameFame
Fame
 
Testdrive AngularJS with Spring 4
Testdrive AngularJS with Spring 4Testdrive AngularJS with Spring 4
Testdrive AngularJS with Spring 4
 
Getting Started With AngularJS
Getting Started With AngularJSGetting Started With AngularJS
Getting Started With AngularJS
 
Implementing auto complete using JQuery
Implementing auto complete using JQueryImplementing auto complete using JQuery
Implementing auto complete using JQuery
 
Spring aop
Spring aopSpring aop
Spring aop
 
Angular tutorial
Angular tutorialAngular tutorial
Angular tutorial
 
Introduction to jQuery
Introduction to jQueryIntroduction to jQuery
Introduction to jQuery
 
Building a Simple Mobile-optimized Web App Using the jQuery Mobile Framework
Building a Simple Mobile-optimized Web App Using the jQuery Mobile FrameworkBuilding a Simple Mobile-optimized Web App Using the jQuery Mobile Framework
Building a Simple Mobile-optimized Web App Using the jQuery Mobile Framework
 
RichFaces 4 webinar #1: Everything You Need To Know
RichFaces 4 webinar #1: Everything You Need To KnowRichFaces 4 webinar #1: Everything You Need To Know
RichFaces 4 webinar #1: Everything You Need To Know
 
Developing a Joomla 3.x Component using RAD FOF- Part 2: Front-end + demo - J...
Developing a Joomla 3.x Component using RAD FOF- Part 2: Front-end + demo - J...Developing a Joomla 3.x Component using RAD FOF- Part 2: Front-end + demo - J...
Developing a Joomla 3.x Component using RAD FOF- Part 2: Front-end + demo - J...
 
Universal JS Web Applications with React - Luciano Mammino - Codemotion Rome ...
Universal JS Web Applications with React - Luciano Mammino - Codemotion Rome ...Universal JS Web Applications with React - Luciano Mammino - Codemotion Rome ...
Universal JS Web Applications with React - Luciano Mammino - Codemotion Rome ...
 
Booting up with polymer
Booting up with polymerBooting up with polymer
Booting up with polymer
 

En vedette

Agile web application development YII Framework
Agile web application development YII FrameworkAgile web application development YII Framework
Agile web application development YII FrameworkBeehexa
 
Membuat Aplikasi Kesiswaan Menggunakan Yii Framework - Bagian 2
Membuat Aplikasi Kesiswaan Menggunakan Yii Framework - Bagian 2Membuat Aplikasi Kesiswaan Menggunakan Yii Framework - Bagian 2
Membuat Aplikasi Kesiswaan Menggunakan Yii Framework - Bagian 2Akhmad Khanif Zyen
 
Membuat Aplikasi Kesiswaan Menggunakan Yii Framework Bagian 3
Membuat Aplikasi Kesiswaan Menggunakan Yii Framework Bagian 3Membuat Aplikasi Kesiswaan Menggunakan Yii Framework Bagian 3
Membuat Aplikasi Kesiswaan Menggunakan Yii Framework Bagian 3Akhmad Khanif Zyen
 
Membuat Aplikasi Kesiswaan Menggunakan Yii Framework - Bagian 1
Membuat Aplikasi Kesiswaan Menggunakan Yii Framework - Bagian 1Membuat Aplikasi Kesiswaan Menggunakan Yii Framework - Bagian 1
Membuat Aplikasi Kesiswaan Menggunakan Yii Framework - Bagian 1Akhmad Khanif Zyen
 
YiiConf 2012 - Alexander Makarov - Yii2, what's new
YiiConf 2012 - Alexander Makarov - Yii2, what's newYiiConf 2012 - Alexander Makarov - Yii2, what's new
YiiConf 2012 - Alexander Makarov - Yii2, what's newAlexander Makarov
 
James Altucher: 40 Alternatives To College
James Altucher: 40 Alternatives To CollegeJames Altucher: 40 Alternatives To College
James Altucher: 40 Alternatives To CollegeJamesAltucher
 
Bài 4 Hướng dẫn chỉnh sửa và thiết kế giao diện web Joomla
Bài 4 Hướng dẫn chỉnh sửa và thiết kế giao diện web JoomlaBài 4 Hướng dẫn chỉnh sửa và thiết kế giao diện web Joomla
Bài 4 Hướng dẫn chỉnh sửa và thiết kế giao diện web JoomlaMasterCode.vn
 
Bài 9 Hướng dẫn thiết kế website bán hàng trực tuyến bằng Joomla
Bài 9 Hướng dẫn thiết kế website bán hàng trực tuyến bằng JoomlaBài 9 Hướng dẫn thiết kế website bán hàng trực tuyến bằng Joomla
Bài 9 Hướng dẫn thiết kế website bán hàng trực tuyến bằng JoomlaMasterCode.vn
 
Lập trình và thiết kế website tương tác với facebook tập 1
Lập trình và thiết kế website tương tác với facebook tập 1Lập trình và thiết kế website tương tác với facebook tập 1
Lập trình và thiết kế website tương tác với facebook tập 1Lel Đặng Văn
 
Bài 2: Lập trình hướng đối tượng (OOP) - Giáo trình FPT
Bài 2: Lập trình hướng đối tượng (OOP) - Giáo trình FPTBài 2: Lập trình hướng đối tượng (OOP) - Giáo trình FPT
Bài 2: Lập trình hướng đối tượng (OOP) - Giáo trình FPTMasterCode.vn
 

En vedette (13)

Giới thiệu Yii Framework 1
Giới thiệu Yii Framework 1Giới thiệu Yii Framework 1
Giới thiệu Yii Framework 1
 
Agile web application development YII Framework
Agile web application development YII FrameworkAgile web application development YII Framework
Agile web application development YII Framework
 
Yii
YiiYii
Yii
 
Membuat Aplikasi Kesiswaan Menggunakan Yii Framework - Bagian 2
Membuat Aplikasi Kesiswaan Menggunakan Yii Framework - Bagian 2Membuat Aplikasi Kesiswaan Menggunakan Yii Framework - Bagian 2
Membuat Aplikasi Kesiswaan Menggunakan Yii Framework - Bagian 2
 
Membuat Aplikasi Kesiswaan Menggunakan Yii Framework Bagian 3
Membuat Aplikasi Kesiswaan Menggunakan Yii Framework Bagian 3Membuat Aplikasi Kesiswaan Menggunakan Yii Framework Bagian 3
Membuat Aplikasi Kesiswaan Menggunakan Yii Framework Bagian 3
 
Membuat Aplikasi Kesiswaan Menggunakan Yii Framework - Bagian 1
Membuat Aplikasi Kesiswaan Menggunakan Yii Framework - Bagian 1Membuat Aplikasi Kesiswaan Menggunakan Yii Framework - Bagian 1
Membuat Aplikasi Kesiswaan Menggunakan Yii Framework - Bagian 1
 
YiiConf 2012 - Alexander Makarov - Yii2, what's new
YiiConf 2012 - Alexander Makarov - Yii2, what's newYiiConf 2012 - Alexander Makarov - Yii2, what's new
YiiConf 2012 - Alexander Makarov - Yii2, what's new
 
James Altucher: 40 Alternatives To College
James Altucher: 40 Alternatives To CollegeJames Altucher: 40 Alternatives To College
James Altucher: 40 Alternatives To College
 
Bài 4 Hướng dẫn chỉnh sửa và thiết kế giao diện web Joomla
Bài 4 Hướng dẫn chỉnh sửa và thiết kế giao diện web JoomlaBài 4 Hướng dẫn chỉnh sửa và thiết kế giao diện web Joomla
Bài 4 Hướng dẫn chỉnh sửa và thiết kế giao diện web Joomla
 
Bài 9 Hướng dẫn thiết kế website bán hàng trực tuyến bằng Joomla
Bài 9 Hướng dẫn thiết kế website bán hàng trực tuyến bằng JoomlaBài 9 Hướng dẫn thiết kế website bán hàng trực tuyến bằng Joomla
Bài 9 Hướng dẫn thiết kế website bán hàng trực tuyến bằng Joomla
 
Yii Framework
Yii FrameworkYii Framework
Yii Framework
 
Lập trình và thiết kế website tương tác với facebook tập 1
Lập trình và thiết kế website tương tác với facebook tập 1Lập trình và thiết kế website tương tác với facebook tập 1
Lập trình và thiết kế website tương tác với facebook tập 1
 
Bài 2: Lập trình hướng đối tượng (OOP) - Giáo trình FPT
Bài 2: Lập trình hướng đối tượng (OOP) - Giáo trình FPTBài 2: Lập trình hướng đối tượng (OOP) - Giáo trình FPT
Bài 2: Lập trình hướng đối tượng (OOP) - Giáo trình FPT
 

Similaire à Get things done with Yii - quickly build webapplications

Code igniter - A brief introduction
Code igniter - A brief introductionCode igniter - A brief introduction
Code igniter - A brief introductionCommit University
 
Introduction to django
Introduction to djangoIntroduction to django
Introduction to djangoIlian Iliev
 
IRJET- Lightweight MVC Framework in PHP
IRJET- Lightweight MVC Framework in PHPIRJET- Lightweight MVC Framework in PHP
IRJET- Lightweight MVC Framework in PHPIRJET Journal
 
Folio3 - An Introduction to PHP Yii
Folio3 - An Introduction to PHP YiiFolio3 - An Introduction to PHP Yii
Folio3 - An Introduction to PHP YiiFolio3 Software
 
Introduction To Code Igniter
Introduction To Code IgniterIntroduction To Code Igniter
Introduction To Code IgniterAmzad Hossain
 
Enterprise Level Application Architecture with Web APIs using Entity Framewor...
Enterprise Level Application Architecture with Web APIs using Entity Framewor...Enterprise Level Application Architecture with Web APIs using Entity Framewor...
Enterprise Level Application Architecture with Web APIs using Entity Framewor...Akhil Mittal
 
Strategies and Tips for Building Enterprise Drupal Applications - PNWDS 2013
Strategies and Tips for Building Enterprise Drupal Applications - PNWDS 2013Strategies and Tips for Building Enterprise Drupal Applications - PNWDS 2013
Strategies and Tips for Building Enterprise Drupal Applications - PNWDS 2013Mack Hardy
 
AEM Sightly Deep Dive
AEM Sightly Deep DiveAEM Sightly Deep Dive
AEM Sightly Deep DiveGabriel Walt
 
Symfony2 Introduction Presentation
Symfony2 Introduction PresentationSymfony2 Introduction Presentation
Symfony2 Introduction PresentationNerd Tzanetopoulos
 
WebNet Conference 2012 - Designing complex applications using html5 and knock...
WebNet Conference 2012 - Designing complex applications using html5 and knock...WebNet Conference 2012 - Designing complex applications using html5 and knock...
WebNet Conference 2012 - Designing complex applications using html5 and knock...Fabio Franzini
 
AspMVC4 start101
AspMVC4 start101AspMVC4 start101
AspMVC4 start101Rich Helton
 
Staying Sane with Drupal NEPHP
Staying Sane with Drupal NEPHPStaying Sane with Drupal NEPHP
Staying Sane with Drupal NEPHPOscar Merida
 

Similaire à Get things done with Yii - quickly build webapplications (20)

Yii php framework_honey
Yii php framework_honeyYii php framework_honey
Yii php framework_honey
 
Code igniter - A brief introduction
Code igniter - A brief introductionCode igniter - A brief introduction
Code igniter - A brief introduction
 
Introduction to django
Introduction to djangoIntroduction to django
Introduction to django
 
IRJET- Lightweight MVC Framework in PHP
IRJET- Lightweight MVC Framework in PHPIRJET- Lightweight MVC Framework in PHP
IRJET- Lightweight MVC Framework in PHP
 
Folio3 - An Introduction to PHP Yii
Folio3 - An Introduction to PHP YiiFolio3 - An Introduction to PHP Yii
Folio3 - An Introduction to PHP Yii
 
Introduction To Code Igniter
Introduction To Code IgniterIntroduction To Code Igniter
Introduction To Code Igniter
 
Codeigniter
CodeigniterCodeigniter
Codeigniter
 
Codeigniter
CodeigniterCodeigniter
Codeigniter
 
Yii framework
Yii frameworkYii framework
Yii framework
 
Enterprise Level Application Architecture with Web APIs using Entity Framewor...
Enterprise Level Application Architecture with Web APIs using Entity Framewor...Enterprise Level Application Architecture with Web APIs using Entity Framewor...
Enterprise Level Application Architecture with Web APIs using Entity Framewor...
 
Asp.Net MVC 5 in Arabic
Asp.Net MVC 5 in ArabicAsp.Net MVC 5 in Arabic
Asp.Net MVC 5 in Arabic
 
Strategies and Tips for Building Enterprise Drupal Applications - PNWDS 2013
Strategies and Tips for Building Enterprise Drupal Applications - PNWDS 2013Strategies and Tips for Building Enterprise Drupal Applications - PNWDS 2013
Strategies and Tips for Building Enterprise Drupal Applications - PNWDS 2013
 
P H P Framework
P H P  FrameworkP H P  Framework
P H P Framework
 
AEM Sightly Deep Dive
AEM Sightly Deep DiveAEM Sightly Deep Dive
AEM Sightly Deep Dive
 
Symfony2 Introduction Presentation
Symfony2 Introduction PresentationSymfony2 Introduction Presentation
Symfony2 Introduction Presentation
 
WebNet Conference 2012 - Designing complex applications using html5 and knock...
WebNet Conference 2012 - Designing complex applications using html5 and knock...WebNet Conference 2012 - Designing complex applications using html5 and knock...
WebNet Conference 2012 - Designing complex applications using html5 and knock...
 
AspMVC4 start101
AspMVC4 start101AspMVC4 start101
AspMVC4 start101
 
Codeigniter
CodeigniterCodeigniter
Codeigniter
 
Codegnitorppt
CodegnitorpptCodegnitorppt
Codegnitorppt
 
Staying Sane with Drupal NEPHP
Staying Sane with Drupal NEPHPStaying Sane with Drupal NEPHP
Staying Sane with Drupal NEPHP
 

Plus de Giuliano Iacobelli

Easily Build a FAQ Spark Bot with IBM Watson
Easily Build a FAQ Spark Bot with IBM WatsonEasily Build a FAQ Spark Bot with IBM Watson
Easily Build a FAQ Spark Bot with IBM WatsonGiuliano Iacobelli
 
APIs and Process automation at APIDays Global 2016
APIs and Process automation at APIDays Global 2016APIs and Process automation at APIDays Global 2016
APIs and Process automation at APIDays Global 2016Giuliano Iacobelli
 
Grow as you go: lesson learned as a tech startupper
Grow as you go: lesson learned as a tech startupperGrow as you go: lesson learned as a tech startupper
Grow as you go: lesson learned as a tech startupperGiuliano Iacobelli
 
Stamplay: Scale your business with Microsoft Bizspark and Windows Azure
Stamplay: Scale your business with Microsoft Bizspark and Windows AzureStamplay: Scale your business with Microsoft Bizspark and Windows Azure
Stamplay: Scale your business with Microsoft Bizspark and Windows AzureGiuliano Iacobelli
 
Social Media: The Web Wide World
Social Media: The Web Wide WorldSocial Media: The Web Wide World
Social Media: The Web Wide WorldGiuliano Iacobelli
 
Mobile Zen - Improve your life through your device
Mobile Zen - Improve your life through your deviceMobile Zen - Improve your life through your device
Mobile Zen - Improve your life through your deviceGiuliano Iacobelli
 
Social is the new normal: Thoughts, tips and insights in a strongly connected...
Social is the new normal: Thoughts, tips and insights in a strongly connected...Social is the new normal: Thoughts, tips and insights in a strongly connected...
Social is the new normal: Thoughts, tips and insights in a strongly connected...Giuliano Iacobelli
 
Poke the Web and see what happen
Poke the Web and see what happenPoke the Web and see what happen
Poke the Web and see what happenGiuliano Iacobelli
 

Plus de Giuliano Iacobelli (14)

Easily Build a FAQ Spark Bot with IBM Watson
Easily Build a FAQ Spark Bot with IBM WatsonEasily Build a FAQ Spark Bot with IBM Watson
Easily Build a FAQ Spark Bot with IBM Watson
 
APIs and Process automation at APIDays Global 2016
APIs and Process automation at APIDays Global 2016APIs and Process automation at APIDays Global 2016
APIs and Process automation at APIDays Global 2016
 
The Chatbot Revolution
The Chatbot RevolutionThe Chatbot Revolution
The Chatbot Revolution
 
La rivoluzione dei chatbot
La rivoluzione dei chatbotLa rivoluzione dei chatbot
La rivoluzione dei chatbot
 
APIs as building blocks
APIs as building blocksAPIs as building blocks
APIs as building blocks
 
Grow as you go: lesson learned as a tech startupper
Grow as you go: lesson learned as a tech startupperGrow as you go: lesson learned as a tech startupper
Grow as you go: lesson learned as a tech startupper
 
Mobile Trends 2013
Mobile Trends 2013Mobile Trends 2013
Mobile Trends 2013
 
Stamplay: Scale your business with Microsoft Bizspark and Windows Azure
Stamplay: Scale your business with Microsoft Bizspark and Windows AzureStamplay: Scale your business with Microsoft Bizspark and Windows Azure
Stamplay: Scale your business with Microsoft Bizspark and Windows Azure
 
Social Media: The Web Wide World
Social Media: The Web Wide WorldSocial Media: The Web Wide World
Social Media: The Web Wide World
 
From an idea to a Startup
From an idea to a StartupFrom an idea to a Startup
From an idea to a Startup
 
Mobile Zen - Improve your life through your device
Mobile Zen - Improve your life through your deviceMobile Zen - Improve your life through your device
Mobile Zen - Improve your life through your device
 
Social is the new normal: Thoughts, tips and insights in a strongly connected...
Social is the new normal: Thoughts, tips and insights in a strongly connected...Social is the new normal: Thoughts, tips and insights in a strongly connected...
Social is the new normal: Thoughts, tips and insights in a strongly connected...
 
Poke the Web and see what happen
Poke the Web and see what happenPoke the Web and see what happen
Poke the Web and see what happen
 
Un universo di App
Un universo di AppUn universo di App
Un universo di App
 

Dernier

The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESmohitsingh558521
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 

Dernier (20)

The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 

Get things done with Yii - quickly build webapplications

  • 1. GET THINGS DONE WITH QUICKLY BUILD A WEBAPP USING YII GIULIANO IACOBELLI - @Giuliano84 - me@giulianoiacobelli.com
  • 2. WEB IS FULL OF AMAZING TOOLS
  • 4. IF IT’S THE RIGHT ONE AND IS WELL EXECUTED..
  • 5. IF YOU HAVE GOOD IDEA, DO IT. MOVE FAST AND BREAK THINGS
  • 6. SO LET ME INTRODUCE YOU TO
  • 7. WHAT IS IT? Yii is a high-performance component-based PHP framework for developing large-scale Webapplications. It enables maximum reusability in Web programming and can significantly accelerate the development process.
  • 8. IT’S EASY? IT’S RAPID? IT’S SECURE? YES IT IS (YII) !!!
  • 9. THE MVC PATTERN MVC is a design pattern widely adopted in Web programming that aims to separate business logic from user interface considerations, so that developers can more easily change each part without affecting the other.
  • 10. THE MVC PATTERN Assume a Web application consists of several sub- applications: • Front end: a public-facing website for normal end users; • Back end: a website that exposes administrative functionality for managing the application. • Console: an application consisting of console commands to be run in a terminal window or as scheduled jobs to support the whole application; • Web API: providing interfaces to third parties for integrating with the application.
  • 11. M for MODEL Models are used to keep data and their relevant business rules. A model represents a single data object that could be a row in a database table or a form of user inputs. • should contain properties to represent specific data; • should contain business logic (e.g. validation rules) to ensure the represented data fulfills the design requirement; • may contain code for manipulating data. For example, a SearchForm model, besides representing the search input data, may contain a search method to implement the actual search.
  • 12. C for CONTROLLER Controllers are the glue that binds models, views and other components together into a runnable application. They are responsible for dealing directly with end user requests. • may access $_GET, $_POST and other PHP variables that represent user requests; • may create model instances and manage their life cycles. • should avoid containing embedded SQL statements, which are better kept in models. • should avoid containing any HTML or any other presentational markup. This is better kept in views.
  • 13. V for VIEW A view is a PHP script consisting of mainly elements of user interface the spirit of seperation of logic and presentation, large chunk of logic should be placed in controller or model instead of view. • should mainly contain presentational code, such as HTML, and simple PHP code to traverse, format and render data; • should avoid containing code that performs explicit DB queries. Such code is better placed in models. • should avoid direct access to $_GET, $_POST, or other similar variables that represent the end user request. This is the controller's job.
  • 14. STRUCTURE OF YII APPLICATION
  • 15. THE ENTRY SCRIPT This is a “bootstrap” file, meaning that all user interactions actually go through it. For example, showing an employee record might be through the URL. It is the only PHP script that end users can directly request to execute. // remove the following line when in production mode defined('YII_DEBUG') or define('YII_DEBUG',true); // include Yii bootstrap file require_once('path/to/yii/framework/yii.php'); // create application instance and run $configFile='path/to/config/file.php'; Yii::createWebApplication($configFile)->run();
  • 16. YII WORKFLOW 1 - Request with the URL http://example.com/index.php?r=post/ show&id=1 and the Web server handles the request by executing the bootstrap script index.php. 2 - The bootstrap script creates an Application instance and runs it. 3 - The Application obtains detailed user request information from an application component named request. 4 - The application determines the requested controller and action with the help of an application component named urlManager.
  • 17. YII WORKFLOW 5 - The application creates an instance of the requested controller to further handle the user request. The controller determines that the action show refers to a method named actionShow in the controller class. 6 - The action reads a Post model whose ID is 1 from the database. 7 - The action renders a view named show with the Post model. 8 - The view reads and displays the attributes of the Post model. 9,10,11 - The view executes some widgets, embed the rendering result in a layout and displays it to the user.
  • 18. OK, OK, I GOT IT, TOO MUCH TALK.. LET’S HAVE AN IDEA TO BUILD..
  • 19. AND THE AMAZING IDEA IS..
  • 20. A BLOG! OK, IT’S NOT THAT AMAZING BUT IN THIS WAY I’M PRETTY SURE THAT ALL OF YOU KNOW WHAT WE ARE GOIN TO BUILD
  • 21. WARM UP • CREATE A “BLOGDEMO” FOLDER IN YOUR APACHE DOCUMENT ROOT DIRECTORY • DOWNLOAD YiiBlogDemo.zip FILE FROM http://goo.gl/nOqef AND UNZIP IT • OPEN FRAMEWORK.ZIP AND PLACE ITS CONTENT IN YOUR “BLOGDEMO” FOLDER
  • 22. YII PREPARATION Run a simple console command “blogdemo/framework/yiic webapp ../“ to generate a skeleton Web application built with Yii. This will create a skeleton Yii application under the directory WebRoot/testdrive.
  • 23. THE WEB APPLICATION The application is fully functional, with nice features including user login and contact form. It is a good starting point for implementing more sophisticated features.
  • 24. WHAT A BLOG USUALLY HAVE? • POSTS • USERS • COMMENTS • TAGS
  • 26. SETTING UP THE DATABASE return array( ...... 'components'=>array( ...... 'db'=>array( 'connectionString' => 'mysql:host=localhost;dbname=blog', 'emulatePrepare' => true, 'username' => 'root', 'password' => '', 'charset' => 'utf8', 'tablePrefix' => 'tbl_', ), ), ...... );
  • 27. GENERATING THE MODELS We need to create a model class for each of our database tables. Yii has an amazing component called Gii that totally automates this process (known as scaffolding) for us. 'modules'=>array( 'gii'=>array( 'class'=>'system.gii.GiiModule', 'password'=>'pick up a password here', ), ),
  • 29. OUR MODELS • User.php contains the User class and can be used to access the tbl_user database table; • Post.php contains the Post class and can be used to access the tbl_post database table; • Tag.php contains the Tag class and can be used to access the tbl_tag database table; • Comment.php contains the Comment class and can be used to access the tbl_comment database table; • Lookup.php contains the Lookup class and can be used to access the tbl_lookup database table.
  • 30. CRUD OPERATIONS After the model classes are created, we can use the Crud Generator to generate the code implementing the CRUD operations for these models. We will do this for the Post and Comment models.
  • 31. AUTHENTICATING USER Our blog application needs to differentiate between the system owner and guest users. Therefore, we need to implement the user authentication feature User authentication is performed in a class implementing the IUserIdentity interface. The skeleton application uses the UserIdentity class for this purpose. The class is stored in the file /wwwroot/blogdemo/ protected/components/UserIdentity.php.
  • 32. AUTHENTICATING USER Application already provides user authentication by checking if the username and password are both demo or admin. Now we will modify the corresponding code so that the authentication is done against the User database table.
  • 33. EDITING USERIDENTITY.PHP public function authenticate() { $username=strtolower($this->username); $user=User::model()->find('LOWER(username)=?',array($username)); if($user===null) $this->errorCode=self::ERROR_USERNAME_INVALID; else if(!$user->validatePassword($this->password)) $this->errorCode=self::ERROR_PASSWORD_INVALID; else { $this->_id=$user->id; $this->username=$user->username; $this->errorCode=self::ERROR_NONE; } return $this->errorCode==self::ERROR_NONE; } public function getId() { return $this->_id; }
  • 34. RECAP • Identified the requirements to be fulfilled; • We installed the Yii framework and created a skeleton application; • We designed and created the blog database; • We generated basic CRUD operations; • We modified the authentication method to check against the tbl_user table.
  • 35. CUSTOMIZING POST MODEL Post model generated is fine but now we need to specify validation rules and related objects • Validation rules ensure the attribute values entered by users are correct before they are saved to the database. For example, the status attribute of Post should be an integer 1, 2 or 3. • Customizing the relations we can exploit the powerful Relational ActiveRecord (RAR) feature to access the related object information of a post, such as its author and comments, without the need to write complex SQL statements.
  • 36. VALIDATION RULES Based on the requirement analysis, we modify the rules() method as follows: public function rules() { return array( array('title, content, status', 'required'), array('title', 'length', 'max'=>128), array('status', 'in', 'range'=>array(1,2,3)), array('tags', 'match', 'pattern'=>'/^[ws,]+$/', 'message'=>'Tags can only contain word characters.'), array('tags', 'normalizeTags'), array('title, status', 'safe', 'on'=>'search'), ); }
  • 37. MODEL RELATIONS We customize relations() method as follow public function relations() { return array( 'author' => array(self::BELONGS_TO, 'User', 'author_id'), 'comments' => array(self::HAS_MANY, 'Comment', 'post_id', 'condition'=>'comments.status='.Comment::STATUS_APPROVED, 'order'=>'comments.create_time DESC'), 'commentCount' => array(self::STAT, 'Comment', 'post_id', 'condition'=>'status='.Comment::STATUS_APPROVED), ); } We also introduce in the Comment class Comment extends CActiveRecord { model class two constants that are const STATUS_PENDING=1; used in the above method: const STATUS_APPROVED=2; ...... }
  • 38. REPRESENTING STATUS IN TEXT Because the status of a post is stored as an integer in the database, we need to provide a textual representation so that it is more intuitive when being displayed to end users. In a large system, the similar requirement is very common. As a generic solution, we use the tbl_lookup table to store the mapping between integer values and textual representations that are needed by other data objects. We modify the Lookup model class as follows to more easily access the textual data in the table.
  • 39. LOOKUP.PHP class Lookup extends CActiveRecord { private static $_items=array(); public static function items($type) { if(!isset(self::$_items[$type])) self::loadItems($type); return self::$_items[$type]; } public static function item($type,$code) { if(!isset(self::$_items[$type])) self::loadItems($type); return isset(self::$_items[$type][$code]) ? self::$_items[$type][$code] : false; } private static function loadItems($type) { self::$_items[$type]=array(); $models=self::model()->findAll(array( 'condition'=>'type=:type', 'params'=>array(':type'=>$type), 'order'=>'position', )); foreach($models as $model) self::$_items[$type][$model->code]=$model->name; } }
  • 40. POST POSSIBLE STATUSES class Post extends CActiveRecord { const STATUS_DRAFT=1; const STATUS_PUBLISHED=2; const STATUS_ARCHIVED=3; ...... } Now we can call Lookup::items('PostStatus') to get the list of possible post statuses (text strings indexed by the corresponding integer values), and call Lookup::item('PostStatus', Post::STATUS_PUBLISHED) to get the string representation of the published status.
  • 41. CONFIGURING ACCESS RULES public function accessRules() { return array( array('allow', // allow all users to perform 'list' and 'show' actions 'actions'=>array('index', 'view'), 'users'=>array('*'), ), array('allow', // allow authenticated users to perform any action 'users'=>array('@'), ), array('deny', // deny all users 'users'=>array('*'), ), ); } The rules state that all users can access the index and view actions, and authenticated users can access any actions, including the admin action.
  • 42. CREATE AND UPDATE The create and update operations are very similar. They both need to display an HTML form to collect user inputs, validate them, and save them into database. Gii generates a partial view /wwwroot/blog/protected/views/ post/_form.php that is embedded in both the create and update views to render the needed HTML form. We want to add a dropdown list to collect user input for STATUS attribute echo $form->dropDownList($model,'status',Lookup::items('PostStatus'));
  • 43. CREATE AND UPDATE We then modify the Post class so that it can automatically set some attributes (create_time, author_id) before a post is saved to the database. We override the beforeSave() method as follows protected function beforeSave() { if(parent::beforeSave()) { if($this->isNewRecord) { $this->create_time=$this->update_time=time(); $this->author_id=Yii::app()->user->id; } else $this->update_time=time(); return true; } else return false; }
  • 45. HOW TO BORROW SOME STYLE? http://twitter.github.com/bootstrap
  • 46. QUICKLY BUILD A NICE UI
  • 47. WEB AS CONCEPT IS REALLY WIDE
  • 48.
  • 50. LOOK AT THE NUMBERS http://www.phonecount.com/pc/count.jsp
  • 52. BOOTSTRAP RESPONSIVENESS It supports a handful of media queries in a single file to help make your projects appropriate on different devices and screen resolutions. @media (min-width:400px) { }
  • 53. Thanks Giuliano Iacobelli giuliano.iacobelli me@giulianoiacobelli.com http://giulianoiacobelli.com Connect with me: Ps: slide 47 and 48 were borrowed from this amazing presentation of Brad Frost