Есть база данных по имени u13461( в ней есть таблица result и 3 поля id,date,result)
Создаю файл модели results.php(В папке models)
Пишу тут
namespace app\models;
use yii\db\ActiveRecord;
class results extends ActiveRecord
{
const STATUS_INACTIVE = 0;
const STATUS_ACTIVE = 1;
/**
* @return string название таблицы, сопоставленной с этим ActiveRecord-классом.
*/
public static function tableName()
{
return 'result';
}
}
Далее в контролере SiteController пишу
use Yii;
use yii\filters\AccessControl;
use yii\web\Controller;
use yii\filters\VerbFilter;
use app\models\EntryForm;
use app\models\results;
class SiteController extends Controller
{
public function actionIndex()
{
$query = results::find()->all();
return $this->render('index', [
'query' => $query
]);
}
}
В views файле index.php пишу:
echo "<pre>";
print_r($query);
echo "</pre>";
В итоге, по мимо данных из базы я получаю еще куча данных в непонятной структуре и данные из базы дублируются.
Почему?
Вот что показывает:
Array
(
[0] => app\models\results Object
(
[_attributes:yii\db\BaseActiveRecord:private] => Array
(
[id] => 6
[date] =>
[result] => 0
)
[_oldAttributes:yii\db\BaseActiveRecord:private] => Array
(
[id] => 6
[date] =>
[result] => 0
)
[_related:yii\db\BaseActiveRecord:private] => Array
(
)
[_errors:yii\base\Model:private] =>
[_validators:yii\base\Model:private] =>
[_scenario:yii\base\Model:private] => default
[_events:yii\base\Component:private] => Array
(
)
[_behaviors:yii\base\Component:private] => Array
(
)
)
[1] => app\models\results Object
(
[_attributes:yii\db\BaseActiveRecord:private] => Array
(
[id] => 6
[date] =>
[result] => 0
)
[_oldAttributes:yii\db\BaseActiveRecord:private] => Array
(
[id] => 6
[date] =>
[result] => 0
)
[_related:yii\db\BaseActiveRecord:private] => Array
(
)
[_errors:yii\base\Model:private] =>
[_validators:yii\base\Model:private] =>
[_scenario:yii\base\Model:private] => default
[_events:yii\base\Component:private] => Array
(
)
[_behaviors:yii\base\Component:private] => Array
(
)
)
[2] => app\models\results Object
(
[_attributes:yii\db\BaseActiveRecord:private] => Array
(
[id] => 6
[date] =>
[result] => 0
)
[_oldAttributes:yii\db\BaseActiveRecord:private] => Array
(
[id] => 6
[date] =>
[result] => 0
)
[_related:yii\db\BaseActiveRecord:private] => Array
(
)
[_errors:yii\base\Model:private] =>
[_validators:yii\base\Model:private] =>
[_scenario:yii\base\Model:private] => default
[_events:yii\base\Component:private] => Array
(
)
[_behaviors:yii\base\Component:private] => Array
(
)
)
[3] => app\models\results Object
(
[_attributes:yii\db\BaseActiveRecord:private] => Array
(
[id] => 6
[date] =>
[result] => 0
)
[_oldAttributes:yii\db\BaseActiveRecord:private] => Array
(
[id] => 6
[date] =>
[result] => 0
)
[_related:yii\db\BaseActiveRecord:private] => Array
(
)
[_errors:yii\base\Model:private] =>
[_validators:yii\base\Model:private] =>
[_scenario:yii\base\Model:private] => default
[_events:yii\base\Component:private] => Array
(
)
[_behaviors:yii\base\Component:private] => Array
(
)
)
)