Building MVC Web Applications Tommy MacWilliam Models Views

Building MVC Web Applications

Controllers Assets TwitterNiter

Tommy MacWilliam [email protected]

February 15, 2012

Today Building MVC Web Applications Tommy MacWilliam Models

I

models

Controllers

I

views

Assets

I

controllers

I

assets

I

TwitterNiter

Views

TwitterNiter

Models Building MVC Web Applications Tommy MacWilliam Models Views Controllers

I

the M in MVC

I

application/models/

I

models access the database

Assets TwitterNiter

I

and nothing else

Documentation Building MVC Web Applications Tommy MacWilliam Models

I

Views Controllers Assets TwitterNiter

http://codeigniter.com/user_guide/ database/active_record.html I

I

http: //codeigniter.com/user_guide/database/ I

I

your new best friend

even more friends

read the documentation.

Query Building Building MVC Web Applications Tommy MacWilliam Models Views

I

I

Controllers Assets TwitterNiter

$this->db is an object with query-building methods

I

nicer than writing SQL yourself

$results = $this->db->get(’table’)->result(); I

get entire table as array of objects

Active Record Building MVC Web Applications Tommy MacWilliam Models Views Controllers Assets TwitterNiter

I

CodeIgniter is NOT Active Record

I

http://en.wikipedia.org/wiki/Active_ record_pattern I

the Internet is always right

Reading Building MVC Web Applications Tommy MacWilliam

I Models Views

$this->db->where_in(’column’, array(1, 2, 3))->get(’table’)->result(); I

Controllers Assets TwitterNiter

I

SELECT * FROM table WHERE column IN (1, 2, 3)

$this->db->get_where(’table’, array(’column’ => ’value’))->result(); I

SELECT * FROM table WHERE column = ’value’

Writing Building MVC Web Applications Tommy MacWilliam

I

Models Views

$this->db->insert(’table’, array(’column’ => ’value’)); I

Controllers

INSERT INTO table (column) VALUES (’value’)

Assets TwitterNiter

I

$this->db->where(’id’, 1’)->update(’table’, array(’column’ => ’value’)); I

UPDATE table SET column = ’value’ WHERE id = 1

Tweet Model Building MVC Web Applications Tommy MacWilliam Models Views Controllers

I

tweets table, each row is a tweet

Assets

I

tweets table has a Tweet model in application/models/tweet.php

TwitterNiter

Tweet Model Building MVC Web Applications Tommy MacWilliam Models Views Controllers

I

application/models/tweet.php

Assets

I

TwitterNiter

I

add() get_newsfeed()

Views Building MVC Web Applications Tommy MacWilliam Models Views Controllers

I

the V in MVC

I

application/views/

I

views display data

Assets TwitterNiter

I

and nothing else

Views Building MVC Web Applications Tommy MacWilliam Models Views Controllers

I

views contain both HTML and PHP

Assets

I

use objects from model to display data, iterate over data, etc.

TwitterNiter

Tweets View Building MVC Web Applications Tommy MacWilliam Models Views Controllers Assets TwitterNiter

I

application/views/tweets/index.php

Controllers Building MVC Web Applications Tommy MacWilliam Models Views Controllers

I

the C in MVC

I

application/controllers/

I

controllers connect views to models

Assets TwitterNiter

I

and nothing else

Controllers Building MVC Web Applications Tommy MacWilliam Models Views

I

I go to the URL /courses/view/1

Controllers

I

CodeIgniter instantiates Courses in application/controllers/courses.php

I

CodeIgniter calls the view function and passes 1 as parameter

Assets TwitterNiter

Things that Happen Building MVC Web Applications Tommy MacWilliam Models Views Controllers Assets TwitterNiter

I

requests come from browser to controller

I

controller calls model

I

model accesses database and returns data to controller

I

controller sends model data to view

Things that do NOT Happen Building MVC Web Applications Tommy MacWilliam Models Views Controllers Assets TwitterNiter

I

model does NOT call controller methods

I

view does NOT call controller methods

I

JavaScript does NOT call controller methods

I

view does NOT call model methods

Tweets Controller Building MVC Web Applications Tommy MacWilliam Models Views Controllers

I

application/controllers/tweets.php

Assets

I

TwitterNiter

I

index() add()

Assets Building MVC Web Applications Tommy MacWilliam Models Views

I

Controllers Assets TwitterNiter

JavaScript (yay!), CSS, images, etc. I

I

NOT PHP code

belong in html/ I

only files under html/ can be displayed by web browser

Referencing Assets Building MVC Web Applications Tommy MacWilliam Models Views

I

Controllers

path/to/file is relative to the current file I

Assets TwitterNiter

I

where’s the current file? I dunno.

/path/to/file is relative to the DocumentRoot I

where’s the DocumentRoot? html/

Assets Building MVC Web Applications Tommy MacWilliam Models Views Controllers Assets TwitterNiter

I

html/js/tweets/index.js

.htaccess Building MVC Web Applications Tommy MacWilliam Models Views

I

makes your URLs pretty

Controllers

I

Assets

I TwitterNiter

I

automatically sends everything to index.php (so you don’t have to)

don’t forget to chmod 644 .htaccess!

.htaccess Building MVC Web Applications Tommy MacWilliam Models Views Controllers Assets TwitterNiter

I

html/.htaccess

Adding Tags Building MVC Web Applications Tommy MacWilliam Models Views Controllers Assets TwitterNiter

I

new feature request! tagging posts

Model Building MVC Web Applications Tommy MacWilliam Models Views Controllers Assets TwitterNiter

I

tags table

I

Tag model to interact with table I I

add tag associated with tweet fetch tags for tweets on homepage

View Building MVC Web Applications Tommy MacWilliam Models Views Controllers Assets TwitterNiter

I

display tags in newsfeed

Controller Building MVC Web Applications Tommy MacWilliam Models Views Controllers Assets TwitterNiter

I

account for adding tags to a tweet

I

make sure tags are fetched for tweets

Tags Building MVC Web Applications Tommy MacWilliam Models

I

application/models/tag.php

Controllers

I

application/models/tweet.php

Assets

I

application/controllers/tweets.php

I

application/views/tweets/index.php

I

html/js/tweets/index.js

Views

TwitterNiter

One More Thing Building MVC Web Applications Tommy MacWilliam Models Views Controllers Assets TwitterNiter

I

search!

Search Building MVC Web Applications Tommy MacWilliam Models Views Controllers Assets TwitterNiter

I

application/controllers/tweets.php

Building MVC Web Applications - Tommy MacWilliam

Feb 15, 2012 - Controllers. Assets. TwitterNiter. Documentation. ▷ http://codeigniter.com/user_guide/ · database/active_record.html. ▷ your new best friend.

97KB Sizes 1 Downloads 252 Views

Recommend Documents

Building MVC Web Applications - Tommy MacWilliam
Feb 15, 2012 - Assets. TwitterNiter. Tweet Model. ▷ tweets table, each row is a tweet. ▷ tweets table has a Tweet model in application/models/tweet.php ...

iOS: Table Views and Navigation Controllers - Tommy MacWilliam
Apr 5, 2011 - iOS: Table. Views and. Navigation. Controllers. Tommy. MacWilliam. Property Lists. Table Views. Navigation. Controllers. Advanced. TableViews plist. ▷ key-value pairs, used to store settings. ▷ XCode plist editor. ▷ stored as XML 

iOS: Table Views and Navigation Controllers - Tommy MacWilliam
Apr 5, 2011 - cell identifier: unique string identifying the type of cell we want. ▷ more pertinent when using different types of cells in a table ... Advanced. TableViews. NSIndexPath. ▷ contains property for section and row. ▷ integer, 0-inde

Up Running: Building Web Applications
you ll build a complete custom Whinepad app that helps users rate wines ... Set up React and write your first "Hello world" web appCreate and use custom React.

ePUB React: Up Running: Building Web Applications ...
ePUB React: Up Running: Building Web Applications Read online. InformationWeek com News analysis and research for business technology professionals plus peer to peer knowledge sharing Engage with ... Facebook for building rich web.