25
Lecture#04

Pages within our Framework Categories within Framework Products within Framework Model-View-Controller description of Page, category and products

Embed Size (px)

DESCRIPTION

FieldsFields TypeDescription IdInt (Primary Key, Auto Increment) A reference to framework for content entity Current_ revision IntRefer to current version of content type ActiveBooleanActive or inactive to show user SecureBooleanSecure or insecure to show either logged in user or not ParentIntA reference to its parent content type OrderIntA reference to the order of the content type to build sitemap or menus AuthorIntWho created the first version of content type TypeIntA reference to type of content this entity is PathVarcharSearch engine friendly path for the content CreatedTiemstampWhen the entity is created

Citation preview

Page 1: Pages within our Framework  Categories within Framework  Products within Framework  Model-View-Controller description of Page, category and products

Lecture#04

Page 2: Pages within our Framework  Categories within Framework  Products within Framework  Model-View-Controller description of Page, category and products

Ouline

Pages within our Framework Categories within Framework Products within Framework Model-View-Controller description of

Page, category and products Routing Requests

Page 3: Pages within our Framework  Categories within Framework  Products within Framework  Model-View-Controller description of Page, category and products

Content TableFields Fields Type DescriptionId Int (Primary

Key, Auto Increment)

A reference to framework for content entity

Current_revision

Int Refer to current version of content type

Active Boolean Active or inactive to show userSecure Boolean Secure or insecure to show either logged in

user or notParent Int A reference to its parent content typeOrder Int A reference to the order of the content type

to build sitemap or menusAuthor Int Who created the first version of content

typeType Int A reference to type of content this entity isPath Varchar Search engine friendly path for the contentCreated

Tiemstamp When the entity is created

Page 4: Pages within our Framework  Categories within Framework  Products within Framework  Model-View-Controller description of Page, category and products

Pages within Framework

To enable pages in framework we need: A model-Connection to database and

represent data on page A controller- will look up the current page A template (view)- display data on page to

user With all above, we need some extra

information Menu and Sub menu options Breadcrumb generation

Page 5: Pages within our Framework  Categories within Framework  Products within Framework  Model-View-Controller description of Page, category and products

Pages within Framework-Model Model

Ability to connect to database Search for a page given by page name/path Represent data on the page If no page found, generate “Page not found”

error Can be achieved using a constructor

Pass page path as parameter Set values to properties if page found Set particular value if page not found

Page 6: Pages within our Framework  Categories within Framework  Products within Framework  Model-View-Controller description of Page, category and products

Pages within Framework-Model We need following methods for page

model isValid(): used by controller to lookup if

the page is valid or not? isActive(): used by controller to lookup if

the page is active or not? isSecure(): used by controller to check if

the page is secure or not? And accessible to user or not?

getProperties(): return the properties of the page to integrated with view

Page 7: Pages within our Framework  Categories within Framework  Products within Framework  Model-View-Controller description of Page, category and products

Pages within Framework-View

Page view should have following template pages Header- to have common header on most of

the pages Footer- to have common footer on most of

the pages Page- to display the page to user

We my have additional pages in template 404 Error: indicates page not found Login: logged in by user to access secure

pages Page Disable: show page is inactive

Page 8: Pages within our Framework  Categories within Framework  Products within Framework  Model-View-Controller description of Page, category and products

Pages within Framework-View

Header Template

It may also contain CSS, JavaScript, Icon etc information

Page 9: Pages within our Framework  Categories within Framework  Products within Framework  Model-View-Controller description of Page, category and products

Pages within Framework-View

Footer Template It may contain copyright info, about us,

terms and conditions etc. Page Template

In case of “Page not found” template

Page 10: Pages within our Framework  Categories within Framework  Products within Framework  Model-View-Controller description of Page, category and products

Pages within Framework-View We may have other templates in

framework Page Disable template Login Form template Signup Form template Shipping Address template Change password template Shopping Cart template And sooooooooooooooo on

Can be limited with limited requirements

Page 11: Pages within our Framework  Categories within Framework  Products within Framework  Model-View-Controller description of Page, category and products

Pages within Framework-Controller

Controller of pages needs to perform the following task Clean the path requested Pass path to page model If the page is valid, convert page

properties to tags to use in template, output the page view

If the page is invalid, display 404 page If the page is valid and secure, display

the page if user is logged in, else direct user to login page

Page 12: Pages within our Framework  Categories within Framework  Products within Framework  Model-View-Controller description of Page, category and products

Products within Framework We breakdown functionality into 3

areas Model- manage product data by update,

save, clone Controller- interpret users requests,

interface with model, interact with view to display data

Template- to display list of products to end user

Page 13: Pages within our Framework  Categories within Framework  Products within Framework  Model-View-Controller description of Page, category and products

Products within Framework-Model

Product model needs the following functionality: Lookup a product based on a product path Determine if a product exists or not,

based on said path Store product data Return product data as an array Return a Boolean value indicating if a

product is valid or not

Page 14: Pages within our Framework  Categories within Framework  Products within Framework  Model-View-Controller description of Page, category and products

Products within Framework-View

Product View

Page 15: Pages within our Framework  Categories within Framework  Products within Framework  Model-View-Controller description of Page, category and products

Products within Framework-Controller Product Controller needs the

following functionality Needs to communicate with controller Clean the path requested Pass product URL path to controller If a valid product URL, display it using

view If not a valid URL, display “product not

found” page

Page 16: Pages within our Framework  Categories within Framework  Products within Framework  Model-View-Controller description of Page, category and products

Categories within Framework Our categories functionality of framework

will be same as products model and controller with some minor difference Not as many tables are required to get the

category detail, content_version table is enough

Categories need to list products contained within them

We have to deal with child-parent categories structure

Page 17: Pages within our Framework  Categories within Framework  Products within Framework  Model-View-Controller description of Page, category and products

Categories within Framework-Model Categories Model

Is complex than other product and pages model because it deals with categories and sub categories

In First stage▪ Use subqueries, that will count no. of subcategories▪ Queries are then cached and its references are

passed to template or view to display products In 2nd Stage

▪ Adding some additional functions in controller about cached queries, if there are any subcategory

Page 18: Pages within our Framework  Categories within Framework  Products within Framework  Model-View-Controller description of Page, category and products

Categories within Framework-View Categories View

We need 3 types of templates to display categories to end user

Category template Subcategory template Products Template within category

Page 19: Pages within our Framework  Categories within Framework  Products within Framework  Model-View-Controller description of Page, category and products

Categories within Framework-View Categories View

Category template

Page 20: Pages within our Framework  Categories within Framework  Products within Framework  Model-View-Controller description of Page, category and products

Categories within Framework-View Categories View

Subcategory template

Page 21: Pages within our Framework  Categories within Framework  Products within Framework  Model-View-Controller description of Page, category and products

Categories within Framework-View Categories View

Products template

Page 22: Pages within our Framework  Categories within Framework  Products within Framework  Model-View-Controller description of Page, category and products

Categories within Framework-Controller Categories Controller

Communicate with Model to get categories If no category found, show “No Category

Found” page List categories and sub categories using view If no subcategory found, show “No

Subcategory Found” page List products within categories using views, if

any, else show “No Product in Category”

Page 23: Pages within our Framework  Categories within Framework  Products within Framework  Model-View-Controller description of Page, category and products

Some thoughts In our framework, so far, the models,

controllers and views of products, categories, pages have same format

Thy can be improved using inheritance in PHP

Common classes can be defined with common functionalities

Product view includes one photo of product Product view can be changed to mange

more photos of products

Page 24: Pages within our Framework  Categories within Framework  Products within Framework  Model-View-Controller description of Page, category and products

Routing products and categories First path of the URL should include

the area of site that user is trying to access http://domain/sitearea etc

We need to maintain a list of active controllers

If sitearea match with any active controller Include controller file, create controller

object, pass control to framework controller

Else shows 4o4 page error or “Page not found”

Page 25: Pages within our Framework  Categories within Framework  Products within Framework  Model-View-Controller description of Page, category and products

Routing products and categories We need a controller table to save

list of active controllers