Domanda

vorrei inserire un articolo all'interno del mio componente, Se qualcuno ha un esempio su come farlo?

L'articolo sarebbe selezionato dal backend.

È stato utile?

Soluzione

Nel back-end si selezionato l'articolo, l'ID di articolo verrà memorizzato in un database in params componenti (config.xml) o tabella params componente personalizzato.

In te componente personalizzato

  1. Conservare Articolo Id alla variabile
  2. Query la tabella del database #__content dell'articolo ID
  3. Visualizza l'articolo

Ad esempio

 //
 // Function for your model
 //
/**
 *
 * @return object 
 * 
 * Object will have following structure 
 * 
 * Field            Type    
 * ----------------------------------        
 * id               "int(11) unsigned"
 * title            varchar(255)
 * alias            varchar(255)
 * title_alias    varchar(255)
 * introtext        mediumtext
 * fulltext         mediumtext
 * state            tinyint(3)
 * sectionid        "int(11) unsigned"
 * mask             "int(11) unsigned"
 * catid            "int(11) unsigned"
 * created          datetime
 * created_by      "int(11) unsigned"
 * created_by_alias varchar(255)
 * modified         datetime
 * modified_by  "int(11) unsigned"
 * checked_out  "int(11) unsigned"
 * checked_out_time datetime
 * publish_up      datetime
 * publish_down  datetime
 * images           text
 * urls             text
 * attribs          text
 * version          "int(11) unsigned"
 * parentid         "int(11) unsigned"
 * ordering         int(11)
 * metakey          text
 * metadesc         text
 * access           "int(11) unsigned"
 * hits             "int(11) unsigned"
 * metadata         text
 */
 public function getMyArticle() {

        //  Get Component parameters (config.xml)
        $params = JComponentHelper::getParams('com_mycomponent');

        //  Get Specific parameter
        $myArticleId = (int) $params->get('articleId', 0);

        //  Make sure parameter is set and is greater than zero
        if ($myArticleId > 0) {

            //  Build Query
            $query = "SELECT * FROM #__content WHERE id = $myArticleId";

            //  Load query into an object
            $db = JFactory::getDBO();
            $db->setQuery($query);
            return $db->loadObject();
        }

        //
        return null;
    }

Per fare pop-up selezionate nel back-end, modificare config.xml del componente

add addpath agli elementi <params>

<!-- Add the path to content elements -->
<params addpath="/administrator/components/com_content/elements">
   <!-- Add Select Article param -->
   <param name="articleId" type="article" default="0" label="Select Article" description="" />

Sarà inoltre necessario aggiungere il pulsante alla barra degli strumenti config sulla visualizzazione predefinita del componente

// Add this code in the display() method of the view
// @todo change com_mycomponent to your component's name
JToolBarHelper::preferences('com_mycomponent')   
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top