| home | resources | search | news | join | members: 6958 |
joomla | Wed, 2008-05-07 20:18 tags: Developer Zone, Joomla, Tutorials One of the hardest things to do in any of the more popular CMS is to create and extension or module. This is because the easier it is for the end user the more complicated the code and procedure become for the programmer. If you are not the originating programmer then you have your work cut out for you. Depending on the level of documentation and the willingness of others to part with needed information it can be easy or hard. Sometimes though you just need a good "Hello world" script to get you started in the right direction. Petr Vojtechovsky wrote an excellent tutorial on how to use the new MVC framework in Joomla! to create a component. Introduction:I described my first "helloworld component for joomla 1.5 in my previous tutorial hello world component for joomla 1.5 I have got a huge response for joomla developers and I believe some of them were right pointing out This is very brief introduction. Please refer to these links for thorough explanation. MVC - model view controller MVC is an architectural pattern used in software engineering. In complex computer applications that present lots of data to the user, The MVC paradigm is a way of breaking an application, or even just a piece of an application's interface, into three parts: MVC was originally developed to map the traditional input, processing, output roles into the GUI realm:
Input --> Processing --> Output Controller --> Model --> View ModelThe model is the part of the component that encapsulates the application's data. It will often provide routines to manage and manipulate this data in a meaningful way in addition to routines that retrieve the data from the model. In our case, the model will contain methods to add, remove and update information about the books in the database. It will also contain methods to retrieve the list of books from the database. In general, the underlying data access technique should be encapsulated in the model. In this way, if an application is to be moved from a system that utilizes a flat file to store its information to a system that uses a database, the model is the only element that needs to be changed, not the view or the controller. ViewThe view is the part of the component that is used to render the data from the model in a manner that is suitable for interaction. For a web-based application, the view would generally be an HTML page that is returned to the data. The view pulls data from the model (which is passed to it from the controller) and feeds the data into a template which is populated and presented to the user. The view does not cause the data to be modified in any way, it only displays data retrieved from the model. ControllerThe controller is responsible for responding to user actions. In the case of a web application, a user action is a page request. The controller will determine what request is being made by the user and respond appropriately by triggering the model to manipulate the data appropriately and passing the model into the view. The controller does not display the data in the model, it only triggers methods in the model which modify the data. Joomla! MVC ImplementationIn Joomla!, the MVC pattern is implemented using three classes:
Hello world componenta) structure│ com_helloworld.xml (xml - installation source) │ ├───admin - (administration folder) │ │ index.html - (blank file) │ │ admin.helloworld.php - (create controller and hand over the control) │ │ toolbar.helloworld.php - (tool bar definition and a 'help' menu item) │ │ toolbar.helloworld.html.php - (tool bar definition and a 'help' menu item) │ │ │ ├───images - (here are all picures used in the component) │ │ helloworld.png │ │ index.html - (blank file) │ │ │ ├───controllers - (controllers folder) │ │ default.php - (default controller - "default section") │ │ helloagain.php - (helloagain controller - "helloagain section") │ │ hellotestfoo.php - (hellotestfoo controller - "helhellotestfooloagain sec.") │ │ helloworld.php - (helloworld controller - "helloworld section") │ │ │ ├───models - (models folder) │ │ helloworld.php - (the only model defined here. Currently not in use) │ │ │ ├───views - (views folder) │ │ ├───default │ │ │ view.php - (default view - "default section") │ │ │ │ │ ├───helloagain │ │ │ view.php - (helloagain view - "helloagain section") │ │ │ │ │ ├───hellotestfoo │ │ │ view.php - (hellotestfoo view - "hellotestfoo section") │ │ │ │ │ └───helloworld │ │ view.php - (helloworld view - "helloworld section") │ │ │ ├───sql - (SQL folder. Currently not in use. All sql files) │ │ uninstall.helloworld.sql ( are commented out in the installation xml.) │ │ install.helloworld.sql ( The reasson is very simple. Joomla! 1.5 has ) │ │ ( a minor bug in installation.php. We will need ) │ │ ( a "night build" for the next tutorial) │ │ │ └───lang - (language folder) │ cs-CZ.com_helloworld.ini - (czech text package) │ en-GB.com_helloworld.ini - (english text package) │ └───component │ index.html - (blank file) │ helloworld.php - (core for the frontend application. ) │ ( Prints "hello world".) └───lang cs-CZ.com_helloworld.ini - (czech text package) en-GB.com_helloworld.ini - (english text package) b) concept We need to rewrite the core of our previous component. class helloScreens
{
function helloworld()
{ echo JText::_('helloworld'); }
function helloagain()
{ echo JText::_('helloagain'); }
function hellotestfoo()
{ echo JText::_('hellotestfoo'); }
function hellodefault()
{ echo JText::_('hellodefault'); }
}
All these methods will become stand-alone views. \views\helloworld\view.php class HelloWorldComponentView extends JView
{
function display()
{
echo JText::_('helloworld');
}
}
As you can see there is no model instance passing into the view or accessing from the view.
Thoughtbox - So what did you think? |
Wordpress London Hotels
Drupal Laptop Reviews
Wordpress Just Dial International Calls
Drupal Excel Training Courses
Joomla! excel courses in london
eRuby Data Recovery
|
||||||||
NewsletterGet updates on Hiveminds services, articles and downloads by signing up for the newsletter. |
Editor's choiceSome of the better articles, stories and tutorials found at Hiveminds. |
Find moreFind more of Hiveminds articles, stories, tutorials and user comments by searching. |
Picked linksHand picked websites and articles from around the web that provide quality reading. |