Joomla.it Forum
Non solo Joomla... => Sviluppo => : EremitaDeiMonti 05 May 2011, 16:12:10
-
Salve a tutti.Sto cercando di realizzare un componente i joomla per la gestione degli stage.
L'unica cosa è che non riesco a salvare i record nel db
Questo è il codice del controller presente nella cartella admin.
class StagesController extends JController
{
/**
* Method to display the view
*
* @access public
*/
function display()
{
//prendo l'azione dal task
$azione =JRequest::getVar('task');
$controller=JRequest::getVar('controller');
/*$controller=JRequest::getVar('controller');
$task =JRequest::getVar('task');
$view =JRequest::getVar('view');
echo $controller.'/'.$task.'/'.$view;
$mainframe->close();*/
//imposto quella di default
if($azione==null)
{
$azione='stagess';
}
//divido l'azione(x quando deve compiere funzioni di modifica/eliminazione/aggiunta record
$stringa=".";
$vet=explode($stringa,$azione);
$vista=$vet[0];
$task=$vet[1];
//se il task è uno di modifica record eseguo la parte dell'if
if($task=='add' || $task=='edit'|| $task=='save'|| $task=='cancel'||$task=='remove')
{
//$mainframe->close();
//$controller=JRequest::getVar($vista);
$controller=JRequest::getVar('controller');
echo 'AZIONE'.$azione.'/VISTA='.$vista.'/TASK='.$task.'/CONTOLLER='.$controller."<br></br>";
//imposto la vista
JRequest::setVar( 'view', $vista);
//imposto il layout
JRequest::setVar( 'layout', $vista );
//imposto il menu
//JRequest::setVar('hidemainmenu', 1);
}
else
{
//imposto la vista
JRequest::setVar( 'view', $vista);
//imposto il layout
JRequest::setVar( 'layout', $vista );
//imposto il menu
//JRequest::setVar('hidemainmenu', 1);
}
//echo $vista.'pippo'.$task;
//$mainframe->close();
/*visualizzazione*/
//parent::display($vista);
parent::display();
}
}
Mi potete aiutare.???
-
http://docs.joomla.org/How_to_use_the_database_classes_in_your_script
...cmq nn vedo il model nel tuo controller e presumo tu non abbia previsto l'uso del CRUD (che non è prosciutto :) ) prevedendo una cartella "tables"...
non è obbligatorio ma devi comunque appoggiarti al model e fare tutti i check prima dell'inserimento,...prevedere i setRedirect sugli errori etc...
M.
-
ma l'ho messa anche una cartella "tables" dove ci sono i file x ogni tabella che utilizzo e dove dichiaro i campi di ogni tabella.....
-
Aggiungo anche i codici del model
file alunnis.php
class StagesModelAlunnis extends JModel
{
/**
* ARRAY
*/
var $_alunni;
/**
* imposto la query
*/
function _buildQuery($table)
{
$query = ' SELECT * '
. ' FROM '.$table;
return $query;
}
/**
* Recupero dei dati
* @return array Array of objects containing the data from the database
*/
function getAlunni()
{
// ricarico i dati
if (empty( $this->_alunni ))
{
$query = $this->_buildQuery('#__Alunni');
$this->_alunni = $this->_getList( $query );
}
return $this->_alunni;
}
}
e il file alunni.php
class StagesModelAlunni extends JModel
{
/**
* Constructor that retrieves the ID from the request
*
* @access public
* @return void
*/
function __construct()
{
parent::__construct();
$array = JRequest::getVar('cid', 0, '', 'array');
$this->setId((int)$array[0]);
}
/**
* Method to set the Alunni identifier
*
* @access public
* @param int Alunni identifier
* @return void
*/
function setId($CodAlu)
{
// Set id and wipe data
$this->_CodAlu = $CodAlu;
$this->_alunni= null;
}
/**
* Method to get Alunni
* @return object with data
*/
function &getAlunni()
{
// Load the data
if (empty( $this->_alunni )) {
$query = ' SELECT * FROM #__Alunni '.
' WHERE CodAlu = '.$this->_CodAlu;
$this->_db->setQuery( $query );
$this->_alunni = $this->_db->loadObject();
}
if (!$this->_alunni) {
$this->_alunni= new stdClass();
$this->_alunnI->CodAlu = 0;
$this->_alunni->CodCl = 0;
$this->_alunni->Nome = null;
$this->_alunni->Cogn = null;
$this->_alunni->DataNa = null;
$this->_alunni->Via = null;
$this->_alunni->Loc = null;
$this->_alunni->Prov = null;
$this->_alunni->NumTel = null;
$this->_alunni->NumCell = null;
$this->_alunni->Mail = null;
}
return $this->_alunni;
}
/**
* Method to store a record
*
* @access public
* @return boolean True on success
*/
function store()
{
$row =& $this->getTable('alunni');
$data = JRequest::get( 'post' );
// Bind the form fields to the hello table
if (!$row->bind($data))
{
//JError::raiseError(500, 'Error binding data');
$this->setError($this->_db->getErrorMsg());
return false;
}
// Make sure the hello record is valid
if (!$row->check())
{
$this->setError($this->_db->getErrorMsg());
return false;
}
// Store the web link table to the database
if (!$row->store())
{
$this->setError( $row->getErrorMsg() );
return false;
}
return true;
}
/**
* Method to delete record(s)
*
* @access public
* @return boolean True on success
*/
function delete()
{
$cids = JRequest::getVar( 'cid', array(0), 'post', 'array' );
$row =& $this->getTable('Alunni');
if (count( $cids )) {
foreach($cids as $cid) {
if (!$row->delete( $cid )) {
$this->setError( $row->getErrorMsg() );
return false;
}
}
}
return true;
}
}
boh non capisco xkè alunnis.php riesce ad eseguirmelo correttamente.mentre la delete() e la store() contenute in alunni.php non le fa....:-(
-
se puoi potresti guardarmi il codice del mio componente
http://www.megaupload.com/?d=PT45IG6U
(http://www.megaupload.com/?d=PT45IG6U)
magari riesci a darmi una dritta di come riuscire a salvare i record...
-
Salve a tutti.Sto cercando di realizzare un componente i joomla per la gestione degli stage.
L'unica cosa è che non riesco a salvare i record nel db
Questo è il codice del controller presente nella cartella admin.
class StagesController extends JController
{
/**
* Method to display the view
*
* @access public
*/
function display()
{
//prendo l'azione dal task
$azione =JRequest::getVar('task');
$controller=JRequest::getVar('controller');
/*$controller=JRequest::getVar('controller');
$task =JRequest::getVar('task');
$view =JRequest::getVar('view');
echo $controller.'/'.$task.'/'.$view;
$mainframe->close();*/
//imposto quella di default
if($azione==null)
{
$azione='stagess';
}
//divido l'azione(x quando deve compiere funzioni di modifica/eliminazione/aggiunta record
$stringa=".";
$vet=explode($stringa,$azione);
$vista=$vet[0];
$task=$vet[1];
//se il task è uno di modifica record eseguo la parte dell'if
if($task=='add' || $task=='edit'|| $task=='save'|| $task=='cancel'||$task=='remove')
{
//$mainframe->close();
//$controller=JRequest::getVar($vista);
$controller=JRequest::getVar('controller');
echo 'AZIONE'.$azione.'/VISTA='.$vista.'/TASK='.$task.'/CONTOLLER='.$controller."<br></br>";
//imposto la vista
JRequest::setVar( 'view', $vista);
//imposto il layout
JRequest::setVar( 'layout', $vista );
//imposto il menu
//JRequest::setVar('hidemainmenu', 1);
}
else
{
//imposto la vista
JRequest::setVar( 'view', $vista);
//imposto il layout
JRequest::setVar( 'layout', $vista );
//imposto il menu
//JRequest::setVar('hidemainmenu', 1);
}
//echo $vista.'pippo'.$task;
//$mainframe->close();
/*visualizzazione*/
//parent::display($vista);
parent::display();
}
}
Mi potete aiutare.???