本文整理汇总了PHP中app\models\Object::findOne方法的典型用法代码示例。如果您正苦于以下问题:PHP Object::findOne方法的具体用法?PHP Object::findOne怎么用?PHP Object::findOne使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\models\Object
的用法示例。
在下文中一共展示了Object::findOne方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: findById
/**
* Returns model instance by ID using IdentityMap
* @param integer $id
* @return Object
*/
public static function findById($id)
{
if (!isset(static::$identity_map[$id])) {
static::$identity_map[$id] = Yii::$app->cache->get('Object: ' . $id);
if (static::$identity_map[$id] === false) {
static::$identity_map[$id] = Object::findOne($id);
if (is_object(static::$identity_map[$id])) {
static::$ids_for_class_name[static::$identity_map[$id]->object_class] = $id;
Yii::$app->cache->set('Object: ' . $id, static::$identity_map[$id], 86400, new TagDependency(['tags' => [\devgroup\TagDependencyHelper\ActiveRecordHelper::getObjectTag(static::className(), $id)]]));
}
}
}
return static::$identity_map[$id];
}
示例2: up
public function up()
{
$objects = \app\models\Object::find()->asArray()->all();
foreach ($objects as $object) {
if ($object['name'] == 'Submission') {
continue;
} else {
if ($object['name'] == 'Form') {
$submissionObject = \app\models\Object::findOne(['name' => 'Submission']);
$this->addColumn($object['eav_table_name'], 'property_group_id', 'INT UNSIGNED NOT NULL AFTER `object_model_id`');
$this->addColumn($submissionObject->eav_table_name, 'property_group_id', 'INT UNSIGNED NOT NULL AFTER `object_model_id`');
$groups = \app\models\PropertyGroup::find()->where(['object_id' => $object['id']])->asArray()->all();
foreach ($groups as $group) {
$forms = \app\models\ObjectPropertyGroup::find()->select('object_model_id')->where(['property_group_id' => $group['id']])->asArray()->all();
$formIDs = [];
foreach ($forms as $formID) {
if (!in_array($formID['object_model_id'], $formIDs)) {
$formIDs[] = $formID['object_model_id'];
}
}
$submissionIDs = \app\models\Submission::find()->select('id')->where(['form_id' => $formIDs])->asArray()->all();
$subIDs = [];
foreach ($submissionIDs as $submission) {
$subIDs[] = $submission['id'];
}
$properties = \app\models\Property::find()->select(['id', 'key'])->where(['property_group_id' => $group['id'], 'is_eav' => 1])->asArray()->all();
foreach ($properties as $property) {
$this->update($submissionObject->eav_table_name, ['property_group_id' => $group['id']], ['key' => $property['key']]);
}
}
} else {
$this->addColumn($object['eav_table_name'], 'property_group_id', 'INT UNSIGNED NOT NULL AFTER `object_model_id`');
$groups = \app\models\PropertyGroup::find()->where(['object_id' => $object['id']])->asArray()->all();
foreach ($groups as $group) {
$properties = \app\models\Property::find()->select(['id', 'key'])->where(['property_group_id' => $group['id'], 'is_eav' => 1])->asArray()->all();
foreach ($properties as $property) {
$this->update($object['eav_table_name'], ['property_group_id' => $group['id']], ['key' => $property['key']]);
}
}
}
}
}
}
示例3: findModel
/**
* Finds the Object model based on its primary key value.
* If the model is not found, a 404 HTTP exception will be thrown.
* @param integer $id
* @return Object the loaded model
* @throws NotFoundHttpException if the model cannot be found
*/
protected function findModel($id)
{
if (($model = Object::findOne($id)) !== null) {
return $model;
} else {
throw new NotFoundHttpException('The requested page does not exist.');
}
}
示例4: invalidateObjectCache
/**
* Invalidate cache for object
*/
private function invalidateObjectCache()
{
$className = null;
if (!isset(static::$objectClassMap[static::$tableName])) {
/** @var Object $object */
if (null !== ($object = Object::findOne(['eav_table_name' => static::$tableName]))) {
static::$objectClassMap[static::$tableName] = $object->object_class;
$className = static::$objectClassMap[static::$tableName];
}
} else {
$className = static::$objectClassMap[static::$tableName];
}
if (null !== $className) {
\yii\caching\TagDependency::invalidate(\Yii::$app->cache, [ActiveRecordHelper::getObjectTag($className, $this->object_model_id)]);
}
}
示例5: findModelobject
/**
* Finds the Object model based on its primary key value.
* If the model is not found, a 404 HTTP exception will be thrown.
* @param string $id
* @return Monitor the loaded model
* @throws NotFoundHttpException if the model cannot be found
*/
protected function findModelobject($id)
{
if (($modelobject = Object::findOne($id)) !== null) {
return $modelobject;
} else {
throw new NotFoundHttpException('Заведение не найдено.');
}
}