Problem s nacitanim dat z databazy

cujan
Člen | 410
+
0
-

Zdravim mam problem s nacitanim dat z datbazy, napriek tomu, ze pripojenie urcite funguje, lebo prihlasovanie v aplikacii mi funguje

BaseManager

<?php
<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

namespace App\Model;

use Nette,
    Nette\Database\Context,
    Nette\Object;

/**
 * Description of BaseManager
 *
 * @author Holub
 */
abstract class BaseManager extends Object
{

    /** @var Nette\Database\Context */
    protected $database;


    public function __construct(Context $database)
    {
	$this->database = $database;

    }
}

?>

UsersManager

<?php
<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

namespace App\Model;

use Nette;

/**
 * Description of UsersManager
 *
 * @author Holub
 */
class UsersManager extends BaseManager {
    /**Konstanty pre manipulaciu s modelom*/
    const TABLE_NAME = 'users';



    /**
     * return all rocords from database
     * @return Selection   record list
     */

    public function getRecords()
    {
	return $this->database->table(self::TABLE_NAME);
    }

    /**
     * return record by id
     * @return Slection record
     */

    public function getRecordById($id)
    {
	return $this->getRecords()->getId($id);
    }

}

?>

UserProfilePresenter

<?php
<?php
<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

namespace App\Presenters;

use Nette,
	Nette\Database\Context;

use App\Model\UsersManager;

/**
 * Description of UserProfilePresenter
 *
 * @author Holub
 */
class UserProfilePresenter extends BasePresenter{

    /** @var UsersManager Instance třídy modelu pro práci s články. */
    protected $usersManager;

    public function __construct(UsersManager $usersManager) {
	parent::__construct();
	$this->usersManager = $usersManager;
    }

    public function actionDefault()
    {

	$this->template->records = $this->usersManager->getRecords();

    }
}


?>

Editoval cujan (10. 11. 2017 10:17)

CZechBoY
Člen | 3608
+
0
-

Metoda getId neexistuje ve tride Selection. Pouzij wherePrimary. Jestli chces vratit konkretni radek tak zavolej jeste ->fetch().

cujan
Člen | 410
+
0
-

CZechBoY napsal(a):

Metoda getId neexistuje ve tride Selection. Pouzij wherePrimary. Jestli chces vratit konkretni radek tak zavolej jeste ->fetch().

ale mne nevrati nic ani getRecords()

jiri.pudil
Nette Blogger | 1028
+
0
-

ale mne nevrati nic ani getRecords()

To, že ti v té metodě chybí return, vzniklo až při přepisu do fóra?

cujan
Člen | 410
+
0
-

jiri.pudil napsal(a):

ale mne nevrati nic ani getRecords()

To, že ti v té metodě chybí return, vzniklo až při přepisu do fóra?

ano je to iba v prepise…uz som to upravil…

Editoval cujan (10. 11. 2017 10:19)

jura2.0
Člen | 8
+
0
-

cujan napsal(a):

CZechBoY napsal(a):

Metoda getId neexistuje ve tride Selection. Pouzij wherePrimary. Jestli chces vratit konkretni radek tak zavolej jeste ->fetch().

ale mne nevrati nic ani getRecords()

tak zkus třeba bdump(getRecords()) nejlíp přímo v UsersManager… nemůže to vrátit ‚nic‘, buď to vyhodí error nebo nějaký výsledek… podle toho pak pokračuj. Každopádně kromě toho uprav kód, tak jak psal CZechBoY nebo třeba takto

public function getRecordById($id)
{
return $this->database->table(self::TABLE_NAME)->get($id);
}

stejně jako fetch() ti tohle vrátí ActiveRow, se kterým už můžeš pracovat v latte i v nette jako s objektem, např. $record->name