本文整理汇总了PHP中Country::findOne方法的典型用法代码示例。如果您正苦于以下问题:PHP Country::findOne方法的具体用法?PHP Country::findOne怎么用?PHP Country::findOne使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Country
的用法示例。
在下文中一共展示了Country::findOne方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: actionJscountry
/**
* js(on)country returns an json object for the select2 widget
* @param string $search Text for the lookup
* @param integer of the set value
* @return json [description]
*/
public function actionJscountry($search = NULL, $id = NULL)
{
Yii::$app->response->format = Response::FORMAT_JSON;
$clean['more'] = false;
$query = new Query();
if (!is_Null($search)) {
$mainQuery = $query->select('id, iso3 AS text')->from('{{%net_frenzel_country}}')->where('UPPER(iso3) LIKE "%' . strtoupper($search) . '%"');
$command = $mainQuery->createCommand();
$rows = $command->queryAll();
$clean['results'] = array_values($rows);
} else {
if (!is_null($id)) {
$clean['results'] = ['id' => $id, 'text' => Country::findOne($id)->iso3];
} else {
$clean['results'] = ['id' => 0, 'text' => 'None found'];
}
}
return $clean;
}
示例2: validateCountry
/**
* @inheritdoc
*/
public function validateCountry()
{
if ($this->country_id !== null) {
$country = Country::findOne($this->country_id);
if ($country === null) {
$this->addError('country_id', Yii::t('location', 'Country with id {[id]} doesn\'t exist', ['id' => $this->country_id]));
return false;
}
}
return true;
}
示例3: actionDemo
public function actionDemo($id)
{
return Country::findOne($id);
}