J3.x:تطوير مكون MVC/اضافة موديل الى قسم الموقع
From Joomla! Documentation
< J3.x:Developing an MVC Component
المقالات في هذه السلسلة
اضافة نمط قائمة الى جزء الموقع
اضافة موديل الى جزء الموقع
اضافة طلب متحول في نوع القائمة
استخدام قاعدة البيانات
واجهة خلفية بسيطة
اضافة ادارة لغة
اضافة أفعال في الواجهة الخلفية
اضافة ديكور الى الواجهة الخلفية
اضافة التحقيقات
اضافة فئات
اضافة اعداد
اضافة ملف سكريبت لتثبيت/فك تثبيت/تحديث
Adding a Frontend Form
استخدام ميزات تصفية اللغة
- Adding a Modal
- Adding Associations
- Adding Checkout
- Adding Ordering
- Adding Levels
- Adding Versioning
- Adding Tags
- Adding Access
- Adding a Batch Process
- Adding Cache
- Adding a Feed
اضافة مخدم تحديث
هذه سلسلة من عدة مقالات من الدروس حول كيفية تطوير موديل-عرض-موجه مكون لنسخة Joomla! .
تبدأ مع مقدمة, وتستعرض المقالات في هذه السلسلة باستخدام زر التنقل في الأسفل أو الصندوق الأيمن ("المقالات في هذه السلسلة").
ملاحظات
- هذا الدرس هو جزء من درس تطوير مكون MVC لـ Joomla! 3.x . نشجعك على قراءة الجزء السابق من الدرس قبل قراءة هذا الدرس.
- يمكنك اتباع الخطوات في الأسفل لإنشاء مكون Hello World!,أو يمكنك مباشرة تحميل الرابط archive
- You can watch a video associated with this step in the tutorial at Step 4, Adding a Model.
اضافة موديل الى 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 |
الرجاء انشاء طلب سحب أو مشكلة على https://github.com/joomla/Joomla-3.2-Hello-World-Component لأي اختلافات في الكود أو أي تعديل في شفرة المصدر على هذه الصفحة.