J3.x

J3.x:تطوير مكون MVC/اضافة موديل الى قسم الموقع

From Joomla! Documentation

< J3.x:Developing an MVC Component
This page is a translated version of the page J3.x:Developing an MVC Component/Adding a model to the site part and the translation is 85% complete.
Outdated translations are marked like this.
Other languages:
English • ‎Nederlands • ‎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.

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



ملاحظات

  • يمكنك اتباع الخطوات في الأسفل لإنشاء مكون Hello World!,أو يمكنك مباشرة تحميل الرابط archive

اضافة موديل الى Hello World!

في هذه المقالة سنغطي كيفية اضافة موديل الى مكون Joonla! البسيط. لهذا المثال سنتابع عملنا على مكون Hello World!

هنالك عدة طرق لتحديث مكون Joomla!. في هذا الدرس سنسلط الضوء على الخيار الثاني.

1 اضافة ملفات يدويا الى <path_to_joomla>/
2 التحديث باستخدام مدير مكون Joomla! والفهرس الأصلي، غير مضغوط، المستخدم لتثبيت المكون.
3 التحديث باستخدام مدير مكون Joomla! و مخدم التحديث

لاضافة عنصر قائمة يجب عليك الانتقال الى com_helloworld, والذي هو الفهرس الأصلي الذي أنشأناه لمكوننا. يجب عليك استخدام بنية الفهرس المحدث من آخر درس. باستخدام مدير الملف المفضل لديك، أنشئ أو حدث الملفات التالية ، وعند تعديل أو انشاء الملفات أضف شفرة المصدر لكل ملف موجود في File Details.

1 Create: helloworld.php <path_to_com_helloworld>/site/models/helloworld.php
2 Create: index.html <path_to_com_helloworld>/site/models/index.html
3 Update: view.html.php <path_to_com_helloworld>/site/views/helloworld/view.html.php
4 Update: helloworld.xml <path_to_com_helloworld>/helloworld.xml

تحديث مكون Hello World!

لتحديث مكون Hello World! الموجود في موقع Joomla!، الرجاء اتباع نفس الخطوات في التثبيت الأصلي.

تفاصيل الملف

site/models/helloworld.php

<?php
/**
 * @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
 */

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

/**
 * HelloWorld Model
 *
 * @since  0.0.1
 */
class HelloWorldModelHelloWorld extends JModelItem
{
	/**
	 * @var string message
	 */
	protected $message;

	/**
	 * Get the message
         *
	 * @return  string  The message to be displayed to the user
	 */
	public function getMsg()
	{
		if (!isset($this->message))
		{
			$this->message = 'Hello World!';
		}

		return $this->message;
	}
}

site/views/helloworld/view.html.php

<?php
/**
 * @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
 */

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

/**
 * HTML View class for the HelloWorld Component
 *
 * @since  0.0.1
 */
class HelloWorldViewHelloWorld extends JViewLegacy
{
	/**
	 * Display the Hello World view
	 *
	 * @param   string  $tpl  The name of the template file to parse; automatically searches through the template paths.
	 *
	 * @return  void
	 */
	function display($tpl = null)
	{
		// Assign data to the view
		$this->msg = $this->get('Msg');

		// Check for errors.
		if (count($errors = $this->get('Errors')))
		{
			JLog::add(implode('<br />', $errors), JLog::WARNING, 'jerror');

			return false;
		}

		// Display the view
		parent::display($tpl);
	}
}

helloworld.xml

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

	<name>Hello World!</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.4</version>
	<!-- The description is optional and defaults to the name -->
	<description>Description of the Hello World component ...</description>

	<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>

	<administration>
		<!-- Administration Menu Section -->
		<menu link='index.php?option=com_helloworld'>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.php

class HelloWorldModelHelloWorld extends JModelItem
{

هذ الصنف سيتم استدعائه من قبل الصنف HelloWorldViewHelloWorld.

view.html.php

$this->msg = $this->get('Msg');

إن الصنف HelloWorldViewHelloWorld يسأل الموديل عن البيانات التي تستخدم طريقة "get" لـ JViewLegacy.

محتويات المكون

في هذه النقطة من الدرس، المكون الخاص بك يجب أن يملك الملفات التالية:

1 helloworld.xml هذا ملف XML (manifest) والذي يخبر Joomla! عن كيفية تثبيت المكون الخاص بنا.
2 site/helloworld.php وهذا هو نقطة دخول الموقع الى مكون Hello World!
3 site/index.html منع مخدم الويب من عرض محتوى الفهرس
4 site/controller.php ملف يمثل الموجه
5 site/models/helloworld.php ملف يمثل الموديل
6 site/models/index.html منع مخدم الويب من عرض محتوى الفهرس
7 site/views/index.html منع مخدم الويب من عرض محتوى الفهرس
8 site/views/helloworld/index.html منع مخدم الويب من عرض محتوى الفهرس
9 site/views/helloworld/view.html.php ملف يمثل عرض
10 site/views/helloworld/tmpl/index.html منع مخدم الويب من عرض محتوى الفهرس
11 site/views/helloworld/tmpl/default.php عرض افتراضي
12 site/views/helloworld/tmpl/default.xml ملف يضيف عنصر قائمة
13 admin/index.html منع مخدم الويب من عرض محتوى الفهرس
14 admin/helloworld.php وهذا هو نقطة دخول المسؤول الى مكون Hello World!
15 admin/sql/index.html منع مخدم الويب من عرض محتوى الفهرس
16 admin/sql/updates/index.html منع مخدم الويب من عرض محتوى الفهرس
17 admin/sql/updates/mysql/index.html منع مخدم الويب من عرض محتوى الفهرس
18 admin/sql/updates/mysql/0.0.1.sql ملف يسمح لتهيئة اصدار مخطط مكون com_helloworld
Info non-talk.png
General Information

الرجاء انشاء طلب سحب أو مشكلة على https://github.com/joomla/Joomla-3.2-Hello-World-Component لأي اختلافات في الكود أو أي تعديل في شفرة المصدر على هذه الصفحة.