PDA

Zobacz pełną wersję : ControllerBase problem z task 'kontroler.save'



seeb
17-05-2016, 15:36
Witam!

Mam problem związany z porzuceniem trybu legacy.

struktura:


models
default.php
profil.php
controllers
profil.php
views
profil
tmpl
default.php
html.php

plik views/profil/tmpl/default.php

<h3>Profil płatnika</h3>
<form action="<?php echo JRoute::_('index.php?option=com_test&view=profil'); ?>" method="post" name="adminForm" id="adminForm" class="form-validate form-horizontal"> <table>
<tr><td>ID:</td> <td><input type="text" name="id" value="<?php echo $this->profil->id;/* id profilu */?>" disabled="disabled" /></td></tr>
<tr><td>UID:</td> <td><?php echo $this->profil->userid; /* id wlasciciela profilu z Joomla! */?></td></tr>
<tr><td>NIP:</td> <td><input type="text" name="nip" value="<?php echo $this->profil->nip;?>" /></td></tr> <tr><td>Nazwa:</td> <td><input type="text" name="nazwa" value="<?php echo $this->profil->nazwa; ?>" /></td></tr>
<tr><td>Adres:</td> <td><input type="text" name="adres" value="<?php echo $this->profil->adres;?>" ></td></tr>
<tr><td>Kod:</td> <td><input type="text" name="kod" value="<?php echo $this->profil->kod;?>" /></td></tr>
<tr><td>REGON:</td> <td><input type="text" name="regon" value="<?php echo $this->profil->regon;?>" /></td></tr>
<tr><td>Nazwa banku:</td> <td><input type="text" name="bank" value="<?php echo $this->profil->bank;?>" /></td></tr>
<tr><td>Nr konta:</td> <td><input type="text" name="konto" value="<?php echo $this->profil->konto; ?>" /></td></tr>
</table>
<input name="uid" type="hidden" value="<?php echo $this->profil->userid;?>" />
<input name="option" type="hidden" value="com_test" />
<input type="hidden" name="view" value="profil" />
<input type="hidden" name="task" value="" />
<?php echo JHtml::_('form.token'); ?>
</form>
plik views/profil/html.php

class TestViewsProfilHtml extends JViewHtml{
function render()
{
$app = JFactory::getApplication();
$model = new TestModelsProfil();
$this->profil = $model->getProfil();
$this->addToolbar();
return parent::render();
}
protected function addToolbar() {
...
if ($canDo->get('core.admin'))
{
JToolBarHelper::save('profil.save');
JToolBarHelper::cancel('cancel');
JToolbarHelper::preferences('com_test');
}// koniec if }// koniec addToolbar
}plik controllers/profil.php

class TestControllersProfil extends JControllerBase{
public function execute()
{
$app = $this->getApplication();
$document = JFactory::getDocument();
$viewName = $app->input->getWord('view', 'profil');
$viewFormat = $document->getType();
$layoutName = $app->input->getWord('layout', 'default');
$app->input->set('view', $viewName);

// Register the layout paths for the view
$paths = new SplPriorityQueue;
$paths->insert(JPATH_COMPONENT . '/views/' . $viewName . '/tmpl', 'normal');

$viewClass = 'testViews' . ucfirst($viewName) . ucfirst($viewFormat);
$modelClass = 'testModels' . ucfirst($viewName);

$view = new $viewClass(new $modelClass, $paths);


$view->setLayout($layoutName);
// Render our view.
echo $view->render();

return true;
}

public function save ()
{
$app = JFactory::getApplication();
$result = 'Dane z modelu - celowo wyłączone do testów.';
$app->redirect('index.php?option=com_test&view=profil', $result);
} }

Niestety po zrzucie danych $_POST wszystkie dane zostają przesłane i wyświetlone var_dump($_POST) w default.php, natomiast nie ma reakcji kontrolera.

public function save ()
{
$app = JFactory::getApplication();
$result = 'Dane z modelu - celowo wyłączone do testów.';
var_dump($_POST);
exit ('controller');
$app->redirect('index.php?option=com_test&view=profil', $result);
}

Ktoś wie dlaczego tak się dzieje? W trybie legacy nie miałem takich problemów ale próbuję się rozstać definitywnie z kompatybilnością wsteczną na rzecz późniejszego rozwoju. Spodziewam się, że w Joomla 4.x Legacy będzie deprecated.