ich ein yii2 Projekt und Controller MyModelController.php dort haben, wo ichyii2 bekommen Modell in Controller
namespace app\controllers;
use yii\web\Controller;
use yii\db\Command;
class MyModelController extends Controller
{
public function actionPhoto()
{
$model=new myModel;
return $this->render('photo', ['model' => $model]);
}
}
und Modell bzw.
MyModel.php:
use namespace app\models;
use yii\base\Model;
class MyModel extends ActiveRecord
{
public static function model($className=__CLASS__)
{
return parent::model($className);
}
public function tableName()
{
return 'my_model';
}
public function rules()
{
... some rules
}
public function relations()
{
return array(
);
}
//like fields in my table in mysql
public function attributeLabels()
{
return array(
'id' => 'ID',
'my_model_atribute' => 'MyModel',
);
}
public function search()
{
... some search
}
}
Sie sind in /basic/models
und /basic/controllers
Modell erhalten möchten.
Und ich bekomme diesen Fehler, wenn ich es aus meiner Sicht nennen:
Class 'app\controllers\MyModel' not found
UPD1 Ich versuchte es in Hinblick auf machen photo.php
use yii\helpers\Html;
$model=new MyModel;
var_dump($model);
Und ich gebe immer noch Fehler, dass die Klasse nicht gefunden. UPD2 ich ändern Namespace basic\models
und public_html\basic\models
, wie sie tatsächlich sind, aber es findet noch nicht Klasse dort/
Haben Sie Modell in Controller verwenden? – Farshid
Fügen Sie einfach einen Pfad zu Ihrem Modell im Controller hinzu. Angenommen, es wird wie 'app \ models \ MyModel verwenden;' –
haben Sie Recht. –