Hallo zusammen.
Ich habe eine Komponente programmiert, mit der jeder User Charaktere für ein Rollenspiel hinzufügen kann. Nun möchte ich erreichen, dass die jeweilige BenutzerID ebenfalls in die Datenbank geschrieben wird, so, dass ich später die Charaktere im Zusammenhang des Users ausgeben kann. Das habe ich folgendermassen versucht:
Controller
PHP-Code:<?php
defined( '_JEXEC' ) or die( 'Restricted access' );
jimport('joomla.application.component.controller');
class GwcharsController extends JController {
function display() {
parent::display();
}
function __construct() {
parent::__construct();
$this->registerTask( 'add', 'edit' );
}
function edit() {
JRequest::setVar( 'view', 'addgwchar' );
JRequest::setVar( 'layout', 'form' );
JRequest::setVar( 'hidemainmenu', 1 );
parent::display();
}
function save() {
$model = $this->getModel('addgwchar');
if ($model->store()) {
$msg = JText::_( 'Character Saved' );
} else {
$msg = JText::_( 'Error Saving' ) . ': ' . $model->getError();
}
$this->setRedirect( 'index.php?option=com_gwchars&view=addgwchars',
$msg);
return false;
}
function remove() {
$model = $this->getModel('addgwchar');
if($model->delete()) {
$msg = JText::_( 'Character Deleted' );
} else {
$msg = JText::_( 'Error Deleting' );
}
$this->setRedirect( 'index.php?option=com_gwchars&view=addgwchars',
$msg );
}
function cancel() {
$msg = JText::_( 'Canceled' );
$this->setRedirect( 'index.php?option=com_gwchars&view=addgwchars',
$msg );
}
}
?>
model
TemplatePHP-Code:<?php
defined('_JEXEC') or die('Restriced Access');
jimport('joomla.application.component.model');
class GwcharsModelAddgwchar extends JModel {
function __construct() {
parent::__construct();
$array = JRequest::getVar('cid', 0, '', 'array');
$this->setId($array[0]);
}
function setId($id) {
$this->_id = $id;
$this->_data = null;
}
function getData() {
if (empty( $this->_data )) {
$query = ' SELECT * FROM #__gwchars '.
' WHERE id = '.$this->_id;
$this->_db->setQuery( $query );
$this->_data = $this->_db->loadObject();
}
if (!$this->_data) {
$this->_data = new stdClass();
$this->_data->id = 0;
$this->_data->name = null;
$this->_data->gender = null;
$this->_data->race = null;
$this->_data->profession = null;
$this->_data->published = null;
/*UserID*/
$this->_data->user = null;
}
return $this->_data;
}
function store() {
$row =& $this->getTable(gwchar);
$data = JRequest::get( 'post' );
if (!$row->bind($data)) {
$this->setError($this->getError());
return false;
}
if (!$row->check()) {
$this->setError($this->getError());
return false;
}
if (!$row->store()) {
$this->setError( $row->_db->getErrorMsg() );
return false;
}
return true;
}
function delete() {
$cids = JRequest::getVar( 'cid', array(0),
'post', 'array' );
$row =& $this->getTable(gwchar);
if (count( $cids )) {
foreach($cids as $cid) {
if (!$row->delete( $cid )) {
$this->setError( $row->getErrorMsg() );
return false;
}
}
}
return true;
}
}
?>
Leider funktioniert es nicht wie gewünscht. Die UserID wird nicht eingetragen. Kann mir da jemand auf die Sprünge helfen?PHP-Code:<!-- userID -->
<input type="hidden" name="user" value="<?php echo $this->addgwchar->user; ?>" />
<input type="hidden" name="task" value="save" />
<input type="submit" name="Absenden" class="button validate" />
Danke schon im Voraus


LinkBack URL
About LinkBacks
Zitieren

Lesezeichen