Beruflich Dokumente
Kultur Dokumente
Responsive Design
●
Review of Web Basics
●
Design Theory: UX/UI, Responsive/Mobile First
+Project: Personal Page w/ Resume
OVERVIEW: The DOM
●
DOM: Document Object Model
OVERVIEW: HTML5
Forms
Semantic Elements
Canvas
Rich Media
HTML5 Forms
-HTML forms are used to collect user input.
-The <form> element de1nes an HTML form:
-HTML forms contain form elements.
-Form elements are di2erent types of input elements,
checkboxes, radio buttons, submit buttons, and more.
HTML5 Forms
The Action Attribute
The action attribute de1nes the action to be performed when the form is submitted.
The common way to submit a form to a server, is by using a submit button.
Normally, the form is submitted to a web page on a web server.
In the example above, a server-side script is speci1ed to handle the submitted form:
<form action="action_page.php">
If the action attribute is omitted, the action is set to the current page.
<form>
First name:<br>
<input type="text" name="1rstname"><br>
Last name:<br>
<input type="text" name="lastname">
</form>
OVERVIEW: CSS3
Pseudo Elements
Transitions
Transforms
Media Queries
Responsive Web Design
-Responsive web design
makes your web page look
good on all devices.
-Responsive web design uses
only HTML and CSS for
creating a Cexible layout
-Javascript can be used to
enhance but design should
not be dependent on JS
Responsive Web Design
-The Cuid grid concept calls for -Media queries allow the page to use
page element sizing to be in di2erent CSS style rules based on
characteristics of the device the site
relative units like percentages,
is being displayed on, most
rather than absolute units like commonly the width of the browser.
pixels or points.
div {
transition: width 2s, height 4s;
}
CSS3: Animations
What are CSS3 Animations?
– Ananimation lets an element gradually change from one style to
another.
– Touse CSS3 animation, you must first specify some keyframes for
the animation.
– Keyframes hold what styles the element will have at certain times.
CSS3: Media Queries
Media query is a CSS technique introduced in
CSS3. It uses the @media rule to include a
block of CSS properties only if a certain
condition is true.
Most websites share a very similar (not to say identical) structure. The aim
of frameworks is to provide a common structure so that developers don’t
have to redo it from scratch and can reuse the code provided. In this way,
frameworks allow us to cut out much of the work and save a lot of time.
Advantages Disadvantages
-Rapid Prototyping -Generic look if you're lazy
-Cross browser compatibility -Code bloat/heavy
-Responsive out of the box -Locked into the logic of the FEF
-Large development/user -Too much black box/magic
community (don't know your code)
Popular Frontend Frameworks
Frontend Grid System
● Grid composed of twelve columns
● Number of columns occupied by elements
changes as break points are hit
Frontend Grid System
●
Rows must be placed within a .container (1xed-width) or .container-Cuid (full-width) for proper
alignment and padding.
●
Use rows to create horizontal groups of columns.
●
Content should be placed within columns, and only columns may be immediate children of
rows.
●
Prede1ned grid classes like .row and .col-xs-4 are available for quickly making grid layouts. Less
mixins can also be used for more semantic layouts.
●
Columns create gutters (gaps between column content) via padding. That padding is o2set in
rows for the 1rst and last column via negative margin on .rows.
Frontend Grid System
●
Grid columns are created by specifying the number of twelve available columns
you wish to span. For example, three equal columns would use three .col-xs-4.
●
If more than 12 columns are placed within a single row, each group of extra
columns will, as one unit, wrap onto a new line.
● Grid classes apply to devices with screen widths greater than or equal to the
breakpoint sizes, and override grid classes targeted at smaller devices.
Therefore, e.g. applying any .col-md-* class to an element will not only affect its
styling on medium devices but also on large devices if a .col-lg-* class is not
present.
/* Extra small devices
/* Medium devices
(desktops, 992px and up) */
@media (min-width:
@screen-md-min) { ... }
jQuery takes a lot of common tasks that require many lines of JavaScript code to accomplish, and wraps them into
methods that you can call with a single line of code.
jQuery also simpli1es a lot of the complicated things from JavaScript, like AJAX calls and DOM manipulation.
All the di2erent visitor's actions that a web page can respond to are
called events.
Examples:
-moving a mouse over an element
-selecting a radio button
-clicking on an element
The term "1res/1red" is often used with events. Example: "The
keypress event is 1red, the moment you press a key".
jQuery Events
jQuery Events
$(document).ready()
The $(document).ready() method allows us to execute a function
when the document is fully loaded.
click()
The click() method attaches an event handler function to an HTML
element.
The function is executed when the user clicks on the HTML element.
$("p").click(function(){
$(this).hide();
});
jQuery Events
Basics of MVC
• Model
• View
• Controller
• Navigation
• Sidebars
• Footer
Includes allow us to use conditional logic to change the structure of our
webpage. By editing one template file we can affect the element on all
pages.
PHP Templating with Include Functions
• include
• include_once
• require
• require_once
include attempts to continue processing a script, even if the external file is missing, whereas require is used in
the sense of mandatory: if the file is missing, the PHP engine stops processing and throws a fatal error.
include_once and require_once prevent the same file from being included more than once in a page. This is
particularly important when including files that define functions or classes. Attempting to define a function or
class more than once in a script triggers a fatal error.
PHP Templating with Include Functions
• exam ple.php
• exam ple.inc
• exam ple.inc.php
Other extensions might include “tpl” in CMSs such as Drupal
Connecting to a Database
-$username
-$password
-'database name'
SELECT column_name,column_name
FROM table_name
WHERE column_name operator value;
SQL Commands
SELECT column_name(s)
FROM table_name
WHERE column_name LIKE pattern;
SQL Commands
UPDATE table_name
SET column1=value1,column2=value2,...
WHERE some_column=some_value;
SQL Commands
WP functions: get_header();
Layout options
WP Template: Getting Started
• index.php
• functions.php
Includes allow us to use conditional logic to change the structure of our
webpage. By editing one template file we can affect the element on all
pages.
WP Template: Declaring the Theme
/*
Author: Spencer
Version: 1.0
*/
WP Functions: Enqueue CSS
wp_enqueue_style()
Goes in the FUNCTION.PHP 1le, adds styles and scripts.
add_action('wp_enqueue_scripts', 'theme_styles');
WP Functions: Enqueue JS
wp_enqueue_stript()
Goes in the FUNCTION.PHP 1le, adds scripts.
wp_head()
Echos out function.php actions
-Put in the header.php ,le
-Can be used to add enqueue styles, scripts, functions
WP Functions: Nav
wp_nav_menu ( array $args = array() )
Feed arguments to the array such as:
-$args
(array) (Optional) Array of nav menu arguments.
'menu'
(string) Desired menu. Accepts (matching in order) id, slug, name.
'menu_class'
(string) CSS class to use for the ul element which forms the menu. Default 'menu'.
'menu_id'
(string) The ID that is applied to the ul element which forms the menu. Default is the menu slug, incremented.
'container'
(string) Whether to wrap the ul, and what to wrap it with. Default 'div'.
'container_class'
(string) Class that is applied to the container. Default 'menu-{menu slug}-container'.
'theme_location'
(string) Theme location to be used. Must be registered with register_nav_menu() in order to be selectable by the user.
'items_wrap'
(string) How the list items should be wrapped. Default is a ul with an id and class. Uses printf() format with numbered placeholders.
WP Functions: create_widget()
create_widget();
Registers a new widget area for use in the “Widget
Menu”
-add arguments for name, unique identi,er, short description
create_widget('Right Sidebar', 'right-sidebar', 'Displays Right
Sidebar' );
WP Functions: get_sidebar()
get_sidebar();
Retrieves the 1le sidebar.php and includes it
-add arguments to specify 'left' 'right' etc
<?php get_header(); ?>
<?php get_sidebar( 'left' ); ?>
<?php get_sidebar( 'right' ); ?>
<?php get_footer(); ?>
The ,le names for the right and left sidebars should be sidebar-right.php and
sidebar-left.php respectively.
Creating Template Pages
Page Templates allow for di2erent layout and structures to be
assigned
to di2erent pages; ie Single Column Page, Right Sidebar Page etc
-Declare Template name using a comment at top of page before
get_header()
/*
Template Name: Page with Right Sidebar
*/
Wordpress: The Loop
The Loop is PHP code used by WordPress to display posts. Using The
Loop, WordPress processes each post to be displayed on the current
page, and formats it according to how it matches speci;ed criteria
within The Loop tags. Any HTML or PHP code in the Loop will be
processed on each post.
Title (the_title())
Time (the_time())
Categories (the_category()).
Wordpress: The Loop (shorthand)
The loop starts here:
●
Drupal has a reputation for being the most
di_cult CMS/CMF to learn but also the most
secure, scalable and powerful
●
Not as much usage as WP but higher $
for Developers
Who is Using Drupal?
Drupal is used across many sectors
– Government
– Education
– Business
– Media
Introduction to Drupal: When to Use
●
Drupal is best suited for large projects that will need to scale and extend
functionality in the future.
●
Drupal excels in serving many di2erent users with di2erent user permissions
and accessibility
– Social Network type sites
– Business sites
– Ecommerce: not as popular or user friendly as WP
●
Drupal might not be well suited for specialty applications although with
Drupal 8 “headless Drupal” can serve as the application backend and API.
Drupal Themes
● Drupal, like Wordress, uses themes to render
content on the front end. You can also use backend
themes to improve Webmaster use
● Most popular themes for Drupal 7:
– Bootstrap 3, Omega 5, Adaptive Themes, and Zen
Theme Block Regions
Adding Theme Block Regions
1) in the theme.info 1le register the new region
regions[navigation] = 'Navigation'
regions[header] = 'Top Bar'
………………………………..
regions[featured] = featured
2) In the template 1le (ie page.tpl.php) render(); the region
<?php if ($page['featured']): ?>
<div class="featured">
<?php print render($page['featured']); ?>
</div> <!-- /.featured -->
<?php endif; ?>
Content Types
Content types allow us to construct content 'nodes' using 1elds
Content Types
-Content types allow us to construct content 'nodes' using 1elds
-Content types are made up of 1elds
– Text
– File
– Media
– Urls
– Etc
-Content types output a “node”
Drupal Views
RESTful APIs
RESTful APIs
A RESTful API is an application program interface (API) that uses
HTTP requests to GET, PUT, POST and DELETE data.
Representational state transfer (REST), which is used by
browsers, can be thought of as the language of the Internet.
What is JSON
●
JSON stands for JavaScript Object Notation
●
JSON is a lightweight data-interchange format
●
JSON is language independent *
●
JSON is "self-describing" and easy to understand
●
JSON is a syntax for storing and exchanging data.
●
JSON is an easier-to-use alternative to XML.
JSON Syntax Rules
{",rstName":"John", "lastName":"Doe"}
JSON Arrays
●
</employee>
</employees>
AJAX JSON Call
$(document).ready(function() {
●
$.ajax({
●
url: 'http://localhost/drupal8/app-articles',
●
dataType: 'json',
●
type: 'get',
●
cache: false,
●
success: function(data) {
●
$(data).each(function(index, value) {
●
$( "body" ).append("<h1>" + value.title + "</h1>");
●
$( "body" ).append("<p>" + value.body + "</p>");
●
});
●
}
●
});
●
});
Model-View-Controller Architecture
●
In object-oriented programming
development, model-view-controller (MVC) is
the name of a methodology or design pattern
for successfully and e_ciently relating the
user interface to underlying data models. The
MVC pattern is widely used in program
development with programming languages
such as Java, Smalltalk, C, and C++.
●
The MVC pattern has been heralded by many
developers as a useful pattern for the reuse
of object code and a pattern that allows
them to signi1cantly reduce the time it takes
to develop applications with user interfaces.
Model-View-Controller Architecture
●
A Model, which represents the underlying,
logical structure of data in a software
application and the high-level class associated
with it. This object model does not contain any
information about the user interface.
●
A View, which is a collection of classes
representing the elements in the user interface
(all of the things the user can see and respond
to on the screen, such as buttons, display
boxes, and so forth)
●
A Controller, which represents the classes
connecting the model and the view, and is
used to communicate between classes in the
model and view.
v
v
v
v
v v
v
v
Basic OOP
●
PHP 5 1rst gave support for OOP in 2004
●
Object-oriented programming (OOP) is a programming paradigm based
on the concept of "objects", which may contain data, in the form of ,elds, often
known as attributes; and code, in the form of procedures, often known as
methods. A feature of objects is that an object's procedures can access and often
modify the data ,elds of the object with which they are associated (objects have
a notion of "this" or "self"). In OOP, computer programs are designed by making
them out of objects that interact with one another.
Procedural vs OOP
●
Classes reCect concepts – Objects represent instances
Basic OOP
●
Classes reCect concepts – Objects represent instances
●
In classes $variables = Properties and functions() = Methods
Intro to Laravel 5.1
●
Laravel was 1rst released in 2011 and has rapidly become the
most popuplar PHP framework
Composer
●
Composer is Laravel's Dependency Manager
●
Similar to:
– Ruby's Bundler
– Node.js's Node Package Manager (npm)
●
Adds third party packages to your project
Artisan
●
Artisan is Laravel's CLI. It provides a number of helpful commands
for your use while developing your application. It is driven by the
powerful Symfony Console component.
●
Similar to Drush in Drupal
●
You can use it to execute automated processes
– Create/Migrate DB
– Start PHP server on speci1c port #s
– Create Controllers
– Create Models
– etc
Migrations
● Migrations are like version control for your
database, allowing a team to easily modify and
share the application's database schema.
Migrations are typically paired with Laravel's
schema builder to easily build your application's
database schema.
Migrations
● The Laravel Schema facade provides database
agnostic support for creating and manipulating
tables. It shares the same expressive, fluent API
across all of Laravel's supported database
systems.
● This means you can build your database structure
as a PHP object and then create and manage it
through the CLI
Migrations
● (1)To set up a new Migration file we use Artisan:
CLI: php artisan make:migration create_some_table
● This will create a new migration file in the
database/migrations folder
● (2)The file contains two functions:
– Up(): applies the migration to DB, creates tables
– Down(): undoes migration, drop tables
(3)CLI: php artisan migrate to execute
Migrations: Example
Migrations
● (2) Within the method up() we can use Laravel's Schema
builder to name and create table rows.
public function up()
{
Schema::create('posts', function(Blueprint $table){
$table->increments('id');
$table->string('title');
$table->text('body');
$table->timestamps();
});
}
● (3) execute migration: php artisan migrate
Blade Templating Engine
● Blade is the simple, yet powerful templating engine
provided with Laravel. Unlike other popular PHP
templating engines, Blade does not restrict you from using
plain PHP code in your views. All Blade views are
compiled into plain PHP code and cached until they are
modified, meaning Blade adds essentially zero overhead
to your application. Blade view files use the .blade.php file
extension and are typically stored in the resources/views
directory.
Blade Templating Engine
● You can create a master template and then 'include'
different page elements using the the templating function:
@yield('somecontent')
● The @section directive, as the name implies, defines a
section of content, while the @yield directive is used to
display the contents of a given section.
Blade Templating Engine
● Extending A Layout>>Child to Parent
When defining a child page, you may use the Blade
@extends directive to specify which layout the child page
should "inherit". Views which @extends a Blade layout
may inject content into the layout's sections using
@section directives. The contents of these sections will be
displayed in the layout using @yield:
The MODEL-->ORM
Object-relational mapping (ORM, O/RM, and O/R mapping tool)
in computer science is a programming technique for converting
data between incompatible type systems in object-oriented
programming languages. This creates, in e2ect, a "virtual object
database" that can be used from within the programming
language.
The MODEL-->Eloquent
De1ning An Eloquent Model
class User extends Model {}
●
You may also generate Eloquent models using the make:model
command:
php artisan make:model User
●
Specify a custom table by de1ning a table property on your
model:
class User extends Model {
protected $table = 'my_users';
The MODEL-->Eloquent
Once a model is de1ned, you are ready to start retrieving and
creating records in your table. Note that you will need to place
updated_at and created_at columns on your table by default. If
you do not wish to have these columns automatically maintained,
set the $timestamps property on your model to false.
●
Retrieving All Records
$users = User::all();
●
Retrieving A Record By Primary Key
$user = User::,nd(1);
var_dump($user->name);
The MODEL-->Eloquent
Querying Using Eloquent Models
$users = User::where('votes', '>', 100)->take(10)->get();
foreach ($users as $user)
{
var_dump($user->name);
}
●
Eloquent Aggregates
Of course, you may also use the query builder aggregate functions.
$count = User::where('votes', '>', 100)->count();
●
If you are unable to generate the query you need via the Cuent interface, feel
free to use whereRaw:
$users = User::whereRaw('age > ? and votes = 100', [25])->get();
Eloquent : Mass Assignments
Mass Assignment
When creating a new model, you pass an array of attributes to the model constructor. These
attributes are then assigned to the model via mass-assignment. This is convenient; however, can be
a serious security concern when blindly passing user input into a model. If user input is blindly
passed into a model, the user is free to modify any and all of the model's attributes. For this reason,
all Eloquent models protect against mass-assignment by default.
●
To get started, set the 1llable or guarded properties on your model.
●
De1ning Fillable Attributes On A Model
●
The 1llable property speci1es which attributes should be mass-assignable. This
can be set at the class or instance level.
class User extends Model {
protected $,llable = [',rst_name', 'last_name', 'email'];
}
Eloquent : Mass Assignments
De1ning Guarded Attributes On A Model
The inverse of 1llable is guarded, and serves as a "black-list" instead of a
"white-list":
class User extends Model {
protected $guarded = ['id', 'password'];
}
●
De1ning Fillable Attributes On A Model
●
The 1llable property speci1es which attributes should be mass-
assignable. This can be set at the class or instance level.
class User extends Model {
protected $,llable = [',rst_name', 'last_name', 'email'];
}