130 likes | 252 Views
MVC (Model View Controller). Sergey Gorstka Fastw3b. Definitions.
E N D
MVC(Model View Controller) Sergey Gorstka Fastw3b
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]
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
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.
MVC Component in Joomla! • Entry point • Controller • View(s) • Model(s) • Template • Package description (XML manifest)
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
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
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!
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.
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!
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!