|
|
| (25 intermediate revisions by the same user not shown) |
| Line 1: |
Line 1: |
| Using parameters with a component
| |
|
| |
|
| Background
| |
| When storing data for a component in a table in the Joomla! database, there are essentially two choices: each data item may be stored in its own field, or a collection of data items may be stored within a single parameters field. (Of course, there is nothing to stop you making use of both methods, for different data items, within the same component). Which approach you use for a given data item is largely a matter of personal choice, although there are some factors to consider:
| |
| * Core code included in the Joomla! installation makes it very easy to produce the appropriate form elements for entering data into parameters in the backend. If you choose to save the data in separate fields, you will need to code the appropriate form elements yourself.
| |
| * Again, Joomla! core code allows you to set default values for parameters across the whole component. Individual component items (e.g. individual articles for the com_content component - these will be referred to generically as 'articles' below) can then choose to use the default values, or to override them with values specific to that item.
| |
| * It is not possible to extract individual parameter values directly from the database. Instead, the whole parameters field must be extracted and parsed to obtain the different parameter values. This means that it is not very easy, for example, to run MySQL queries that search for a parameter with a particular value. Any data that you want to run queries against should be given its own table field.
| |
| * Similarly, it is not possible to run data validation on parameter fields before saving data.
| |
| In general, parameters are conventionally used to store data relating to the ''presentation'' of information. The information itself is generally stored in separate form fields.
| |
|
| |
| Storage of component parameters
| |
| Component parameters may be stored in three different locations. Firstly, the component-wide '''default''' parameters are stored in the <code>params</code> field of the <code>#__components</code> table in the Joomla! database, in the row corresponding to your component. Secondly, the parameters for a particular '''article''' are stored in a text field (usually called <code>params</code>). This is located in whatever table you are using to store your articles (i.e. <code>#__mycomponent_data</code> or whatever), in the row corresponding to that particular article. Finally, any parameter overrides associated with a particular '''menu item''' are stored in the <code>params</code> field of the <code>#__menus</code> row for that item.
| |