小编Dmi*_*kov的帖子

yii2中的case casetive query

要在yii2中查找记录,我使用以下代码:

$response = Response::findOne(['unique_url' => $unique_url]);
Run Code Online (Sandbox Code Playgroud)

$unique_url无论如何,它都会回归记录.如何做案例感慨?

activerecord case-sensitive yii2

7
推荐指数
1
解决办法
2614
查看次数

在 yii 中创建具有关系的下拉列表

我是 Yii 框架的新手,现在我尝试从相关表创建下拉列表。我有表“新闻”[...很多字段,类别] 和“新闻类别”[id,category_name]。在用于在新闻中创建新记录的表单中,当用户可以选择 category_name 时,我想在类别字段中创建一个下拉列表,但类别的 id 必须是新记录中的记录器。

请帮帮我吧。对不起我的英语不好。我希望我的解释是可以理解的。

这是我创建关系的方式

模特新闻.php

public function relations()
{

    // NOTE: you may need to adjust the relation name and the related
    // class name for the relations automatically generated below.
    return array(
    'category'=>array(self::BELONGS_TO, 'NewsCategories', 'category'),
    );
}
Run Code Online (Sandbox Code Playgroud)

模型新闻Categories.php

    public function relations()
{
    // NOTE: you may need to adjust the relation name and the related
    // class name for the relations automatically generated below.
    return array(
    'news'=>array(self::HAS_MANY, 'News', 'id'),
    );
}
Run Code Online (Sandbox Code Playgroud)

以及我如何尝试创建下拉列表:

<?php …
Run Code Online (Sandbox Code Playgroud)

php entity-relationship html-select yii

4
推荐指数
1
解决办法
4064
查看次数