Reputation: 127
I'm developing a component for Joomla! 3. It has a "contact" view displaying three links which leads to the:
This page is displayed by means of a layout with the name default.php
of a "contact" view. How should I implement this 3 pages? Is it better to display them with the same view by means of its separate layouts or it more correct to create three separate views for each from the mentioned pages? All these three pages are all about the work with contacts.
Upvotes: 0
Views: 310
Reputation: 6418
You can do it using the same view
using different layouts
. Say you have three layouts-
Then make three layouts at
component/com_yourcomponent/views/contact/tmpl/default.php
component/com_yourcomponent/views/contact/tmpl/default_form.php
component/com_yourcomponent/views/contact/tmpl/default_import.php
Now you can access the layouts by using the layout
query at the URL. Say for showing the form
layout you have to hit the URL-
http://yoursite.com/index.php?option=com_yourcomponent&view=contact&layout=form
Yes, If you want to access them from the menu then you have to do some more job. You have to create three more files inside the same view's tmpl
directory along with layout .php
files. The files path would be-
component/com_yourcomponent/views/contact/tmpl/default.xml
component/com_yourcomponent/views/contact/tmpl/form.xml
component/com_yourcomponent/views/contact/tmpl/import.xml
And a sample .xml
file (say form.xml
) looks like-
<?xml version="1.0" encoding="utf-8"?>
<metadata>
<fields name="params">
<fieldset name="basic" label="Basic">
<!-- Your menu settings params are here-->
</fieldset>
</fields>
<layout title="COM_YOURCOMPONENT_FORM_VIEW_DEFAULT_TITLE" option="COM_YOURCOMPONENT_FORM_VIEW_DEFAULT_OPTION">
<help
key = "JHELP_MENUS_MENU_ITEM_CONTACT_FORM"
/>
<message>
<![CDATA[COM_YOURCOMPONENT_FORM_VIEW_DEFAULT_DESC]]>
</message>
</layout>
</metadata>
And you have to do some more extra job at component/com_yourcomponent/views/contact/view.html.php
and that is, set the layout comes from the menu at the display()
function.
$this->layout_type = str_replace(':_', '', $layout);
$this->setLayout($this->layout_type);
There is only one place for data manipulation for all the view layouts. So you can catch the layout name by using $this->layout_type
and apply your business logic conditionally.
Hope, this will help you.
Upvotes: 2