I tried to add the query but now it returns me (no value) in all the columns. Below is the Sistop model and the index of the view. If I insert on SistopSearch the above query returns me (no value) on all the columns. I do not know what to think.
app\models\Sistop.php
namespace app\models;
use Da\User\Model\User;
use Yii;
use yii\db\Expression;
use yii\behaviors\TimestampBehavior;
use yii\behaviors\BlameableBehavior;
class Sistop extends \yii\db\ActiveRecord
{
public static function tableName()
{
return '{{%sistop}}';
}
public function behaviors()
{
return [
[
'class' => TimestampBehavior::className(),
'createdAtAttribute' => 'created_at',
'updatedAtAttribute' => 'updated_at',
'value' => new Expression('NOW()'),
],
[
'class' => BlameableBehavior::className(),
'createdByAttribute' => 'created_by',
'updatedByAttribute' => 'updated_by',
],
];
}
public function rules()
{
return [
[['qdsistop', 'qusistop'], 'integer'],
[['elencosistop'], 'string', 'max' => 255],
[['elencosistop'], 'unique'],
[['elencosistop'], 'required'],
[['licsistop'], 'string', 'max' => 80],
];
}
public function attributeLabels()
{
return [
'id_sistop' => Yii::t('app', 'ID'),
'elencosistop' => Yii::t('app', 'Sistema Operativo'),
'licsistop' => Yii::t('app', 'Product Key'),
'qdsistop' => Yii::t('app', 'Q.tà disp.'),
'qusistop' => Yii::t('app', 'Q.tà rim.'),
'created_at' => Yii::t('app', 'Data inserimento'),
'created_by' => Yii::t('app', 'Inserito da'),
'updated_at' => Yii::t('app', 'Data modifica'),
'updated_by' => Yii::t('app', 'Modificato da'),
];
}
public function getCreatore()
{
return $this->hasOne(User::className(), ['id' => 'created_by']);
}
public function getModificatore()
{
return $this->hasOne(User::className(), ['id' => 'updated_by']);
}
public function getManagepcs()
{
return $this->hasMany(Managepc::className(), ['elencosistop' => 'elencosistop']);
}
public static function find()
{
return new SistopQuery(get_called_class());
}
}
app\models\SistopSearch.php
namespace app\models;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use app\models\Sistop;
class SistopSearch extends Sistop
{
public function rules()
{
return [
[['id_sistop', 'qdsistop', 'qusistop'], 'integer'],
[['elencosistop', 'licsistop'], 'safe'],
];
}
public function scenarios()
{
return Model::scenarios();
}
public function search($params)
{
$query = Sistop::find();
// add conditions that should always apply here
$dataProvider = new ActiveDataProvider([
'query' => $query,
]);
$this->load($params);
if (!$this->validate()) {
return $dataProvider;
}
// grid filtering conditions
$query->andFilterWhere([
'id_sistop' => $this->id_sistop,
'qdsistop' => $this->qdsistop,
'qusistop' => $this->qusistop,
'created_at' => $this->created_at,
'created_by' => $this->created_by,
'updated_at' => $this->updated_at,
'updated_by' => $this->updated_by,
]);
$query->andFilterWhere(['like', 'elencosistop', $this->elencosistop])
->andFilterWhere(['like', 'licsistop', $this->licsistop]);
return $dataProvider;
}
}
app\controllers\SistopController.php
namespace app\controllers;
use Yii;
use app\models\Sistop;
use app\models\SistopSearch;
use yii\web\Controller;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;
class SistopController extends Controller
{
public function behaviors()
{
return [
'verbs' => [
'class' => VerbFilter::className(),
'actions' => [
'delete' => ['POST'],
],
],
'access' => [
'class' => \yii\filters\AccessControl::className(),
'rules' => [
[
'allow' => true,
'actions' => ['index', 'view'],
'roles' => ['view']
],
[
'allow' => true,
'actions' => ['update'],
'roles' => ['update']
],
[
'allow' => true,
'actions' => ['create'],
'roles' => ['create']
],
[
'allow' => true,
'actions' => ['delete'],
'roles' => ['delete']
],
[
'allow' => false
]
]
]
];
}
public function actionIndex()
{
$searchModel = new SistopSearch();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
return $this->render('index', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
]);
}
public function actionView($id)
{
return $this->render('view', [
'model' => $this->findModel($id),
]);
}
public function actionCreate()
{
$model = new Sistop();
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['view', 'id' => $model->id_sistop]);
}
return $this->render('create', [
'model' => $model,
]);
}
public function actionUpdate($id)
{
$model = $this->findModel($id);
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['view', 'id' => $model->id_sistop]);
}
return $this->render('update', [
'model' => $model,
]);
}
public function actionDelete($id)
{
$this->findModel($id)->delete();
return $this->redirect(['index']);
}
protected function findModel($id)
{
if (($model = Sistop::findOne($id)) !== null) {
return $model;
}
throw new NotFoundHttpException(Yii::t('app', 'The requested page does not exist.'));
}
}
app\views\sistop\index.php
use yii\helpers\Html;
use yii\grid\GridView;
use yii\widgets\Pjax;
$this->title = Yii::t('app', 'Elenco Sistemi Operativi');
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="sistop-index">
<h1><?= Html::encode($this->title) ?></h1>
<p>
<?= Html::a(Yii::t('app', 'Aggiungi nuovo'), ['create'], ['class' => 'btn btn-success']) ?>
</p>
<?php Pjax::begin(); ?>
<?php // echo $this->render('_search', ['model' => $searchModel]);
?>
<?= GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'columns' => [
['class' => 'yii\grid\SerialColumn'],
//'id_sistop',
'elencosistop',
'licsistop',
'qdsistop',
'qusistop',
//'created_at:datetime',
//[
// 'attribute' => 'created_by',
// 'value' => 'creatore.username',
//],
//'updated_at:datetime',
// [
// 'attribute' => 'updated_by',
// 'value' => 'modificatore.username',
//],
['class' => 'yii\grid\ActionColumn'],
],
]); ?>
<?php Pjax::end(); ?>
</div>
app\models\Managepc.php
.......
public function getSistop()
{
return $this->hasOne(Sistop::className(), ['id_sistop' => 'os']);
}
public function getElencosistop()
{
return $this->sistop->elencosistop;
}
app\models\ManagepcSearch.php
.........................................
public function search($params)
{
$query = Managepc::find();
$query->joinWith(['nome']);
$query->joinWith(['cognome']);
$query->joinWith(['sistop']);
.................
................
$dataProvider = new ActiveDataProvider([
'query' => $query,
]);
$this->load($params);
if (!$this->validate()) {
// uncomment the following line if you do not want to return any records when validation fails
// $query->where('0=1');
return $dataProvider;
}
// grid filtering conditions
$query->andFilterWhere([
'id_managepc' => $this->id_managepc,
]);
$query->andFilterWhere(['like', 'cognome.elencocognome', $this->cognomi])
->andFilterWhere(['like', 'nome.elenconome', $this->nomi])
->andFilterWhere(['like', 'sistop.elencosistop', $this->os])
...........................................................
............................................................;
return $dataProvider;
}
}
app\views\managepc\_form.php
use yii\helpers\Html;
use yii\widgets\ActiveForm;
use yii\helpers\ArrayHelper;
use app\models\Cognome;
use app\models\Nome;
use app\models\Sistop;
use app\models\...........;
use app\models\...........;
use app\models\...........;
use app\models\...........;
use app\models\...........;
<div class="managepc-form">
<?php $form = ActiveForm::begin(); ?>
<div class="row">
<div class="col-lg-2 col-xs-12">
<?= $form->field($model, 'cognome')->dropDownList(ArrayHelper::map(Cognome::find()->all(), 'id_cognome', 'elencocognomi'), ['prompt'=>'Seleziona...']) ?>
</div>
<div class="col-lg-2 col-xs-12">
<?= $form->field($model, 'nome')->dropDownList(ArrayHelper::map(Nome::find()->all(), 'id_nome', 'elenconomi'), ['prompt'=>'Seleziona...']) ?>
</div>
<div class="col-lg-2 col-xs-12">
<?= $form->field($model, 'sistop')->dropDownList(ArrayHelper::map(Sistop::find()->all(), 'id_sistop', 'elencosistop'), ['prompt'=>'Seleziona...']) ?>
</div>
<div class="col-lg-3 col-xs-12">
......................................
</div>
<div class="col-lg-3 col-xs-12">
.....................................
</div>
</div>
...............
<?php // echo $form->field($model, 'created_at')->textInput() ?>
<?php // echo $form->field($model, 'created_by')->textInput() ?>
<?php // echo $form->field($model, 'updated_at')->textInput() ?>
<?php // echo $form->field($model, 'updated_by')->textInput() ?>
<div class="form-group">
<?= Html::submitButton(Yii::t('app', 'Salva'), ['class' => 'btn btn-success']) ?>
</div>
<?php ActiveForm::end(); ?>
</div>