本文整理匯總了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);
}