- PeterMoulding.com
- Author
- Trainer
- Speaker
- Business Coach
- How to write a How To book
- PHP Courses
- Speaking
- Web Architect
- Australia
- Books
- Authors
- Akkana Peck
- Alex Berenson
- Andrew Nugent
- Ben Sanders
- Brock Clarke
- Chris Simms
- David Mercer
- Dianna Mullet
- Don Winslow
- Dori Smith
- Harlan Coben
- Jack McDevitt
- James Wines
- Jerry Yudelson
- John Grisham
- Kevin Mullet
- L. E. Modesitt Jr.
- Laurell K. Hamilton
- Marshall Karp
- Martina Cole
- Michael Marshall Smith
- Michel Roux Jr
- Nadia Sawalha
- Philip Pullman
- Raymond Khoury
- Richard North Patterson
- Robert Masello
- Sally Roth
- Sarah Langan
- Stella Rimington
- Stephen Booth
- Stephen King
- Stephen Leather
- T.C. Boyle
- Tom Negrino
- Tony Hillerman
- Urban Waite
- Val McDermid
- Valerio Massimo Manfredi
- Beginning GIMP
- Beginning Visual C++
- Culturalism
- Fiction
- A Drink Before The War
- A Talent for War
- Bag of Bones
- Blood and Ice
- Burn
- Dark Lady
- Dead Line
- Eclipse
- Empress of Eternity
- Exley
- Flipping Out
- Just One Look
- Nightfall
- Pet Sematary
- Savage Moon
- Skinwalkers
- Starvation Lake
- The Fallen
- The Gardens of the Dead
- The Jump
- The Last Templar
- The Mermaids Singing
- The Midnight Mayor
- The Secret Soldier
- The Summons
- The Terror of Living
- The Testament
- The Tower
- Under the Dome
- Virus
- AJAX and PHP
- Aging with Grace
- Food books
- Green Architecture
- Life Is So Good
- SQL: The Complete Reference
- The Backyard Bird Lover's Ultimate How-to Guide
- The Garden Gurus
- Authors
- Sustainability
- -18 hours left to decide the future of Australia
- Campbells vegetable stock or Massel vegetable stock?
- Carbon Sequestration
- Carbon tax for Australia is a fraud
- Copenhagen will fail
- Cost of living in Australia
- Dick Smith jumps on the population bandwagon
- Dry Run: Preventing the Next Urban Water Crisis
- Energy Saving Lights
- Garlic
- How many people can live in Australia?
- Its obsolete, throw it out!
- Julia Gillard offers 9.9 billion dollars bribe to Rob Oakeshott
- Laundry detergent
- Petrol or Diesel?
- Reflective foil batts kill
- RoHS
- Sea level to rise 3mm due to climate change
- Solar power
- Spring again in Sydney
- Sustainable fuels
- The CRUD Tax is back
- The people who make building regulations do not own houses
- Water efficiency
- Which insulation is safer, foil or wool?
- Will Australia reduce greenhouse gas emissions?
- Technology
- Android or Blackberry or iPhone or a flip phone?
- Apple versus Google 2011
- Cameras
- Cars
- Colour
- Burgundy
- Colour Blindness
- Colour Names
- Dulux colours
- Pantone colours
- Safe Colours
- Seculine ProDisk Mini colour balance card
- What Causes Colour Blindness?
- Hardware
- Batteries for the Digital Age
- Cables
- Cases
- Computer reliability
- Computrace
- Disks
- Astone ISO Gear 481E
- Best SSD for your notebook computer
- Disk block size
- Hitachi disk HDS722020ALA330
- LaCie USB 2.0 250 GB mobile hard drive design by F.A. Porsche
- SMART disk
- Samsung 2 TB HD204UI quiet low power disk for mass storage
- Seagate and Samsung merge disk business
- Select the right disk for your RAID array
- USB disk speed
- Western Digital WD20EARX 2 GB SATA 3 disk
- How long should computer hardware last?
- Keyboards
- Mainframe
- Memory cards
- Monitors
- Netbooks, notebooks, tablets, and xPads
- Network Attached Storage
- OLED Displays
- PC's are a thing of the past
- Printers
- Quiet
- Samsung Galaxy S
- Speed
- Television
- Tools
- USB
- Worst computer movies
- Xserve is dead. What next?
- Your backup will not work
- Z68 motherboards
- iPad or Acer Aspire One?
- IQ
- LG Intello Washing Machine
- Lack of a challenge
- Networks
- 802.11n wireless networking
- D-Link DIR-655 wireless router
- D-Link DWA-160 Xtreme N dual band USB adapter
- D-Link DWA-556 Xtreme N PCI Express desktop adapter
- MIMO
- NBN spends another $12 billion of our tax money on nothing
- National Broadband Network
- Netgear wireless modem router DGND3300 with 300 Mbps 802.11n
- Refrigerator kills wireless broadband
- Small Wireless Network
- TP-LINK TL-SG10005D 5 port gigabit switch
- TP-Link TL-WR1043N wireless N gigabit router
- Telstra Pre-paid Mobile Wi-Fi
- Where are the router plus proxy server combinations?
- Open Source documentation
- Software
- 7-zip
- Accounting
- Asterisk
- Audacity
- Backup software
- Bloat only in Windows
- CAD
- CDex
- Disk imaging software for copying and backup
- Exact Audio Copy
- Filezilla
- Firefox
- Java
- LibreOffice or OpenOffice?
- Linux
- 1 in 5 servers will ship with Linux
- Android phones outsell iPhone
- Another Move to Linux
- CentOS 5.5 installation on SSD and RAID 5
- Debian
- Debian 5.0.5 AMD64 installation
- Debian 5.06 installation
- Fedora
- Fedora or Ubuntu?
- Gnome or KDE?
- K9copy
- Linux 2.6.38
- Linux Gnome login settings lost
- Linux Mint
- Linux RAID, a rant
- Linux Speed
- Linux Time
- Linux reliability as demonstrated by Ubuntu 10.10
- Linux reliability as demonstrated by Ubuntu 11.4
- Linux still a struggle in 2011
- Linux workstation disk RAID 1
- Linux, NT, Windows, and SETI
- Linux, three years of progress
- London Stock Exchange switches to Linux
- Mandrake Linux 9.2
- The partition is misaligned by 48128 bytes - warning from Linux RAID
- Ubuntu
- How to fix the scroll bars in Ubuntu 11.4 Gnome
- Kubuntu 10.10 alternate installation on desktop with RAID 1
- POWbuntu
- Ubuntu 10.10 after 6 months use
- Ubuntu 10.10 alternate installation
- Ubuntu 10.10 desktop RAID 1
- Ubuntu 10.10 desktop RAID 5
- Ubuntu 10.10 desktop install on a netbook
- Ubuntu 10.10 desktop installation
- Ubuntu 10.10 netbook install on a netbook
- Ubuntu 10.10 server AMD64
- Ubuntu 10.10 upgrade to version 11.4 beta 2
- Ubuntu 10.4
- Ubuntu 11.10
- Ubuntu 11.10 first upgrade
- Ubuntu 11.4 after one month use
- Ubuntu 12.04 beta1 desktop amd64
- Ubuntu One
- Ubuntu by Microsoft?
- Ubuntu desktop upgrade 10.4 to 10.10 failed because I did not check the media
- Ubuntu strikes again
- Upgrade Ubuntu to Linux Mint 12 LDXE for extra speed
- Yes, use Linux but not that distribution!
- Nero
- OpenOffice
- OpenOffice is now Apache Office
- Project management
- Scribus
- Software for Windows and Linux
- Text editors
- Time
- Todo applications
- Tomboy notes
- Top text editors
- Version control
- VideoLAN VLC media player
- Visio
- Webmin
- Webmin installation on CentOS for Web development
- Webmin installation on Ubuntu
- What is the most popular open source software today?
- Windows
- Another Windows person goes Linux
- BAD_POOL_CALLER
- Cygwin
- Microsoft Malicious Software Removal Tool cannot find a common virus
- One of the developers of Windows XP is criminally insane
- There are unused icons on your desktop
- W32time
- Which Windows version?
- Windows 7 Home Premium
- Windows XP Stop 0x0000007B during installation
- Windows XP is a disaster
- Windows processes
- XML
- Zip, bzip, gzip, or 7zip?
- configFree
- Technology Succession Planning
- VoIP
- Web Sites
- Drupal
- Do Drupal themes have to use the GPL?
- Drupal 7
- A better search facility for Drupal
- Drupal - performance or flexibility
- Drupal 7 Fields are hard to fix
- Drupal 7 new features
- Drupal 7 ships on January 5
- Drupal 7.14
- Drupal 7.4 hits PeterMoulding.com
- Drupal function sequence
- The evolution of a module
- Undefined index: headers in DefaultMailSystem->mail() (line 54 of /modules/system/system.mail.inc).
- Undefined index: to in DefaultMailSystem->mail() (line 83 of /modules/system/system.mail.inc).
- implode(): Invalid arguments passed in DefaultMailSystem->format() (line 23 of /modules/system/system.mail.inc).
- Drupal 8
- Drupal Code Load Cut
- Drupal How To
- Drupal Modules
- Backup and Migrate
- Browscap
- CKEditor with Drupal WYSIWYG
- Captcha
- Cel
- Colorbox
- Content Construction Kit
- Content type
- Devel module for Drupal
- Drupal Rules as an automation language
- Drupal Spam add-on module
- Form alter to node
- IMCE
- IMCE Wysiwyg bridge
- ImageAPI
- Jdog
- Lightbox2
- Module variable
- Node Gallery Access
- Node_Gallery
- Path
- Path redirect
- Pathauto
- Pet
- Search
- Service links
- Session Variable
- Statistics
- Taxonomy
- Token
- Token ex
- Transliteration
- Trigger
- Watch
- Other modules
- Drupal Training
- Drupal access controls need a major rewrite
- Drupal coding tricks
- Drupal performance
- Drupal themes for the future
- Drupal.org colours
- Import existing data into Drupal
- Multiple Web sites made easy using Drupal multisite and the right start
- drupal_lookup_path()
- Adobe PDF
- Apache
- Apache Mahout
- Audi.com
- Bleet
- CSS Strikes Again
- CSS or xCSS
- Can you believe Facebook or email?
- Content Management Systems
- Databases
- Facebook scam
- Font
- Fonts
- HTML
- Install Apache, MySQL, and PHP 5 in Ubuntu 11.4 using the Ubuntu Software Centre
- Language Codes
- Marketing
- Memcache
- Nginx
- Open source development hits another roadblock
- Oscars
- PHP
- SPDY
- Search software
- Techoni.com.au
- Theme themes
- Things to hate on Web sites
- U.S. Patent No. 6,985,875
- Virtual Private Server
- Visible Improvement
- Web 4.0
- Web browser usage
- Web browsers
- Web site development
- Bluefish
- Crying over spilt code
- Eclipse and PHP
- Getting a Git client, a story of ancient technology and pain
- HTTrack
- MVC
- Netbeans
- PHP or ..., CakePHP/Symfony/ZF versus ...
- Programming
- Superfish
- Web browser emulators for testing your Web site
- Web development frameworks
- Web site books
- Web site development on your own computer
- Webmin or phpMyAdmin or cPanel for creating databases?
- aiki framework
- jQuery
- Views development - Learn Fields first
- Views development - Learn Actions and Rules
- jQuery .each()
- jQuery .has()
- jQuery .is()
- jQuery and Firefox Firebug
- jQuery children
- jQuery for people not using Drupal - Installation and getting started
- jQuery hover
- jQuery hover de-duplication example
- jQuery or CSS?
- jQuery performance
- jQuery tests
- Web site hosting
- Westpac Web site still broken after two years and ten months
- Wordpress wins another CMS survey
- Drupal
MVC
Submitted by Peter on Wed, 2011-03-02 11:11
MVC is Model View Controller, a way to structure programs and applications.
MVC is one of many ways to structure programs and applications. Some parts are obvious while others confusing. Everyone using MVC has a favourite variation and blindly accepts a lot of inconsistencies. Lets look at the theory and some actual practice.
The semantic Web
Semantic is a fashionable buzzword around the Web and is good in intent with many parts still evolving. Think if the semantic Web as someone inventing penicillin to cure people of horrible diseases but at a time when people are still trying to invent a usable syringe to inject the penicillin.
The semantic approach requires the separation of data from the presentation of data for at least two important reasons applicable today.
First, visually impaired people can change the presentation of data to fit their range of vision. As an extension of visual impairment, people with smartphones and Apple products, iPhone, iPad, iProfit, can change the presentation to fit a very small screen.
Second, search engines and other applications can access the data without processing all the decorative stuff.
The third reason for the semantic Web, the one still under development, is the addition of data to identify the meaning of data, commonly called metadata. There are lots of ways to add metadata, not much agreement on what you need or what is useful, and very few applications that can use all the metadata.
In the web we can separate presentation from the data by taking all the decoration out of the HTML and placing it in CSS. The CSS can be downloaded once and cached in the Web browser, making your Web site faster and the Web more efficient.
The MVC equivalent is the View. The view formats the output without any programming. To be more specific, there should be no programming related to business logic, application logic, or data conversion. The problem with the View is the ideal is impossible. The advantage with the View is the first step towards separation of presentation.
Model
Some people classify the model as the database. Application ends up in the controller. Most people do the reverse, they put all the business logic in the model and the controller is just a skinny bit selecting the next page to be displayed.
Zend Framework documentation on the model says:
Data access routines and some business logic can be defined in the model.
If you follow the Zend advice, where do you put the resr of the business logic? Why spread the business logic over two areas?
Data usually has relationships, some relationships are part of the business model, and some relationships can be placed in a database. If table ABC has rows identifying invoices and table ABCL contains line items for the invoices and you are using the PostgreSQL database, you can tell PostgreSQL to treat rows in ABCL as children of ABC. Some simpler databases do not let you define relationships. Either way, you model has to understand the relationships.
When someone types in the data for an invoice, they type in the invoice level details then one or more line items. The controller has to know the difference between an invoice and a line item to display the right view, the invoice entry view or the line item entry view. The controller has to know how to switch from the invoice view to the line item and how to switch back when the line items are complete.
Business logic might be involved in the controller decision. Your invoices might require at least one chargeable item plus a matching tax item. Your invoices might require a delivery charge line item even if there is no change. These are your business rules imposed on the basic data structure of an invoice.
View
Look at some example view problems. You have an application displaying money. Should the money amount be formatted in the business logic or in the view? If you work in only one currency, it could be formatted in the view. In some countries a thousand dollars will be $1,000.00 while some Europeans prefer $1.000,00. The view could decide based on the country selected in the profile of someone who is logged in or based on information passed in by their Web browser.
Now expand the currency problem. Process multiple currencies. The business logic has to know the type of currency for an amount. If the amount is processed in the view, the view has to know both the currency and the country of display.
Lets make it more complicated. Your currency might be dollars and cents with two digits displayed for cents. Tax calculations might be made to fractions of a cent then rounded back to cents at the end of the calculation. When you display calculation rates and intermediate amounts, the view would have to know enough to display the right number of digits. An intermediate tax calculation amount might be $35.6745 where the last bit is a fraction of a dollar, not cents.
Try explaining the difference to a view. Try explaining it to a view so the view can send out the data wrapped in HTML with no presentation
information and attach the right CSS.
The typical approach is to process currencies outside of the view to ensure they are correct and to process country level display requirements because they are wrapped up in language processing. You might set up one view for left to right language display and a separate view for right to left. Separate views have the advantage that different people can work on the views.
A view should contain presentation, not data, but many views contain data. They contain the text displayed on a page. When the Web site owner decides to add German to an English language Web site, he/she suddenly finds large parts of the data (the content text) is written into views. There will be a huge cost of moving the text (the data) from the views to the database.
Then the web site owner decides to add Mandarin. Suddenly the text has to be displayed in a different format. Do you use one view, pass the language information, and let the view work out how to present everything or do you create different views?
There are more complicated parts of views. Multipage form handling can be part of the view if it is simply one form over several pages. What do you do when the answers on one page decide which pages should be displayed next? Selective display is business or application logic and should not be in a view.
Lists can be displayed, paged, and sorted in a view without using business or application logic. Sending a default selection from a user’s profile to the view is still acceptable. What do you do when you want to save a user’s selection back to their profile? What do you do when their selection is used to control another part of the application? Again you have part of the view interacting with the data in a way that really should be business or application logic.
Zend Framework documentation on the view says:
Views define exactly what is presented to the user. Usually controllers pass data to each view to render in some format. Views will often collect data from the user, as well. This is where you're likely to find HTML markup in your MVC applications.
HTML can be used to indicate markup (presentation) or structure. Structure is best produced as XML. XHTML makes the most sense for structured data set to a view because the structure can be presented with the addition of CSS and no further processing. If you want to sort a table of data and the table is in an XHTML tble, the user can sort it in any sequence with some Javascript. That is the important bit when thinking about HTML markup instead of HTML.
Some people impose a rule that all HTML must be in the view and nowhere else. They then have to select a way of passing structured data to the view and argue over what is acceptable.
Controller
Zend say:
Controllers bind the whole pattern together. They manipulate models, decide which view to display based on the user's request and other factors, pass along the data that each view will need, or hand off control to another controller entirely. Most MVC experts recommend keeping controllers as skinny as possible.
There are MVC frameworks where nothing happens in the controller. The controller asks the model what should be done next. The model might redirect to a new page.
In the next level up, the controller decides navigation. The controller knows page AA can go to page BB or CC depending on a user selection in a form. The controller can look at the request and make that simple decision.
Then you add editing of user input to the form on page AA. The reply from AA has to be validated in the model before the controller can decide which page is next. There might be a requirement to redisplay AA with error messages. Suddenly it is easier to put navigation in the model. You are back to nothing in the controller.
Layers
Layering software makes sense because an application can be split into several areas for development by specialists with different skills. The view makes sense as a layer if it has a narrow range of code.
View layers can have the formatting instructions in an XSL layer and the programming code in another layer. Assume the Web scripting is written in PHP. There would be a programming layer maintained by a PHP programmer. An XSL expert could work on the XSL. XSLT, the transformation part of XSL, is a type of programming that is half way between the procedural thinking of PHP and the non procedural thinking of CSS. Splitting the work between two brains is a good idea.
When you layer the view into programming and presentation, you effectively have a controller layer and a view layer within the view.
The model can be split into a database related layer, a data related layer, an application layer, and a business logic layer. The database layer is usually called a database abstraction layer and gives you some freedom to use other databases. The other layers give you other freedoms.
The data layer attacks problems along the lines of the invoice/line item problem. You sometimes want to treat an invoice as one object, including the line items, and not worry about the way it is stored in the database. The data layer can do that. The data layer can return the invoice with the customer data attacked, the currency and tax rate attached, whatever level of information you need. The data layer can also save changes with the updates minimised to just the database rows that change.
An application layer might calculate delivery charges in several ways. The business layer might decide when a delivery charge is applied and when delivery is free. The business layer might be changed by the company accountant in consultation with the sales manager and other people. The application layer might be maintained by the people supplying the application. The people supplying the application might build their part into programming code for speed. The business layer should have everything stored in the database with update forms created for the accountant.
Frameworks
Read about frameworks in Web development frameworks. Most frameworks have some sort of structure that fits into an MVC style. Some frameworks let you decide what you put in the model, the view, and the controller. Some frameworks define exactly what goes into each area. The right framework for you is more important that the fine details of what they put where.
Conclusion
The View part of MVC is required for the semantic Web. The rest of MVC is so variable that it is almost irrelevant. You are better off choosing a development framework and using the structure built in to the framework.








