本文整理汇总了PHP中Animal::save方法的典型用法代码示例。如果您正苦于以下问题:PHP Animal::save方法的具体用法?PHP Animal::save怎么用?PHP Animal::save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Animal
的用法示例。
在下文中一共展示了Animal::save方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: AnimalType
function test_getAnimals()
{
//Arrange
$type = "dog";
$id = null;
$test_animal_type = new AnimalType($type, $id);
$test_animal_type->save();
$test_type_id = $test_animal_type->getId();
$name = 'Sparky';
$gender = 'Male';
$breed = 'Pug';
$admit_date = '2015-08-18';
$test_animal = new Animal($name, $gender, $breed, $admit_date, $test_type_id);
$test_animal->save();
$name2 = 'Senna';
$gender2 = 'Male';
$breed2 = 'Domestic Shorthair';
$admit_date2 = '2015-07-28';
$test_animal2 = new Animal($name, $gender, $breed, $admit_date, $test_type_id);
$test_animal2->save();
//Act
$result = $test_animal_type->getAnimals();
//Assert
$this->assertEquals([$test_animal, $test_animal2], $result);
}
示例2: register
public function register($aid, $name, $gender, $age, $type, $u_name, $u_gender, $u_city, $inviter)
{
$user = new User();
$user->name = $u_name;
$user->gender = $u_gender;
$user->city = $u_city;
$user->code = $this->createInviteCode();
$user->inviter = $inviter;
$user->gold = 500;
$reward_items = array(1101 => 3, 1102 => 3, 1103 => 3, 1104 => 3, 1105 => 3, 1106 => 3, 1107 => 3, 1201 => 2, 1202 => 2, 1203 => 2, 1204 => 2, 1205 => 2, 1206 => 2, 1207 => 2, 1301 => 1, 1302 => 1, 1303 => 1, 1304 => 1, 1305 => 1, 2101 => 3, 2102 => 3, 2103 => 3, 2104 => 3);
$user->items = serialize($reward_items);
$user->save();
if (!isset($aid)) {
$animal = new Animal();
$animal->name = $name;
$animal->gender = $gender;
$animal->age = $age;
$animal->type = $type;
$animal->from = substr($type, 0, 1);
$animal->master_id = $user->usr_id;
$animal->save();
$aid = $animal->aid;
$circle = new Circle();
$circle->aid = $aid;
$circle->usr_id = $user->usr_id;
$circle->rank = 0;
$circle->save();
} else {
$circle = new Circle();
$circle->aid = $aid;
$circle->usr_id = $user->usr_id;
$circle->save();
}
$f = new Follow();
$f->usr_id = $user->usr_id;
$f->aid = $aid;
$f->create_time = time();
$f->save();
$user->aid = $aid;
$user->saveAttributes(array('aid'));
$user->initialize();
$user->rewardInviter();
//$this->onRegister = array($user, 'initialize');
//$this->onRegister = array($user, 'rewardInviter');
$this->owner->usr_id = $user->usr_id;
$this->owner->saveAttributes(array('usr_id'));
$this->onRegister(new CEvent());
return $user;
}
示例3: actionCreateApi
public function actionCreateApi($name, $gender, $age, $type)
{
$transaction = Yii::app()->db->beginTransaction();
try {
$animal = new Animal();
$animal->name = $name;
$animal->gender = $gender;
$animal->age = $age;
$animal->type = $type;
$animal->from = substr($type, 0, 1);
$animal->master_id = $this->usr_id;
$animal->save();
$circle = new Circle();
$circle->aid = $animal->aid;
$circle->usr_id = $this->usr_id;
$circle->rank = 0;
$circle->save();
$f = new Follow();
$f->usr_id = $this->usr_id;
$f->aid = $animal->aid;
$f->create_time = time();
$f->save();
Yii::app()->db->createCommand('UPDATE dc_user SET aid=:aid WHERE usr_id=:usr_id')->bindValues(array(':aid' => $animal->aid, ':usr_id' => $this->usr_id))->execute();
$transaction->commit();
} catch (Exception $e) {
$transaction->rollback();
throw $e;
}
$this->echoJsonData(array('aid' => $animal->aid));
}
示例4: actionSalvarNovoAnimal
/**
* SAVE NOVO ANIMAL
*/
public function actionSalvarNovoAnimal()
{
$dadosPost = Yii::app()->request->rawBody;
$parametros = CJSON::decode($dadosPost, true);
if (isset($parametros['id']) && $parametros['id'] != '') {
$animal = Animal::model()->find(array('condition' => ' id=:id', 'params' => array(':id' => $parametros['id'])));
} else {
$animal = new Animal();
}
$animal->nome = $parametros['nome'];
$animal->nascimento = isset($parametros['nascimento']) ? $parametros['nascimento'] : "";
$animal->raca = $parametros['raca'];
$animal->sexo = $parametros['sexo'];
$animal->registro = isset($parametros['registro']) ? $parametros['registro'] : "";
$animal->dna = isset($parametros['dna']) ? $parametros['dna'] : "";
$animal->pelagem = isset($parametros['pelagem']) ? $parametros['pelagem'] : "";
$animal->video = isset($parametros['video']) ? $parametros['video'] : "";
$animal->descricao = isset($parametros['descricao']) ? $parametros['descricao'] : "";
$animal->pai = isset($parametros['pai']) ? $parametros['pai'] : "";
$animal->mae = isset($parametros['mae']) ? $parametros['mae'] : "";
$animal->pagina = isset($parametros['pagina']) ? $parametros['pagina'] : "";
$response = array();
if ($animal->save() === false) {
$response['success'] = false;
$response['errors'] = $animal->errors;
} else {
$imagens = $parametros['imagens'];
for ($i = 0; $i < count($imagens); $i++) {
$imagem = $imagens[$i];
$status = isset($imagem['status']) ? $imagem['status'] : "";
if ($status == "I") {
$imagemAnimal = new Imagemanimal();
$imagemAnimal->url = $imagens[$i]['url'];
$imagemAnimal->animal = $animal->id;
$imagemAnimal->status = 'U';
$imagemAnimal->descricao = isset($imagens[$i]['descricao']) ? $imagens[$i]['descricao'] : "";
$imagemAnimal->save();
} else {
if ($status == "U") {
if (isset($imagem['id'])) {
$condition = ' id=:id';
$params = array(':id' => $imagem['id']);
$busca = array('condition' => $condition, 'params' => $params);
$imagemAnimal = Imagemanimal::model()->find($busca);
$imagemAnimal->descricao = isset($imagem['descricao']) ? $imagem['descricao'] : "";
$imagemAnimal->save();
}
} else {
if ($status == "D") {
if (isset($imagem['id'])) {
$condition = ' id=:id';
$params = array(':id' => $imagem['id']);
$busca = array('condition' => $condition, 'params' => $params);
$imagemAnimal = Imagemanimal::model()->find($busca);
$imagemAnimal->delete();
}
}
}
}
}
$premiacoes = $parametros['premiacoes'];
for ($i = 0; $i < count($premiacoes); $i++) {
$premiacao = $premiacoes[$i];
$status = isset($premiacao['status']) ? $premiacao['status'] : "";
if ($status == "I") {
$animalpremiacao = new Animalpremiacao();
$animalpremiacao->descricao = $premiacao['descricao'];
$animalpremiacao->status = 'U';
$animalpremiacao->animal = $animal->id;
$animalpremiacao->save();
}
}
$response['success'] = true;
$response['contacts'] = $animal;
}
header('Content-type: application/json; charset=utf-8');
echo CJSON::encode($response);
Yii::app()->end();
}
示例5: function
// });
$app->get("/types", function () use($app) {
return $app['twig']->render('types.html.twig', array('types' => Type::getAll()));
});
$app->get("/types/{id}", function ($id) use($app) {
$type = Type::find($id);
return $app['twig']->render('types.html.twig', array('types' => $type, 'animals' => $type->getAnimals()));
});
$app->post("/animals", function () use($app) {
$name = $_POST['name'];
$gender = $_POST['gender'];
$breed = $_POST['breed'];
$age = $_POST['age'];
$type_id = $_POST['type_id'];
$animal = new Animal($name, $gender, $breed, $age, $type_id, $id = null);
$animal->save();
$type = Type::find($type_id);
return $app['twig']->render('types.html.twig', array('types' => $type, 'animals' => Animal::getAll()));
});
$app->post("/types", function () use($app) {
$type = new Type($_POST['name']);
$type->save();
return $app['twig']->render('index.html.twig', array('types' => Type::getAll()));
});
$app->post("/delete_types", function () use($app) {
Animal::deleteAll();
Type::deleteAll();
return $app['twig']->render('index.html.twig', array('types' => Type::getAll()));
});
return $app;
?>