本文整理汇总了PHP中Animal::model方法的典型用法代码示例。如果您正苦于以下问题:PHP Animal::model方法的具体用法?PHP Animal::model怎么用?PHP Animal::model使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Animal
的用法示例。
在下文中一共展示了Animal::model方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: actionCommentApi
public function actionCommentApi()
{
$img_id = $_POST['img_id'];
$body = $_POST['body'];
$image = Image::model()->findByPk($img_id);
$user = User::model()->findByPk($this->usr_id);
$ex_gold = $user->gold;
$ex_exp = $user->exp;
$ex_lv = $user->lv;
/*
$comment = array(
'usr_id' => $this->usr_id,
'name' => $user->name,
'body' => $body,
'create_time' => time(),
);
*/
if (isset($_POST['reply_id'])) {
$image->comments = 'usr_id:' . $this->usr_id . ',' . 'name:' . $user->name . ',' . 'reply_id:' . $_POST['reply_id'] . ',' . 'reply_name:' . $_POST['reply_name'] . ',' . 'body:' . $body . ',' . 'create_time:' . time() . ';' . $image->comments;
//PMail::create($_POST['reply_id'], $user, $user->name.'在'.$image->img_id.'回复了你');
} else {
$image->comments = 'usr_id:' . $this->usr_id . ',' . 'name:' . $user->name . ',' . 'body:' . $body . ',' . 'create_time:' . time() . ';' . $image->comments;
}
if ($image->saveAttributes(array('comments'))) {
$animal = Animal::model()->findByPk($image->aid);
$animal->t_rq += 5;
$animal->d_rq += 5;
$animal->w_rq += 5;
$animal->m_rq += 5;
$animal->saveAttributes(array('t_rq', 'd_rq', 'w_rq', 'm_rq'));
$session = Yii::app()->session;
if (isset($session['comment_count'])) {
$session['comment_count'] += 1;
} else {
$session['comment_count'] = 1;
}
if ($session['comment_count'] <= 15) {
$user->comment();
}
if (isset($_POST['reply_id'])) {
Talk::model()->sendMsg(NPC_IMAGE_USRID, $_POST['reply_id'], "[" . $image->img_id . "]" . $user->name . "回复了你:" . $body);
} else {
Talk::model()->sendMsg(NPC_IMAGE_USRID, $animal->master_id, "[" . $image->img_id . "]" . $user->name . "评论了你:" . $body);
}
$this->echoJsonData(array('exp' => $user->exp - $ex_exp, 'gold' => $user->gold - $ex_gold, 'lv' => $user->lv - $ex_lv));
}
}
示例2: actionModifyInfoApi
public function actionModifyInfoApi($aid, $name, $gender, $age, $type)
{
$pattern = '/^[a-zA-Z0-9\\x{30A0}-\\x{30FF}\\x{3040}-\\x{309F}\\x{4E00}-\\x{9FBF}]+$/u';
//$namelen = (strlen($name)+mb_strlen($name,"UTF8"))/2;
$namelen = mb_strlen($name, "UTF8");
if ($namelen > 8) {
throw new PException('宠物昵称超过最大长度');
}
if (!preg_match($pattern, $name)) {
throw new PException('宠物昵称含有特殊字符');
}
$transaction = Yii::app()->db->beginTransaction();
try {
$animal = Animal::model()->findByPk($aid);
$animal->name = $name;
$animal->age = $age;
$animal->type = $type;
$animal->gender = $gender;
$animal->saveAttributes(array('name', 'age', 'type', 'gender'));
$transaction->commit();
$this->echoJsonData(array('isSuccess' => true));
} catch (Exception $e) {
$transaction->rollback();
throw $e;
}
}
示例3: actionAnimalFindAll
/**
* ANIMAL FINDALL
*/
public function actionAnimalFindAll()
{
$dadosPost = Yii::app()->request->rawBody;
$parametros = CJSON::decode($dadosPost, true);
$condition = " 1=1 ";
$params = array();
$criteria = new CDbCriteria();
$criteria->condition = $condition;
$criteria->params = $params;
$criteria->together = true;
$criteria->order = 'id asc';
$animais = Animal::model()->findAll($criteria);
$jsons = array();
foreach ($animais as $key => $animal) {
$dados = array();
$dados['id'] = $animal->id;
$dados['nome'] = $animal->nome;
$dados['nascimento'] = strftime('%d%m%Y', strtotime($animal->nascimento));
$dados['nascimentonome'] = strftime('%d de %b, %Y', strtotime($animal->nascimento));
$dados['registro'] = $animal->registro;
$dados['dna'] = $animal->dna;
$dados['pelagem'] = $animal->pelagem;
$dados['video'] = $animal->video;
$dados['descricao'] = $animal->descricao;
$dados['pai'] = $animal->pai;
$dados['nomepai'] = isset($animal->Pai) ? $animal->Pai->nome : '';
$dados['mae'] = $animal->mae;
$dados['nomemae'] = isset($animal->Mae) ? $animal->Mae->nome : '';
$dados['sexo'] = $animal->sexo;
$dados['nomeraca'] = isset($animal->Raca) ? $animal->Raca->nome : '';
$dados['raca'] = $animal->raca;
$dados['pagina'] = $animal->pagina;
$dados['paginanome'] = isset($animal->Pagina) ? $animal->Pagina->nome : '';
$dados['show'] = true;
$dados['qtdimagem'] = count($animal->Imagemanimal);
if (count($animal->Imagemanimal) > 0) {
foreach ($animal->Imagemanimal as $key => $imagem) {
$dados[$imagem->descricao] = $imagem->url;
}
}
$count = 1;
while ($count <= 8) {
if (!isset($dados['imagem' . $count]) || $dados['imagem' . $count] == "") {
$dados['imagem' . $count] = Yii::app()->baseUrl . "/assets/images/simbolo/thumbnail-default.jpg";
}
$count++;
}
$jsons[] = $dados;
}
header('Content-type: application/json; charset=utf-8');
echo CJSON::encode($jsons);
Yii::app()->end();
}