Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/opencv/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
带有多个条件Yii2的左连接错误_Yii2 - Fatal编程技术网

带有多个条件Yii2的左连接错误

带有多个条件Yii2的左连接错误,yii2,Yii2,根据这条线索 我在Mfwpcontroller中创建sql函数,如下所示: use Yii; use app\models\Mfwp; use app\models\User; use app\models\MfwpSearch; use yii\web\Controller; use yii\web\NotFoundHttpException; use yii\filters\VerbFilter; use yii\web\Response; public function ac

根据这条线索 我在Mfwpcontroller中创建sql函数,如下所示:

use Yii;
use app\models\Mfwp;
use app\models\User;
use app\models\MfwpSearch;
use yii\web\Controller;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;
use yii\web\Response;



    public function actionLists($id)    
    {           
    $posts = Mfwp::find()
    ->joinWith(['user' => function (ActiveQuery $query) {
        return $query
            ->andOnCondition(['=', 'user.id', 'mfwp.id_mfwp'])
            ->andWhere(['=', 'mfwp.id', $id]);
    }])        
    ->asArray()        
    ->all();
    Yii::$app->response->format = 'json';
    return $posts;


   }
这是我在mfwp中的模型

public function getMfwp()
{
    return $this->hasOne(User::className(), ['id' => 'id_mfwp']);
}

/**
 * @return \yii\db\ActiveQuery
 */
public function getSmWps()
{
    return $this->hasMany(SmWp::className(), ['id_sm_wp' => 'id']);
}
当我试图通过访问执行时,它会显示一个错误

无效参数–yii\base\InvalidArgumentException app\models\Mfwp没有名为“user”的关系。 ↵ 原因:未知方法–yii\base\UnknownMethodException 调用未知方法:app\models\Mfwp::getuser()

这是我的数据库结构


那么我的代码有什么问题呢..谢谢你的建议

“用户”在你的示例中是表名还是关系名?用户是表名..好的,这就是你的问题。在Yii中,您需要输入一个关系名称。所以用户必须是一个关系。查看internet如何设置关系,您可以将关系命名为“user”Thx my man Finally我找到了答案..关于关系名称..模型中的用户来自yii迁移..我以前使用名称pejabat再次生成了1个模型。因此,我更改了pejabat模型中的名称关系,并更正了mfwp模型中的名称关系..及其工作..我在yii2中是新的..在您的
Mpwp
模型中定义一个关系名
getUser()