Ich versuche, yii zu verwenden, und ich folge einem Tutorial, um einfach eine Seite zu erstellen, die Felder der Datenbank Tabelle schuhen. i create index Ansichtyii Fehler aktive Datensatzabfrage
<?php
/* @var $this yii\web\View */
?>
<h1>articoli/index</h1>
<p>
pippo
<?php
foreach($posts as $post){?>
<h1><?php echo $post->autore; ?> </h1>
<p><?php echo $post->articolo; ?></p>
}
?>
</p>
in Controller erstellen i ArticoliController
<?php
namespace app\controllers;
class ArticoliController extends \yii\web\Controller
{
public function actionIndex()
{
$posts=Articoli::model()->findall();
$data['posts']=$posts;
return $this->render('index',$data);
}
public function actionSaluta(){
$vsa['messaggio']='Alessio';
return $this->render('saluta',$vsa);
}
}
in Modell erstellen i Articoli .php
<?php
namespace app\models;
use Yii;
/**
* This is the model class for table "articoli".
*
* @property integer $id
* @property string $autore
* @property string $articolo
*/
class Articoli extends \yii\db\ActiveRecord
{
/**
* @inheritdoc
*/
public static function tableName()
{
return 'articoli';
}
/**
* @inheritdoc
*/
public function rules()
{
return [
[['articolo'], 'required'],
[['autore'], 'string', 'max' => 55],
[['articolo'], 'string', 'max' => 255],
];
}
/**
* @inheritdoc
*/
public function attributeLabels()
{
return [
'id' => 'ID',
'autore' => 'Autore',
'articolo' => 'Articolo',
];
}
}
, wenn ich es zurückgeben versuchen
PHP Fatal Error – yii\base\ErrorException
Class 'app\controllers\Articoli' not found
ich verstehe nicht. Ich denke, dass es zu app \ models \ Articoli.php gehen muss
Ich versuche es anders $ posts = Articoli :: -> findall();
aber nicht funktionieren
Schauen Sie sich diese Anleitung an: http://www.yiiframework.com/doc-2.0/yii-db-baseactiverecord.html#findAll()-detail –