Componenti e parametri [SOLVED]

Moderator: alexred

Forum rules
Regole Forum
Locked
User avatar
prof3ta
Joomla! Intern
Joomla! Intern
Posts: 66
Joined: Wed Dec 26, 2007 12:01 pm
Location: Italy
Contact:

Componenti e parametri [SOLVED]

Post by prof3ta » Wed Jan 02, 2008 12:34 pm

Salve a tutti,
sto cercando di realizzare un componente per Joomla 1.5 il cui frontend prenda alcuni parametri dal pannello di amministrazione.
Nel file di installazione (com_mycomponent.xml) ho inserito:

Code: Select all

[...]
<administration>

  [...]

  <!-- Administration Main File Copy Section -->
  <files>
	<filename>config.xml</filename>
  </files>

  [...]


</administration>
<params>
</params>
[...]
Dove il file config.xml è fatto così:

Code: Select all

<?xml version="1.0" encoding="utf-8"?>
<config>
 <params>
  <param name="username" type="text" default="none" label="Username" description="Your Username" />
 </params>
</config>
Così facendo sono riuscito a far comparire la voce "Parameters - Component" all'interno della schermata di modifica delle preferenze del componente (lato amministrazione), ovvero quella che si apre quando, ad esempio, si aggiunge una voce ad un menu preesistente. Da li l'amministratore può modificare i parametri a piacimento.

Nel frontend faccio:

Code: Select all

$params = &$mainframe->getParams();
$username = $params->get('username');
echo "USERNAME IS: " . $username;
Ma Username risulta irrimediabilmente vuoto :(

Come vedete, nel file di installazione non ho specificato alcun parametro. Ho provato ad inserire i parametri direttamente li (escludendo il file config.xml). In questo caso, riesco ad accedere tranquillamente ai parametri dal frontend (Username ha il valore di default), ma non li vedo (e quindi non posso modificarli) nella schermata di amministrazione.
Qualche idea? Please... :)
Last edited by prof3ta on Wed Jan 02, 2008 2:14 pm, edited 1 time in total.

User avatar
Gianmarco Odorizzi
Joomla! Virtuoso
Joomla! Virtuoso
Posts: 3505
Joined: Wed Jun 14, 2006 12:54 pm
Location: Trento
Contact:

Re: Componenti e parametri

Post by Gianmarco Odorizzi » Wed Jan 02, 2008 12:41 pm

Ciao! Prova a vedere una soluzione alternativa, se ti puo' interessare :)

http://sviluppare.in.rete.googlepages.com/cconfig
It has been more than a long day, but Joomla has survived, and will continue to not just survive but grow even stronger.

ilox - 19 Aug 2007

User avatar
prof3ta
Joomla! Intern
Joomla! Intern
Posts: 66
Joined: Wed Dec 26, 2007 12:01 pm
Location: Italy
Contact:

Re: Componenti e parametri

Post by prof3ta » Wed Jan 02, 2008 12:47 pm

Uhm, la soluzione che mi hai proposto è per Joomla 1.0...
A me interessava capire il metodo che gli sviluppatori avevano pensato per il passaggio dei parametri-componente in Joomla 1.5 (cosa semplicissima, invece, per i moduli).

User avatar
Gianmarco Odorizzi
Joomla! Virtuoso
Joomla! Virtuoso
Posts: 3505
Joined: Wed Jun 14, 2006 12:54 pm
Location: Trento
Contact:

Re: Componenti e parametri

Post by Gianmarco Odorizzi » Wed Jan 02, 2008 1:57 pm

Sono interessato pure io, comuqnue quel componente lavora anche con Joomla 1.5 se adattato...io lo uso e va benissimo ;)
It has been more than a long day, but Joomla has survived, and will continue to not just survive but grow even stronger.

ilox - 19 Aug 2007

User avatar
prof3ta
Joomla! Intern
Joomla! Intern
Posts: 66
Joined: Wed Dec 26, 2007 12:01 pm
Location: Italy
Contact:

Re: Componenti e parametri

Post by prof3ta » Wed Jan 02, 2008 2:03 pm

Si, ma così devi scrivere esplicitamente il codice per gestire i parametri.
A me interessava invece recuperare nel frontend il valore dei parametri inseriti nel backend mediante i tag che Joomla già gestisce perfettamente...

User avatar
Gianmarco Odorizzi
Joomla! Virtuoso
Joomla! Virtuoso
Posts: 3505
Joined: Wed Jun 14, 2006 12:54 pm
Location: Trento
Contact:

Re: Componenti e parametri

Post by Gianmarco Odorizzi » Wed Jan 02, 2008 2:07 pm

Certo, è molto più comodo. Fammi sapere se risolvi :)
It has been more than a long day, but Joomla has survived, and will continue to not just survive but grow even stronger.

ilox - 19 Aug 2007

User avatar
prof3ta
Joomla! Intern
Joomla! Intern
Posts: 66
Joined: Wed Dec 26, 2007 12:01 pm
Location: Italy
Contact:

Re: Componenti e parametri

Post by prof3ta » Wed Jan 02, 2008 2:14 pm

Ok, fatto :p

Il segreto stava in una import :)

Basta fare, nel frontend:

jimport('joomla.application.component.helper');
$params = &JComponentHelper::getParams($option);
$username = $params->get('username');

E funge tutto... :p

User avatar
Gianmarco Odorizzi
Joomla! Virtuoso
Joomla! Virtuoso
Posts: 3505
Joined: Wed Jun 14, 2006 12:54 pm
Location: Trento
Contact:

Re: Componenti e parametri [SOLVED]

Post by Gianmarco Odorizzi » Wed Jan 02, 2008 2:31 pm

Bello! Pero' la configurazione è visibile a tutti, vero?
It has been more than a long day, but Joomla has survived, and will continue to not just survive but grow even stronger.

ilox - 19 Aug 2007

User avatar
prof3ta
Joomla! Intern
Joomla! Intern
Posts: 66
Joined: Wed Dec 26, 2007 12:01 pm
Location: Italy
Contact:

Re: Componenti e parametri [SOLVED]

Post by prof3ta » Wed Jan 02, 2008 5:59 pm

E perchè dovrebbe essere visibile a tutti? Viene fatta dal backend... No?

User avatar
Gianmarco Odorizzi
Joomla! Virtuoso
Joomla! Virtuoso
Posts: 3505
Joined: Wed Jun 14, 2006 12:54 pm
Location: Trento
Contact:

Re: Componenti e parametri [SOLVED]

Post by Gianmarco Odorizzi » Thu Jan 03, 2008 2:16 am

io dico il file config.xml :)
It has been more than a long day, but Joomla has survived, and will continue to not just survive but grow even stronger.

ilox - 19 Aug 2007

User avatar
prof3ta
Joomla! Intern
Joomla! Intern
Posts: 66
Joined: Wed Dec 26, 2007 12:01 pm
Location: Italy
Contact:

Re: Componenti e parametri [SOLVED]

Post by prof3ta » Thu Jan 03, 2008 7:59 am

Beh, ma quello contiene i parametri di default, che potrebbero anche essere messi a "NULL" :)

User avatar
Gianmarco Odorizzi
Joomla! Virtuoso
Joomla! Virtuoso
Posts: 3505
Joined: Wed Jun 14, 2006 12:54 pm
Location: Trento
Contact:

Re: Componenti e parametri [SOLVED]

Post by Gianmarco Odorizzi » Thu Jan 03, 2008 5:47 pm

Ah ok...scusa ma allora i parametri dove vengono salvati :) ?
It has been more than a long day, but Joomla has survived, and will continue to not just survive but grow even stronger.

ilox - 19 Aug 2007

GMassi
Joomla! Guru
Joomla! Guru
Posts: 675
Joined: Fri Jun 23, 2006 1:45 pm

Re: Componenti e parametri [SOLVED]

Post by GMassi » Mon Jan 07, 2008 12:28 pm

Gianmarco Odorizzi wrote: Ah ok...scusa ma allora i parametri dove vengono salvati :) ?
Nel campo params del record relativo al componente in jos_components  ;)

User avatar
Gianmarco Odorizzi
Joomla! Virtuoso
Joomla! Virtuoso
Posts: 3505
Joined: Wed Jun 14, 2006 12:54 pm
Location: Trento
Contact:

Re: Componenti e parametri [SOLVED]

Post by Gianmarco Odorizzi » Mon Jan 07, 2008 12:49 pm

Wow!!! Allora crdo sia più comodo rispetto alla classe che hai utilizzato nel componente cconfig

COrreggimi se sbalgio. Grazie :)
It has been more than a long day, but Joomla has survived, and will continue to not just survive but grow even stronger.

ilox - 19 Aug 2007

GMassi
Joomla! Guru
Joomla! Guru
Posts: 675
Joined: Fri Jun 23, 2006 1:45 pm

Re: Componenti e parametri [SOLVED]

Post by GMassi » Mon Jan 07, 2008 1:40 pm

Gianmarco Odorizzi wrote: Wow!!! Allora crdo sia più comodo rispetto alla classe che hai utilizzato nel componente cconfig
Quello era per la versione 1.0, con la 1.5 io fatto solo una prova veloce però credo tu possai fare tranquillamente in quest'altro modo.

User avatar
Gianmarco Odorizzi
Joomla! Virtuoso
Joomla! Virtuoso
Posts: 3505
Joined: Wed Jun 14, 2006 12:54 pm
Location: Trento
Contact:

Re: Componenti e parametri [SOLVED]

Post by Gianmarco Odorizzi » Mon Jan 07, 2008 3:51 pm

Grazie mille!!! :) Lo testero' il prima possibile :)

Ciao!
It has been more than a long day, but Joomla has survived, and will continue to not just survive but grow even stronger.

ilox - 19 Aug 2007


Locked

Return to “Joomla! 1.x”