Goldensites. Создание сайтов. Разработка сайтов.

Новое на сайте

Редизайн сайта для Avantage, г.Новосибирск
Сайт на домене www.avantage-sib.ru; Разработка эксклюзивного дизайна в соответствии с
Создание сайта для оценочной компании Эстима, г.Барнаул
Сайт на домене www.estimacom.ru; Разработка эксклюзивного дизайна в соответствии с
Разработка сайта для ООО Алтай-Метран-Сервис
Сайт на домене www.ams-bar.ru; Разработка эксклюзивного дизайна для организации, занимающейся
Добавить сайт в каталог лучшихсайтов Joomla!

Вход в личный кабинет Goldensites

LiveZilla Live Chat Software

Портфолио по дизайну сайтов, разработке сайтов, созданию фирменного стиля

Создание компонента для Joomla! 1.6 (часть 5)- Добавляем параметры запроса в пункт меню

Сначало прочтите  Продолжаем разработку компонента для Joomla! 1.6 (Часть 4)

На настоящий момент наш тестовый компонент выводит на экран лишь одно сообщение - "Hello World!". В Joomla! 1.6 есть возможность добавлять параметры запроса пунктам меню, для этого необходимо использовать созданный нами ранее файл yoursite.ru/components/com_helloworld/views/helloworld/tmpl/default.xml


<?xml version="1.0" encoding="utf-8"?>
<metadata>
        <layout title="COM_HELLOWORLD_HELLOWORLD_VIEW_DEFAULT_TITLE">
                <message>COM_HELLOWORLD_HELLOWORLD_VIEW_DEFAULT_DESC</message>
        </layout>
        <fields name="request">
                <fieldset name="request">
                        <field
                                name="id"
                                type="list"
                                label="COM_HELLOWORLD_HELLOWORLD_FIELD_GREETING_LABEL"
                                description="COM_HELLOWORLD_HELLOWORLD_FIELD_GREETING_DESC"
                                default="1"
                        >
                                <option value="1">Hello World!</option>
                                <option value="2">Good bye World!</option>
                        </field>
                </fieldset>
        </fields>
</metadata>




Теперь администратор, при создании пункта меню, будет иметь возможность определить какое сообщение будет выводиться на экран - Hello World! или Good bye World!
Далее необходимо изменить модель yoursite.ru/components/com_helloworld/models/helloworld.php

<?php
// No direct access to this file
defined('_JEXEC') or die('Restricted access');
 
// import Joomla modelitem library
jimport('joomla.application.component.modelitem');
 
/**
 * HelloWorld Model
 */
class HelloWorldModelHelloWorld extends JModelItem
{
        //определяем строковую переменную
        protected $msg;
 
        //метод для показа сообщения
        public function getMsg() 
        {
                if (!isset($this->msg)) 
                {
                        $id = JRequest::getInt('id'); //вытаскиваем параметр id из запроса
                        switch ($id) 
                        {
                        case 2:
                                $this->msg = 'Good bye World!';
                        break;
                        default:
                        case 1:
                                $this->msg = 'Hello World!';
                        break;
                        }
                }
                return $this->msg;
        }
}


Также необходимо сделать изменения в helloworld.xml

<?xml version="1.0" encoding="utf-8"?>
<extension type="component" version="1.6.0" method="upgrade">
 
        <name>Hello World!</name>
        <!-- The following elements are optional and free of formatting conttraints -->
        <creationDate>November 2009</creationDate>
        <author>John Doe</author>
        <authorUrl>http://www.example.org</authorUrl>
        <copyright>Copyright Info</copyright>
        <license>License Info</license>
        <!--  The version string is recorded in the components table -->
        <version>0.0.5</version>
        <!-- The description is optional and defaults to the name -->
        <description>Description of the Hello World component ...</description>
 
        <update> <!-- Runs on update; New in 1.6 -->
                <schemas>
                        <schemapath type="mysql">sql/updates/mysql</schemapath>
                </schemas>
        </update>
 
        <!-- Site Main File Copy Section -->
        <!-- Note the folder attribute: This attribute describes the folder
                to copy FROM in the package to install therefore files copied
                in this section are copied from /site/ in the package -->
        <files folder="site">
                <filename>index.html</filename>
                <filename>helloworld.php</filename>
                <filename>controller.php</filename>
                <folder>views</folder>
                <folder>models</folder>
        </files>
 
        <administration>
                <!-- Administration Menu Section -->
                <menu>Hello World!</menu>
                <!-- Administration Main File Copy Section -->
                <!-- Note the folder attribute: This attribute describes the folder
                        to copy FROM in the package to install therefore files copied
                        in this section are copied from /admin/ in the package -->
                <files folder="admin">
                        <!-- Admin Main File Copy Section -->
                        <filename>index.html</filename>
                        <filename>helloworld.php</filename>
                        <!-- SQL files section -->
                        <folder>sql</folder>
                </files>
        </administration>
 
</extension>



Установочный пакет

    * helloworld.xml
    * site/index.html
    * site/helloworld.php
    * site/controller.php
    * site/views/index.html
    * site/views/helloworld/index.html
    * site/views/helloworld/view.html.php
    * site/views/helloworld/tmpl/index.html
    * site/views/helloworld/tmpl/default.xml
    * site/views/helloworld/tmpl/default.php
    * site/models/index.html
    * site/models/helloworld.php
    * admin/index.html
    * admin/helloworld.php
    * admin/sql/index.html
    * admin/sql/updates/index.html
    * admin/sql/updates/mysql/index.html
    * admin/sql/updates/mysql/0.0.1.sql

Создайте установочний файл ZIP или загрузите пакет Установите его с помощью менеджера расширений Joomla!1.6.

Для проверки введите yoursite.ru/index.php?option=com_helloworld&id=1 и yoursite.ru/index.php?option=com_helloworld&id=2

Следующая статья будет посвящена использованиб БД при разработек расширений Joomla! 1.6

<?php
// No direct access to this file
defined('_JEXEC') or die('Restricted access');

// import Joomla modelitem library
jimport('joomla.application.component.modelitem');

/**
* HelloWorld Model
*/

class HelloWorldModelHelloWorld extends JModelItem
{
/**
* @var string msg
*/

protected $msg;

/**
* Get the message
* @return string The message to be displayed to the user
*/

public function getMsg()
{
if (!isset($this->msg))
{
$id = JRequest::getInt('id');
switch ($id)
{
case 2:
$this->msg = 'Good bye World!';
break;
default:
case 1:
$this->msg = 'Hello World!';
break;
}
}
return $this->msg;
}
}

Добавить комментарий


Защитный код
Обновить


Есть что почитать

API Joomla! на русском - JDocument/setMetaData
Устанавливает значение эллементов метаданных сайта Joomla!.Синтаксисvoid setMetaData( $name, $content, $http-equiv
Создание сайта-визитки для магазина "Инструмент"
Регистрация доменного имени benzopila22.ru; Разработка эксклюзивного дизайна в соответствии с
Правильное подключение файлов Javascript и CSS к шаблону Joomla
Чтобы иметь правильно построенный документ XHTML, Вы должны поместить все
Класс JFactory
Часто при разработке сайтов на Joomla! мы используем класс JFactory.
Создание сайта для компании "Авантаж" г.Новосибирск
Сайт на домене www.tent-sib.ru; Разработка эксклюзивного дизайна для компании, занимающейся