كيفية استخدام هيكلية MVC المتواجدة في جملة

الجزء الثاني من سلسلة تعليم كيفية تطوير اضافة كومبونانت لمجلة جملة
و يتناول كيفية استخدام هيكلية MVC
Model
View
Controller

المتواجدة في مجلة جملة و سيكون التركيز الاكثر على الموديول و الفيو هذه المرة







كيفية عمل كومبونانت لمجلة جملة (2)
Uploaded by shalkam. - More lifestyle, fashion and how-to videos.



الاكواد المستخدمة:



أولا الموديل  

defined( '_JEXEC' ) or die( 'Restricted access' );

jimport( 'joomla.application.component.model' );
class AzozModelshowdata extends JModel {
function showdata() {
$db =& JFactory::getDBO();
//المثال المستخدم في الفيديو
//$query = 'SELECT * FROM #__sobi2_fields_data';
// يمكنك استخدام طلب قاعدة البيانات الذي يناسبك
$query = '/*طلب بلغة السيكويل*/';
$db->setQuery( $query );
$result = $db->loadObjectList();
return $result;
}
}



ثانيا : العرض  view


view.html.php


defined( '_JEXEC' ) or die( 'Restricted access' );

jimport( 'joomla.application.component.view' );
class AzozViewshowdata extends JView {
function display($tpl == null) {
$model = &$this->getModel();
$deta = $model->showdata();
$this->assignRef( 'data', $deta );
parent::display($tpl);
}
}
default.php

defined('_JEXEC') or die('Restricted access');
foreach ($this->data as $item) {
echo $item->data_txt;
}
ثالثا كود المتحكم controller




defined( '_JEXEC' ) or die( 'Restricted access' );

jimport('joomla.application.component.controller');

class AzozController extends JController
{
    function display()
    {
        parent::display();
    }

}
اخيرا الملف الرئيسي azoz.php



defined( '_JEXEC' ) or die( 'Restricted access' );

// Require the base controller
 require_once( JPATH_COMPONENT.DS.'controller.php' );

 // Create the controller
$controller   = new AzozController( );

// Perform the Request task
$controller->execute( JRequest::getWord( 'task' ) );

// Redirect if set by the controller
$controller->redirect();

0 التعليقات:

إرسال تعليق

عن المدونة

من أنا

مستخدم كمبيوتر عادي قرر أنه يتعلم برمجة مع نفسه و كل حاجة في مشوار التعلم دا هاشاركم بيه معايا هنا على المدونة

المتابعون

يتم التشغيل بواسطة Blogger.