Problem pri prepojeni na databazu
Upozornění: Tohle vlákno je hodně staré a informace nemusí být platné pro současné Nette.
- cujan
- Člen | 410
caute skladam db aplikaciu podla prikladu cd-colection
a hadze mi nasledujucu chybu
Fatal Error
Call to a member function findAll() on a non-object search►
repository
<?php
namespace App\Model;
use Nette;
class PrijmyVydajeRepository extends Nette\Object
{
/** @var Nette\Database\Context */
private $database;
public function __construct(Nette\Database\Context $database)
{
$this->database = $database;
}
/** @return Nette\Database\Table\Selection */
public function findAll()
{
return $this->database->table('prijmyVydaje');
}
/** @return Nette\Database\Table\ActiveRow */
public function findById($id)
{
return $this->findAll()->get($id);
}
/** @return Nette\Database\Table\ActiveRow */
public function insert($values)
{
return $this->findAll()->insert($values);
}
}
presenter
<?php
namespace App\Presenters;
use App\Model,
Nette,
Nette\Application\UI\Form;
class EkonomikaPresenter extends BasePresenter {
/** @var Model\AlbumRepository */
private $prijmyvydaje;
public function _construct(Model\PrijmyVydajeRepository $prijmyvydaje) {
$this->prijmyvydaje = $prijmyvydaje;
}
/********************* view default *********************/
public function renderDefault()
{
$this->template->prijmyvydaje = $this->prijmyvydaje->findAll();
}
/**protected function createComponentGrid($name) {
$grid = new \Grido\Grid($this,$name);
$grid->translator->lang='sk';
$grid->setModel($this->prijmyvydaje);
$grid->addColumnDate('datum', 'Datum')->setDateFormat(\Grido\Components\Columns\Date::FORMAT_DATE)->setSortable();
$grid->addColumnText('popis', "Popis");
$grid->addColumnText('suma', "Suma")->setSortable();
$grid->addColumnText('identifikator', 'identifikator');
}*/
protected function createComponentPolozkaForm($name) {
$identifikatory = array('1'=>'prijem','-1'=>'vydaj');
$form = new Form;
$form->addRadioList('identifikator', 'transakcia', $identifikatory);
$form->addText('popis','Popis');
// $form->addText('datum','Datum');
$form->addDatePicker('datum', 'Datum:', 10, 10)->setRequired();
$form->addText('suma','Suma')->addRule(\Nette\Application\UI\Form::FLOAT,'Prosim vlozte cislo');
$form->addSubmit('send', 'Vloz transakciu');
$form->onSuccess[] = array($this, 'vlozitTransakciuFormSubmitted');
return $form;
}
public function vlozitTransakciuFormSubmitted($form) {
$values = $form->getValues();
dump($values);
$this->database->table('prijmyVydaje')->insert($values);
$this->redirect('Ekonomika:default');
}
}
- David Matějka
- Moderator | 6445
v nazvu konstruktoru v presenteru ti chybi jedno podtrzitko
_construct
⇒ __construct