J3.x:تطوير مكون MVC/اضافة ملف نصي للتثبيت-فك التثبيت-التحديث

Other languages:
English • ‎español • ‎français • ‎العربية • ‎中文(台灣)‎
Joomla! 
3.x
درس
تطوير مكون MVC

اضافة موديل الى جزء الموقع

اضافة طلب متحول في نوع القائمة

استخدام قاعدة البيانات

واجهة خلفية بسيطة

اضافة ادارة لغة

اضافة أفعال في الواجهة الخلفية

اضافة ديكور الى الواجهة الخلفية

اضافة التحقيقات

اضافة فئات

اضافة اعداد

  1. اضافة لائحة تحكم بالوصول ACL

اضافة ملف سكريبت لتثبيت/فك تثبيت/تحديث

Adding a Frontend Form

  1. Adding an Image
  2. Adding a Map
  3. Adding AJAX
  4. Adding an Alias

استخدام ميزات تصفية اللغة

  1. Adding a Modal
  2. Adding Associations
  3. Adding Checkout
  4. Adding Ordering
  5. Adding Levels
  6. Adding Versioning
  7. Adding Tags
  8. Adding Access
  9. Adding a Batch Process
  10. Adding Cache
  11. Adding a Feed

اضافة مخدم تحديث

  1. Adding Custom Fields
  2. Upgrading to Joomla4



هذه سلسلة من عدة مقالات من الدروس حول كيفية تطوير موديل-عرض-موجه مكون لنسخة Joomla! Joomla 3.x.

تبدأ مع مقدمة, وتستعرض المقالات في هذه السلسلة باستخدام زر التنقل في الأسفل أو الصندوق الأيمن ("المقالات في هذه السلسلة").



مقدمة

هذا الدرس هو جزء من درس تطوير مكون MVC لـ Joomla! 3.2 . نشجعك على قراءة الجزء السابق من الدرس قبل قراءة هذا الدرس.

You can watch a video associated with this step at Outline of Joomla Install Process.

انشاء ملف النصي للملحق

تثبيت ، فك تثبيت وتحديث المكون ربما يتطلب عمليات اضافية لايمكن الوصول لها في شرح العمليات الأساسية في ملف xml الرئيسي. تعرض جوملا مقاربة جديدة لحل هذه المشكلة . تتكون في استخدام ملف نصي php يحتوي على صنف يستخدم خمسة اجرائيات :

كتابة شفرة ملحق تتكون في التصريح عن الصنف والذي اسمه com_ComponentNameInstallerScript بهذه الاجرائيات الخمس.

script.php

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

/**
 * Script file of HelloWorld component.
 *
 * The name of this class is dependent on the component being installed.
 * The class name should have the component's name, directly followed by
 * the text InstallerScript (ex:. com_helloWorldInstallerScript).
 *
 * This class will be called by Joomla!'s installer, if specified in your component's
 * manifest file, and is used for custom automation actions in its installation process.
 *
 * In order to use this automation script, you should reference it in your component's
 * manifest file as follows:
 * <scriptfile>script.php</scriptfile>
 *
 * @package     Joomla.Administrator
 * @subpackage  com_helloworld
 *
 * @copyright   Copyright (C) 2005 - 2018 Open Source Matters, Inc. All rights reserved.
 * @license     GNU General Public License version 2 or later; see LICENSE.txt
 */
class com_helloWorldInstallerScript
{
    /**
     * This method is called after a component is installed.
     *
     * @param  \stdClass $parent - Parent object calling this method.
     *
     * @return void
     */
    public function install($parent) 
    {
        $parent->getParent()->setRedirectURL('index.php?option=com_helloworld');
    }

    /**
     * This method is called after a component is uninstalled.
     *
     * @param  \stdClass $parent - Parent object calling this method.
     *
     * @return void
     */
    public function uninstall($parent) 
    {
        echo '<p>' . JText::_('COM_HELLOWORLD_UNINSTALL_TEXT') . '</p>';
    }

    /**
     * This method is called after a component is updated.
     *
     * @param  \stdClass $parent - Parent object calling object.
     *
     * @return void
     */
    public function update($parent) 
    {
        echo '<p>' . JText::sprintf('COM_HELLOWORLD_UPDATE_TEXT', $parent->get('manifest')->version) . '</p>';
    }

    /**
     * Runs just before any installation action is performed on the component.
     * Verifications and pre-requisites should run in this function.
     *
     * @param  string    $type   - Type of PreFlight action. Possible values are:
     *                           - * install
     *                           - * update
     *                           - * discover_install
     * @param  \stdClass $parent - Parent object calling object.
     *
     * @return void
     */
    public function preflight($type, $parent) 
    {
        echo '<p>' . JText::_('COM_HELLOWORLD_PREFLIGHT_' . $type . '_TEXT') . '</p>';
    }

    /**
     * Runs right after any installation action is performed on the component.
     *
     * @param  string    $type   - Type of PostFlight action. Possible values are:
     *                           - * install
     *                           - * update
     *                           - * discover_install
     * @param  \stdClass $parent - Parent object calling object.
     *
     * @return void
     */
    function postflight($type, $parent) 
    {
        echo '<p>' . JText::_('COM_HELLOWORLD_POSTFLIGHT_' . $type . '_TEXT') . '</p>';
    }
}

وهذا الملف النصي سيعيد توجيه المستخدم الى مكون com_helloworld عندما يتم تثبيته وسيظهر الرسائل عند التحديث أو فك التثبيت. في اجرائية التحديث سنشاهد نشخة جديدة تستخدم $parent->get('manifest')->version.

اضافة بعض مفاتيح اللغة

admin/language/en-GB/en-GB.com_helloworld.sys.ini

; Joomla! Project
; Copyright (C) 2005 - 2018 Open Source Matters. All rights reserved.
; License GNU General Public License version 2 or later; see LICENSE.txt, see LICENSE.php
; Note : All ini files need to be saved as UTF-8

COM_HELLOWORLD="Hello World!"
COM_HELLOWORLD_DESCRIPTION="This is the Hello World description"
COM_HELLOWORLD_HELLOWORLD_VIEW_DEFAULT_TITLE="Hello World"
COM_HELLOWORLD_HELLOWORLD_VIEW_DEFAULT_DESC="This view displays a selected message"
COM_HELLOWORLD_INSTALL_TEXT="HelloWorld Install script"
COM_HELLOWORLD_MENU="Hello World!"
COM_HELLOWORLD_POSTFLIGHT_DISCOVER_INSTALL_TEXT="HelloWorld postflight discover install script"
COM_HELLOWORLD_POSTFLIGHT_INSTALL_TEXT="HelloWorld postflight install script"
COM_HELLOWORLD_POSTFLIGHT_UNINSTALL_TEXT="HelloWorld postflight uninstall script"
COM_HELLOWORLD_POSTFLIGHT_UPDATE_TEXT="HelloWorld postflight update script"
COM_HELLOWORLD_PREFLIGHT_DISCOVER_INSTALL_TEXT="HelloWorld preflight discover install script"
COM_HELLOWORLD_PREFLIGHT_INSTALL_TEXT="HelloWorld preflight install script"
COM_HELLOWORLD_PREFLIGHT_UNINSTALL_TEXT="HelloWorld preflight uninstall script"
COM_HELLOWORLD_PREFLIGHT_UPDATE_TEXT="HelloWorld preflight update script"
COM_HELLOWORLD_UNINSTALL_TEXT="HelloWorld Uninstall script"
COM_HELLOWORLD_UPDATE_TEXT="HelloWorld Update script. HelloWorld now updated to version %s."

"ملاحظة:" إذا كنت تريد لمفاتيح هذه اللغة أن تستخدم لأول مرة يتم فيها التثبيت للمكون، يجب حفظ ملف اللغة sys.ini في فهرس المكون (admin/language/en-GB/en-GB.com_helloworld.sys.ini), وملف التعريف xml يجب أن يحتوي وسم الفهرس لنسخ اللغة في فهرس المكون. عدل ملف التعريف حسب ذلك.

                <files folder="admin">
                        <!-- language folder -->
                        <folder>language</folder>
                </files>
 
                <languages folder="admin">
                        <language tag="en-GB">language/en-GB/en-GB.com_helloworld.ini</language>
                        <!-- com_helloworld.sys.ini no longer needed there-->
                </languages>

حزم المكون

محتوياات فهرس الشفرة الخاص بك

انشئ ملف مضغوط عن هذا الفهرس أو حمل مباشرة من archive وثبته باستخدام مدير الملحقات في Joomla!. بامكانك اضافة عنصر قائمة لهذا المكون باستخدام مدير القائمة في الخلفية.

helloworld.xml

<?xml version="1.0" encoding="utf-8"?>
<extension type="component" version="3.0" method="upgrade">

	<name>COM_HELLOWORLD</name>
	<!-- The following elements are optional and free of formatting constraints. -->
	<creationDate>January 2018</creationDate>
	<author>John Doe</author>
	<authorEmail>john.doe@example.org</authorEmail>
	<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.15</version>
	<!-- The description is optional and defaults to the name -->
	<description>COM_HELLOWORLD_DESCRIPTION</description>

	<!-- Runs on install/uninstall/update; New in 2.5 -->
	<scriptfile>script.php</scriptfile>

	<install> <!-- Runs on install -->
		<sql>
			<file driver="mysql" charset="utf8">sql/install.mysql.utf8.sql</file>
		</sql>
	</install>
	<uninstall> <!-- Runs on uninstall -->
		<sql>
			<file driver="mysql" charset="utf8">sql/uninstall.mysql.utf8.sql</file>
		</sql>
	</uninstall>
	<update> <!-- Runs on update; New since J2.5 -->
		<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>

        <languages folder="site/language">
		<language tag="en-GB">en-GB/en-GB.com_helloworld.ini</language>
        </languages>

	<media destination="com_helloworld" folder="media">
		<filename>index.html</filename>
		<folder>images</folder>
	</media>

	<administration>
		<!-- Administration Menu Section -->
		<menu link='index.php?option=com_helloworld' img="../media/com_helloworldhttps://docs.joomla.org/images/tux-16x16.png">COM_HELLOWORLD_MENU</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>config.xml</filename>
			<filename>helloworld.php</filename>
			<filename>controller.php</filename>
			<filename>access.xml</filename>
			<!-- SQL files section -->
			<folder>sql</folder>
			<!-- tables files section -->
			<folder>tables</folder>
			<!-- models files section -->
			<folder>models</folder>
			<!-- views files section -->
			<folder>views</folder>
			<!-- controllers files section -->
			<folder>controllers</folder>
			<!-- helpers files section -->
			<folder>helpers</folder>
		</files>
		<languages folder="admin/language">
        		<language tag="en-GB">en-GB/en-GB.com_helloworld.ini</language>
                        <language tag="en-GB">en-GB/en-GB.com_helloworld.sys.ini</language>
		</languages>
	</administration>

</extension>

المساهمين


Top