PDA

Zobacz pełną wersję : Zapis zmian (edycja/update).



GrzesiekP
24-10-2010, 20:50
Najpierw poszczególne pliki:

controller.php


<?php
/*
* @Package: com_blank.
* @Blank component
* @Author: Wojciech Romanek
* @Author e-mail: admin@wromanek.info
* @Author website: http://www.wromanek.info
* If you want to publish this package on your site you should pleace authors website url witch you can find above.
* You can modify or do what ever you want with this file
*/
defined ('_JEXEC') or die('Restricted access');
jimport('joomla.application.component.controller') ;

class AA3ToolsController extends JController
{

function __construct($config = array())
{
parent::__construct($config);
}

function display()
{
if ( ! JRequest::getVar( 'view' ) ) {
JRequest::setVar('view', 'bans' );
}

parent::display();
}

function remove()
{
global $mainframe;
JTable::addIncludePath(JPATH_ADMINISTRATOR.DS.'com ponents'.DS.'com_aa3tools'.DS.'tables');
$row =& JTable::getInstance('bans', 'Table');
$id = JRequest::getVar('cid');
$num = 0;
foreach ($id as $bid)
{
$row->delete($bid);
$num += 1;
}
$mainframe->redirect('index.php?option=com_aa3tools', 'Usuniętych: '.$num);
}


function addBan()
{
global $mainframe;
$mainframe->redirect('index.php?option=com_aa3tools&view=banform');
}

function edit()
{
$id = JRequest::getVar('cid');
global $mainframe;
$mainframe->redirect('index.php?option=com_aa3tools&view=banform&cid='.$id['0']);
}


function save()
{
$option = JRequest::getCmd('option');
$this->setRedirect('index.php?option=' . $option);

$post = JRequest::get('post');
JTable::addIncludePath(JPATH_ADMINISTRATOR.DS.'com ponents'.DS.'com_aa3tools'.DS.'tables');
$row =& JTable::getInstance('bans', 'Table');

if (!$row->bind($post)) {
return JError::raiseWarning(500, $row->getError());
}

if (!$row->store()) {
return JError::raiseWarning(500, $row->getError());
}

$this->setMessage('Zapisano pomyślnie!');
}
}
?>


view.html.php (banform view)

<?php
/*
* @Package: com_blank.
* @Blank component
* @Author: Wojciech Romanek
* @Author e-mail: admin@wromanek.info
* @Author website: http://www.wromanek.info
* If you want to publish this package on your site you should pleace authors website url witch you can find above.
* You can modify or do what ever you want with this file
*/
defined( '_JEXEC' ) or die( 'Restricted access' );

jimport( 'joomla.application.component.view');
JToolbarHelper::title('AA3 Tools - Dodaj bana');
JToolbarHelper::save('save');
JToolBarHelper::cancel();


class AA3ToolsViewBanForm extends JView
{
function display($tpl = null)
{
global $mainframe;
$model =& $this->getModel();
$this->getModel();
JRequest::setVar( 'hidemainmenu', 1 );

$cid= JRequest::getVar('cid');
JTable::addIncludePath(JPATH_ADMINISTRATOR.DS.'com ponents'.DS.'com_aa3tools'.DS.'tables');
$row =& JTable::getInstance('bans', 'Table');

if (isset($cid)) {
$row->load($cid);
}

$this->assignRef('rowban', $row);

parent::display($tpl);
}
}
?>

default.php (banform view)



<?php
defined('_JEXEC') or die('Restricted access');
?>

<script language="javascript" type="text/javascript">
function submitbutton(pressbutton) {
var form = document.adminForm;
if (pressbutton == 'cancel') {
submitform( pressbutton );
return;
}

// do field validation
if (form.soldiername.value == ""){
alert( "<?php echo JText::_('ALERT_ENTER_SOLDIER_NAME'); ?>" );
} else if (form.reason.value == "0"){
alert( "<?php echo JText::_('ALERT_ENTER_REASON'); ?>" );
} else {
submitform( pressbutton );
}
}
</script>


<?php echo($this->rowban->id); ?>
<form action="index.php" method="post" name="adminForm">
<table>
<tr>
<td><?php echo JText::_('SOLDIER_NAME') ?>:</td>
<td><input type="text" width="120" name="soldiername" value="<?php echo($this->rowban->soldiername); ?>"></td>
</tr>
<tr>
<td><?php echo JText::_('BAN_REASON') ?>:</td>
<td><select name="reason">
<option value="1">Cheater</option>
<option value="2">Culture</option>
<option value="3">Enemy</option>
<option value="4">Pinger</option>
</select></td>
</tr>
</table>
<input type="hidden" name="cid[]" value="<?php echo($this->rowban->id); ?>" />
<input type="hidden" name="option" value="com_aa3tools" />
<input type="hidden" name="task" value="" />
</form>

Jestem zielony w te klocki i dopiero zgłębiam tajniki zarówno PHP jak i pisania komponentów pod Joomle.

To jest część prostego komponentu - tabelki z banami. Dodawanie działa, usuwanie także. Nie mogę jednak zapisać zmian przy edycji - nie wiem dlaczego. Zamiast zapisywać (update) dodaje nowy rekord.

Ktoś pomoże?

EDIT

Wystarczyło zamienić:

<input type="hidden" name="cid[]" value="<?php echo($this->rowban->id); ?>" />
na:

<input type="hidden" name="id" value="<?php echo($this->rowban->id); ?>" />

I działa :-)

Myślałem, że spróbowałem wszystkiego, ale jak zwykle dopiero po napisaniu posta z prośbą o pomoc, udaje mi się rozwiązać problem samemu :-)

Żeby jednak wykorzystać już mój tekst -> na ile poprawny jest ten kod sklecony przeze mnie?
Pisałem dotychczas w VB pod ASP.Net, więc przesiadka na PHP jest dla mnie czymś hardkorowym :-P

salon
30-03-2011, 16:05
gdzie znalezc odpowiedni plik default.php ???