SlideShare a Scribd company logo
EMBER.JS FOR A
CAKEPHP
DEVELOPER
EMBER.JS
A framework for creating ambitious web applications.
1.0 RELEASED!
OBJECTS
EXTENDING/CREATING OBJECTS
var Person, p;
Person = Ember.Object.extend({
sayHello: function() {
alert('Hello!');
}
});
p = Person.create();
p.sayHello();
DATA BINDINGS
var Person, p;
Person = Ember.Object.extend({
message: 'Hello',
responseBinding: 'message',
yell: function() {
alert(this.get('response'));
}
});
p = Person.create();
p.yell(); // alert('Hello')
p.set('message', 'Goodbye');
p.yell(); // alert('Goodbye')
COMPUTED PROPERTIES
var Person, p;
Person = Ember.Object.extend({
firstName: '',
lastName: '',
fullName: function() {
return this.get('firstName') + ' ' + this.get('lastName');
}.property('firstName', 'lastName')
});
p = Person.create({ firstName: 'Joey', lastName: 'Trapp' });
p.get('fullName'); // "Joey Trapp"
p.set('firstName', 'Connor');
p.get('fullName'); // "Connor Trapp"
CONVENTIONS
Type Name
Route this.resource('projects');
Route (class) App.ProjectsRoute
Controller App.ProjectsController
View App.ProjectsView
Template Ember.TEMPLATES['projects']
TEMPLATES
TEMPLATES EMBEDDED IN HTML
<script type="text/x-handlebars" data-template-name="project">
<h1>{{title}}</h1>
<p>{{description}}</p>
</script>
Gets compiled on document read to:
Ember.TEMPLATES['project'] = // compiled template function
TEMPLATES FILES
Integrate into build step and compile server side
// webroot/templates/projects/add.hbs
<form {{action save on="submit"}}>
<label>Project Name</label>
{{input type="text" value=name}}
<input type="submit" value="Save">
</form>
Gets compiled with a build tool in development, and as
part of a production build step to:
Ember.TEMPLATES['projects/add'] = // compiled template function
BUILT IN HELPERS
<div class="posts">
{{#each post in controller}}
{{#if post.isPublished}}
<h2>{{#link-to 'post' post}} {{post.title}} {{/link-to}}</h2>
{{/if}}
{{else}}
<p>{{#link-to 'posts.new'}}Create the first post{{/link-to}}
{{/each}}
</p></div>
And many more
ROUTER
DEFINING ROUTES
App.Router.map(function() {
this.route('about'); // #/about
});
Routes defined this way can not contain nested routes
DEFINING RESOURCES
App.Router.map(function() {
this.resource('conferences'); // #/conferences
});
Will render the conferencestemplate in the
applicationtemplates outlet.
NESTING RESOURCES
App.Router.map(function() {
this.resource('conferences', function() { // #/conferences
this.resource('cakefest'); // #/conferences/cakefest
});
});
Will render the cakefesttemplate in the conferences
templates outlet, which is rendered in the application
templates outlet.
DYNAMIC SEGMENTS
App.Router.map(function() {
this.resource('conferences', function() { // #/conferences
this.resource('conference', { path: ':name' }); // #/conferences/blah
});
});
By default, the segment value is available in the template.
// conference template
<h1>{{name}}</h1>
<p>...</p>
NESTED ROUTES
App.Router.map(function() {
this.resource('conferences', function() { // #/conferences
this.route('new'); // #/conferences/new
});
});
Renders conferences/newtemplate in the
conferencestemplates outlet.
ROUTES
DEFINING DATA FOR TEMPLATE
window.CONFERENCES = [
Em.Object.create({id: 1, name: 'cakefest' }),
Em.Object.create({id: 2, name: 'embercamp' }),
Em.Object.create({id: 3, name: 'jsconf' })
];
var App = Ember.Application.create();
App.Router.map(function() {
this.resource('conferences', function() {
this.resource('conference', { path: '/:conference_id' });
});
});
DEFINING ROUTE CLASSES
App.ConferencesRoute = Ember.Route.extend({
model: function() {
return window.CONFERENCES;
}
});
App.ConferenceRoute = Ember.Route.extend({
model: function(params) {
return window.CONFERENCES.findProperty(
'id',
+params.conference_id
);
}
});
TEMPLATES
conferences.hbs
<h1>Conferences</h1>
{{#each conf in controller}}
{{#link-to 'conference' conf}} {{conf.name}} {{/link-to}}
{{/each}}
conference.hbs
<h1>{{name}} Conference</h1>
<p>{{desc}}</p>
OTHER CALLBACKS
App.ConferenceRoute = Ember.Route.extend({
model: function(params) {
// Return data for the template
},
setupController: function(controller, model) {
// Receives instance of this controller and
// the return value from model hook
},
renderTemplate: function() {
// Render template manually if you need to do
// something unconventional
}
});
CONTROLLERS
Controllers are long lived in Ember*,
and are the default context for templates.
CONTROLLER
Decorates a model, but has no special proxying behavior.
App.ApplicationController = Ember.Controller.extend({
search: '',
query: function() {
var query = this.get('search');
this.transitionToRoute('search', { query: query });
}
});
OBJECT CONTROLLER
Acts like an object and proxies to the modelproperty.
// In route class (this is the default behavior)
setupController: function(controller, model) {
controller.set('model', model);
}
// Object Controller
App.ConferenceController = Ember.ObjectController.extend({
isEven: function() {
return this.get('name').length % 2 === 0;
}.property('name')
});
isEvencalls this.get('name')which proxies to
this.get('model.name')
ARRAY CONTROLLER
Acts like an array, but actually performs on the methods
on the modelproperty.
App.ConferencesController = Ember.ArrayController.extend({
sortProperties: ['title']
});
// conferences template
{{#each conf in controller}}
<div>
<h1>{{conf.title}}</h1>
</div>
{{/each}}
Looping over controllerin a template is actually
looping over the modelproperty*
VIEWS
Views are primarily used to handle browser events. Since
many application actions can be handled with the action
helper and controller methods, you'll often not define
views.
UTILIZE BROWSER EVENTS
App.ConferenceView = App.View.extend({
click: function(e) {
alert('Click event was handled');
}
});
SETTING VIEWS TAG
In the DOM, your templates are wrapped by a divwith a
special id that Ember knows about.
App.ConferenceView = Ember.View.extend({
tagName: 'section',
});
The element wrapping the template will now be a
section
HELPERS
REUSABLE TEMPLATE FUNCTIONS
Ember.Handlebars.helper('capitalize', function(str) {
return str[0].toUpperCase() + str.slice(1);
});
And use the helpers in handlebars templates
<h1>{{title}}</h1>
<p>by {{capitalize firstName}} {{capitalize lastName}}</p>
QUESTIONS?
@joeytrapp
github.com/joeytrapp
@loadsys
github.com/loadsys

More Related Content

PPTX
Gary Gao: APIs Are Good
PDF
Web components
PDF
Silex Cheat Sheet
PDF
Silex: From nothing to an API
PDF
Make WordPress realtime.
PDF
Angular Promises and Advanced Routing
PPTX
Emberjs as a rails_developer
PPTX
Cakefest 2010: API Development
Gary Gao: APIs Are Good
Web components
Silex Cheat Sheet
Silex: From nothing to an API
Make WordPress realtime.
Angular Promises and Advanced Routing
Emberjs as a rails_developer
Cakefest 2010: API Development

What's hot (20)

PDF
Complex Sites with Silex
PDF
Frameworks da nova Era PHP FuelPHP
PDF
Advanced RESTful Rails
PDF
Keeping it Small: Getting to know the Slim Micro Framework
PDF
I Phone On Rails
PPT
Slim RedBeanPHP and Knockout
PPTX
18.register login
DOC
Java script for_art_pr_class
PPTX
Using WordPress as your application stack
PPTX
Intro to Silex
PPT
Rails 2010 Workshop
KEY
Chef 0.8, Knife and Amazon EC2
KEY
Keeping it small: Getting to know the Slim micro framework
PDF
Building Modern and Secure PHP Applications – Codementor Office Hours with Be...
PDF
Binary Studio Academy 2016: Laravel Controllers
PPTX
21.search in laravel
PDF
Phinx talk
PDF
Keeping it small - Getting to know the Slim PHP micro framework
PDF
Codeigniter : Two Step View - Concept Implementation
PDF
Great Developers Steal
Complex Sites with Silex
Frameworks da nova Era PHP FuelPHP
Advanced RESTful Rails
Keeping it Small: Getting to know the Slim Micro Framework
I Phone On Rails
Slim RedBeanPHP and Knockout
18.register login
Java script for_art_pr_class
Using WordPress as your application stack
Intro to Silex
Rails 2010 Workshop
Chef 0.8, Knife and Amazon EC2
Keeping it small: Getting to know the Slim micro framework
Building Modern and Secure PHP Applications – Codementor Office Hours with Be...
Binary Studio Academy 2016: Laravel Controllers
21.search in laravel
Phinx talk
Keeping it small - Getting to know the Slim PHP micro framework
Codeigniter : Two Step View - Concept Implementation
Great Developers Steal
Ad

Similar to Ember.js for a CakePHP Developer (20)

PPTX
Sencha Touch - Introduction
PPTX
Java script+mvc+with+emberjs
PDF
Emberjs building-ambitious-web-applications
PPTX
Koajs as an alternative to Express - OdessaJs'16
PPTX
Express JS
PPT
Building your first Node app with Connect & Express
PPTX
Intro to Ember.JS 2016
PDF
Silex Cheat Sheet
PDF
Ember.js for Big Profit
PDF
WordPress REST API hacking
KEY
Phpne august-2012-symfony-components-friends
DOCX
Apache Drill with Oracle, Hive and HBase
PDF
node.js practical guide to serverside javascript
PPTX
PHP: GraphQL consistency through code generation
PPTX
Angular Workshop_Sarajevo2
PDF
Doctrine For Beginners
PDF
EmberConf 2015 – Ambitious UX for Ambitious Apps
PDF
Angular Data
KEY
Single Page Web Applications with CoffeeScript, Backbone and Jasmine
PDF
OSCON - ES6 metaprogramming unleashed
Sencha Touch - Introduction
Java script+mvc+with+emberjs
Emberjs building-ambitious-web-applications
Koajs as an alternative to Express - OdessaJs'16
Express JS
Building your first Node app with Connect & Express
Intro to Ember.JS 2016
Silex Cheat Sheet
Ember.js for Big Profit
WordPress REST API hacking
Phpne august-2012-symfony-components-friends
Apache Drill with Oracle, Hive and HBase
node.js practical guide to serverside javascript
PHP: GraphQL consistency through code generation
Angular Workshop_Sarajevo2
Doctrine For Beginners
EmberConf 2015 – Ambitious UX for Ambitious Apps
Angular Data
Single Page Web Applications with CoffeeScript, Backbone and Jasmine
OSCON - ES6 metaprogramming unleashed
Ad

Recently uploaded (20)

PPTX
TLE Review Electricity (Electricity).pptx
PDF
Web App vs Mobile App What Should You Build First.pdf
PDF
DASA ADMISSION 2024_FirstRound_FirstRank_LastRank.pdf
PDF
ENT215_Completing-a-large-scale-migration-and-modernization-with-AWS.pdf
PDF
How ambidextrous entrepreneurial leaders react to the artificial intelligence...
PDF
1 - Historical Antecedents, Social Consideration.pdf
PPTX
O2C Customer Invoices to Receipt V15A.pptx
PPTX
Chapter 5: Probability Theory and Statistics
PDF
A novel scalable deep ensemble learning framework for big data classification...
PPTX
Final SEM Unit 1 for mit wpu at pune .pptx
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PDF
DP Operators-handbook-extract for the Mautical Institute
PDF
Enhancing emotion recognition model for a student engagement use case through...
PPTX
cloud_computing_Infrastucture_as_cloud_p
PPTX
observCloud-Native Containerability and monitoring.pptx
PDF
August Patch Tuesday
PPTX
Tartificialntelligence_presentation.pptx
PDF
A contest of sentiment analysis: k-nearest neighbor versus neural network
PDF
Getting started with AI Agents and Multi-Agent Systems
PPT
What is a Computer? Input Devices /output devices
TLE Review Electricity (Electricity).pptx
Web App vs Mobile App What Should You Build First.pdf
DASA ADMISSION 2024_FirstRound_FirstRank_LastRank.pdf
ENT215_Completing-a-large-scale-migration-and-modernization-with-AWS.pdf
How ambidextrous entrepreneurial leaders react to the artificial intelligence...
1 - Historical Antecedents, Social Consideration.pdf
O2C Customer Invoices to Receipt V15A.pptx
Chapter 5: Probability Theory and Statistics
A novel scalable deep ensemble learning framework for big data classification...
Final SEM Unit 1 for mit wpu at pune .pptx
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
DP Operators-handbook-extract for the Mautical Institute
Enhancing emotion recognition model for a student engagement use case through...
cloud_computing_Infrastucture_as_cloud_p
observCloud-Native Containerability and monitoring.pptx
August Patch Tuesday
Tartificialntelligence_presentation.pptx
A contest of sentiment analysis: k-nearest neighbor versus neural network
Getting started with AI Agents and Multi-Agent Systems
What is a Computer? Input Devices /output devices

Ember.js for a CakePHP Developer