Creating extensions for Joomla! 1.5 - Managing the Back - Part 1 view recods

Writing extensions with Joomla!Component Builder is quite easy since it is the program that takes care to write the skeleton for models, views and templates for editing. You have only to define the business logic for data managing, but this is your own task.

 

Operation of the components for Joomla!1.5

Each component of Joomla! has, whether we speak of front end or back end, an entry point. This is a PHP file, named as the component, which receives the requests that must be managed by the component. This file will then define which view and which controller to load.

Side Back - End

At back end side, the work for the entry point is quite more difficult than front-end, because, as access is not made via a menu item, you must define the controller / view .

The file generated by Joomla Component Builder includes a die () to remind us where to make changes.

... [ccat.php]
die ( 'Insert the default view in'. __FILE__. 'After line n. '. __LINE__);
/ / Define default controller & view ...
if (!JRequest: getword ( 'controller')) (
JRequest:: setvar ( 'controller', '***'); / / insert here!
JRequest:: setvar ( 'view', JRequest: getword ( 'controller'));
) else (
JRequest:: setvar ( 'view', JRequest: getword ( 'controller'));
)

Instead of three asterisks we enter the name for the default controller, but what is the default controller?
Obviously the answer varies from project to project, usually is the basic information that we changed more frequently, in our case: brands(ccatbrands). Remember to remove or comment out the line with die ().

Note that the basic controller always refers to the record set, never the single record (that brings up the list).

File ccat.php, as shown by the code, then loads the specified controller, which contains the code needed to perform the following tasks ($ task):

  • edit (): call the controllorer for editing of individual record
  • save () saves the information of each record [to eliminate in the next release]
  • remove (): delete individual records [to be deleted in the next release]
  • publish (): it publish individual records
  • unpublish (): Hides the individual records
  • orderup (): Move through records (requires ccatbrand model, to act on the individual records)
  • orderdown (): moves the record down (requires model ccatbrand, to act on the individual records)
  • saveOrder (): save the display order of records (requires ccatbrand model, to act on the individual records)

With the its inclusion, the controller calls the constructor and the method display () of base the class JController; and the Joomla! framework then loads the following files:

  • / administrator / components / com_ccat / views / ccatbrands / view.html.php
  • / administrator / components / com_ccat / views / ccatbrands / tmpl / default.php
  • / administrator / components / com_ccat / models / ccatbrands.php
  • / administrator / components / com_ccat / tables / ccatbrand.php

A step back:

  1. when statement $controller->execute(JRequest::getVar ( 'task')) is executed, in the file /components/com_ccat/ccat.php,
  2. is invoked the method display() in file /administrator/components/com_ccat/controllers/ ccatbrands.php
  3. The controller call the method display() of the class CcatViewCcatbrands in /components/com_ccat/views/ccatbrands/view.html.php

Within the last file we have, among others, the following lines of code:

function display ($ tpl = null) (
...
JToolBarHelper ::[...]
...
$ data = $ this->get ( 'Data');
$ this-> assignRef ( 'rows', $ data);
...
parent::display ($ tpl);
)

The header of the method display() require the optional parameter $tpl, Attention! is not the name of the template to load, but the name of subtemplate!

  1. Instructions JToolBarHelper::[...] are used to generate the buttonhole for the functions of sorting, editing and creating new records.
  2. The code $data = $this->get( 'Data') invokes the method getData() in the file /components/com_ccat/models/ccatbrands.php (class CcatModelCcatbrands), this method makes the query on the db and returns a recordset as an array of objects, in the Joomla! standard.
  3. the code $this->assignRef( 'data', $data) creates the property $this->data within the class CcatViewCcatbrands so that such information is easily accessible from the template.
  4. the code parent::display($tpl) invokes and executes the file /components/com_ccat/views/ccatbrands/tmpl/default.php that displays the contents of the recordset.

Within the file /components/com_ccat/views/ccatbrands/tmpl/default.php yuo will find two areas marked by the delimiters "<! - Joomla!Component Builder - begin code -> "and" <! - Joomla!Component Builder - end code -> ";these are placed in the header of the table and within the table itself. In these areas, Joomla Component Builder writes the fields retrieved from the table in the db (# __ccat_brands) so they are viewed: remove those that are not of interest in this View.

In the file /components/com_ccat/views/ccatbrands/tmpl/default.php you will find a code like this:

 
<?php
$ k = 0;
for ($ i = 0, $ n = count ($ this-> rows); $ i <$ n, $ i + +) (
$ row = & $ this-> rows [$ i];
$ checked = JHTML ::_(' grid.id ', $ i, $ row-> id);
$ published = JHTML ::_(' grid.published ', $ row, $ i);
$ link = JRoute:: _ ( 'index.php?option = com_mac & DC = ccatbrands & task = edit & cid []='. $ row-> id);
?>
[... html code for displaying the adminList, or all records in the table]
<?php
$ k = 1 - $ k;
)
?>

The for loop iterates through all the records retrieved by the method getData(), presents in the model, and assigned to $this->rows by the view with assignRef(); the previous lines of code used to create objects standard adminList for Joomla ( checkbox, icon publication, et cetera)

The code $link = JRoute::_("...") creates the URL to edit the individual records; in the next article we will see how to do this.

 

 



Add to your favorite Bookmarking / Aggiungi ai tuoi segnalibri prferiti

 

Aggiungi commento


Codice di sicurezza
Aggiorna