1 / 12

MVC (Model View Controller)

MVC (Model View Controller). Sergey Gorstka Fastw3b. Definitions.

Download Presentation

MVC (Model View Controller)

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. MVC(Model View Controller) Sergey Gorstka Fastw3b

  2. Definitions • Model–view–controller (MVC) is a software architecture, currently considered an architectural pattern used in software engineering. The pattern isolates "domain logic" (the application logic for the user) from the user interface (input and presentation), permitting independent development, testing and maintenance of each (separation of concerns). [Wikipedia] • The Model-View-Controller (MVC) pattern separates the modeling of the domain, the presentation, and the actions based on user input into three separate classes [MSDN] • Model View Controller MVC is a time tested method of separating the user interface of an application from its Domain Logic. [WACT]

  3. Why to use MVC? • Clarity of extension architecture • Efficient modularity • Multiple views • Scalability • Flexibility • Powerful user interfacesThe MVC paradigm is a way of breaking an application, or even just a piece of an application's interface, into three parts: the model, the view, and the controller. MVC was originally developed to map the traditional input, processing, output roles into the GUI realm:Input --> Processing --> OutputController --> Model --> View

  4. The Concept

  5. Typical Workflow • The user interacts with the user interface in some way. • The controller handles the input event from the user interface, often via a registered handler or callback, and converts the event into an appropriate user action, understandable for the model. • The controller notifies the model of the user action, possibly resulting in a change in the model's state. • A view queries the model in order to generate an appropriate user interface. The view gets its own data from the model. The user interface waits for further user interactions, which restarts the control flow cycle.

  6. MVC Component in Joomla! • Entry point • Controller • View(s) • Model(s) • Template • Package description (XML manifest)

  7. The model manages the behaviour and data of the application domain, responds to requests for information about its state (usually from the view), and responds to instructions to change state (usually from the controller). In event-driven systems, the model notifies observers (usually views) when the information changes so that they can react. JModel Class jimport(‘joomla.application.component.model’); Class HelloModelHello extends JModel { function getSomeText () { return ‘some text’; } } Defining the model

  8. The model manages the behaviour and data of the application domain, responds to requests for information about its state (usually from the view), and responds to instructions to change state (usually from the controller). In event-driven systems, the model notifies observers (usually views) when the information changes so that they can react. JView Class jimport(‘joomla.application.component.view’); Class HelloViewHello extends JView { function display($tpl = null) { $model = &$this->getModel $sometext = $model->getSomeText(); $this->aasignRef (‘sometext’, $sometext ); parent::display($tpl); } } Creating a view in Joomla

  9. The controller receives user input and initiates a response by making calls on model objects. A controller accepts input from the user and instructs the model and view to perform actions based on that input. JController Class jimport(‘joomla.application.component.controller’); Class HelloController extends JController { function display () { parent::display(); } } Component controller in Joomla!

  10. Recommendations • Put all business login in the model. • Put HTML in views. • Use controller for handling user behaviour. • Implement error handling. • Guard against common attacks. • Authenticate users to protect content.

  11. Summary • MVC is a simple time proven concept • MVC is supported by Joomla! Architecture • MVC helps to secure extensions • MVC is a must for long-term projects • MVC helps you with vivid presentation MVC is a must in Joomla!

  12. Thank you for your attention! Special thanks to Fastw3b team and Gregory Palchikovsky You can always reach me atceo@fastw3b.net Please send your questions/comments/ideas!

More Related