2010-09-15 6 views

Répondre

4

Obtenir le modèle est assez facile. Incluez simplement le fichier PHP du modèle dans le code du plug-in et créez vos objets selon vos besoins.

Il est préférable de gérer toutes les manipulations de table dans le modèle, mais il existe des moyens de charger la table dans le plug-in lui-même.

Voici comment vous chargez le modèle du plug-in:

<?php 

// Path to component 
$componentPath = JPATH_ADMINISTRATOR . DS . 'components' . DS . 'mycomponent'; 

// Include model 
require_once $componentPath . DS . 'models' . DS . 'example.php'; 

// You need to specify table_path because by default model uses 
// JPATH_COMPONENT_ADMINISTRATOR . DS . 'tables' 
// and you will not have correct JPATH_COMPONENT_ADMINISTRATOR in the plu-in 
// unless you specify it in config array and pass it to constructor 
$config = array(
    'table_path' => $componentPath . DS . 'tables' 
); 

// Create instance 
$model = new MycomponentModelExample($config); 

?> 

Voici comment vous chargez la table du plug-in:

<?php 

// 1. Add the path so getInstance know where to find the table 
$tablePath = JPATH_ADMINISTRATOR . DS . 'components' . DS . 'mycomponent' . DS . 'tables'; 
JTable::addIncludePath($tablePath); 

// 2. Create instance of the table 
$tbl = JTable::getInstance('tableName', 'Table'); 

?> 
Questions connexes