/** * Displays a particular model. * 如果查询没有子地区,则跳转到当前地区 * @param integer $id the ID of the model to be displayed */ public function actionView($id) { $model = $this->loadModel($id); UtilHelper::writeToFile($model->attributes); if ($model->children == null) { //如果已有人开启了广告栏,则跳转到对应广告栏首页,否则就回到本地首页 if ($model->forerunner) { // 设置cookie信息 $cookies = new CHttpCookie('area', serialize($model->attributes)); $cookies->expire = time() + 60 * 60 * 24 * 30; Yii::app()->request->cookies['area'] = $cookies; $link = $this->createUrl('/site/index', array('area' => Region::model()->getUserArea()->short, 'id' => $model->id)); } else { $link = $this->createUrl('/site/mention', array('region' => $model->region)); } echo 'fail_' . $link; } else { $pinyin = new PinYin(); // echo '<ul>'; foreach ($model->children as $data) { // echo '<li>'; echo CHtml::link($data->region, array('/region/view', 'id' => $data->id, 'area' => $pinyin->words2Short($data->region, 1)), array('onclick' => 'uu.loadRegion($(this));return false;')); // echo '</li>'; } // echo '</ul>'; } }
public static function sendMail($to, $subject, $message) { $transport = new Zend_Mail_Transport_Smtp('smtp.yuekegu.com', self::$_config); $mail = new Zend_Mail('UTF-8'); $mail->setHeaderEncoding(Zend_Mime::ENCODING_BASE64); $mail->setBodyHtml($message); $mail->setFrom('*****@*****.**', 'Administrator'); // $mail->addTo(Yii::app()->params['mail'], Yii::app()->params['author']); $mail->addTo($to, 'Receiver'); $mail->setSubject($subject); $mail->send($transport); UtilHelper::writeToFile($mail, 'a+'); }
public function actionIgnore() { ignore_user_abort(); //关掉浏览器,PHP脚本也可以继续执行. set_time_limit(0); // 通过set_time_limit(0)可以让程序无限制的执行下去 $interval = 10; // 每隔半小时运行 static $i = 1; do { //这里是你要执行的代码 UtilHelper::writeToFile(date('y/m/d h:i:s') . "\t i = " . $i++ . "\r\n", 'a+'); sleep($interval); // 等待5分钟 } while (true); }
/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $this->layout = '//layouts/column1'; $model = new Theme(); // Uncomment the following line if AJAX validation is needed $this->performAjaxValidation($model); if (isset($_POST['Theme'])) { $model->attributes = $_POST['Theme']; UtilHelper::writeToFile($_POST); UtilHelper::writeToFile($model->attributes, 'a+'); if ($model->save()) { // $this->redirect(array('view','id'=>$model->id)); echo "OK"; Yii::app()->end(); } else { UtilHelper::writeToFile(CHtml::errorSummary($model)); echo CHtml::errorSummary($model); Yii::app()->end(); } } $this->render('create', array('model' => $model)); }
public function actionRegister() { $this->layout = '//layouts/site'; $model = new RegisterForm(); // uncomment the following code to enable ajax-based validation if (isset($_POST['ajax']) && $_POST['ajax'] === 'register-form') { echo CActiveForm::validate($model); Yii::app()->end(); } if (isset($_POST['RegisterForm'])) { $model->attributes = $_POST['RegisterForm']; // UtilHelper::dump($model->attributes); if ($model->validate() && $model->register()) { Yii::app()->user->setFlash('register', '你是本站的第' . User::model()->count() . '位悦珂人'); $this->refresh(); // form inputs are valid, do something here // return; } else { UtilHelper::writeToFile(CHtml::errorSummary($model), 'a+'); } } $this->render('register', array('model' => $model)); }
public function generateJobLinks($pid, $link = '', $htmlOptions = array(), $addmore = true) { $links = ''; $model = self::getJobs($pid); foreach ($model as $item) { $htmlOptions['id'] = $item->id; $links .= CHtml::link($item->name, array($link, 'id' => $item->id), $htmlOptions); } UtilHelper::writeToFile($links); if ($addmore) { $links .= '<br />如果这里没有您所从事的工作,点这里' . CHtml::link('添加', 'javascript:void();', array('style' => 'border:none;', 'onclick' => 'addRegion();return false;')); } return $links; }
/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $model = new Advertisement(); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['Advertisement'])) { $model->attributes = $_POST['Advertisement']; $model->start = strtotime($model->start); $model->end = strtotime($model->end); if ($model->save()) { $this->redirect(array('view', 'id' => $model->id)); } else { UtilHelper::writeToFile(CHtml::errorSummary($model), './public/test2.txt'); } } $this->render('create', array('model' => $model)); }
return false; } var data = { 'Template[name]':\$("#Template_name").val(), 'Template[code]':formatTemplateCode(), 'Template[sorttype]':\$("#Template_sorttype").val(), 'Template[cname]':\$("#Template_cname").val() }; \$.post("{$submitUrl}",data,function(msg){ console.log(msg); if(msg == 'OK') uu.alert("操作提示","模板添加成功!"); else{ \$(".errorSummary").show().html(\$(msg).html()); } }); } SCRIPT; // Yii::app()->getClientScript()->registerScript('ext-create-CodeMirrorWidget',$script,CClientScript::POS_END); UtilHelper::writeToFile(Yii::app()->getClientScript());
<ul> <?php foreach ($model as $data) { ?> <li class="right" style="margin:2px;text-align:center;width:54px;"> <?php UtilHelper::writeToFile($data->attributes, 'a+'); ?> <?php $avatar = Profile::model()->getUserAvatar($data->id, array('class' => 'left roundSection', 'style' => 'width:50px;margin:10px;padding:10px;'), 50); echo CHtml::link($avatar, array('/archiver/index', 'uid' => $data->id, 'name' => $data->username), array('title' => $data->username)); ?> <br /> <?php // echo UtilHelper::strlen_utf8($data->username)>=8?$data->username:UtilHelper::strSlice($data->username,0,5); ?> </li> <?php } ?> </ul>
/** * 获取格式化标签 * 供给archive/favorite,archiver/efavorite使用 * @param unknown_type $type * @param unknown_type $limit * @param unknown_type $offset * @param unknown_type $htmlOptions * @param unknown_type $url */ public function getTags($type, $limit = 10, $offset = 20, $htmlOptions = array(), $url = 'javascript:void();') { $cacheId = 'getTags_' . $type . '_' . $offset; $result = Yii::app()->cache->get($cacheId); if ($result === false) { if (!isset($htmlOptions['class'])) { $htmlOptions['class'] = 'select'; } $criteria = new CDbCriteria(); $criteria->condition = 'tid = ' . $type; $criteria->limit = $limit; $criteria->offset = $offset; $model = Tag::model()->findAll($criteria); if ($model == null) { $criteria->offset = 0; $model = Tag::model()->findAll($criteria); return '没有了~'; } foreach ($model as $tag) { $htmlOptions['id'] = 'tag-' . $tag->id; $result .= CHtml::link($tag->name, $url, $htmlOptions); // $result .= '<span>'.$tag->name.'</span>'; } Yii::app()->cache->set($cacheId, $result, 3600, new CDbCacheDependency("SELECT MAX(id) FROM {{tag}} WHERE tid = {$type}")); } UtilHelper::writeToFile($result); return $result; }
/** * Add the visitor who have read this blog * @param int $id */ public function addArticleVisitorInfo($id, $interval) { $ip = UtilNet::getClientIp(); // echo $ip; // $qq = new QQWry(long2ip($ip)); // echo $qq->getDetailInfo(); $visitorInfo = Visitor::model()->find('ip = :ip AND aid = :aid', array(':ip' => $ip, ':aid' => $id)); // UtilHelper::dump($visitorInfo->attributes); if ($visitorInfo) { $visitorInfo->lasttime = time(); $visitorInfo->times++; $visitorInfo->alltime .= '|' . time(); $visitorInfo->intervals .= '|' . $interval; if (!Yii::app()->user->isGuest) { $visitorInfo->uid = Yii::app()->user->id; } UtilHelper::writeToFile($visitorInfo->attributes); // Yii::app()->end(); try { $visitorInfo->save(); } catch (Exception $e) { UtilHelper::dump($e); } } else { $visitorInfo = new Visitor(); $visitorInfo->aid = $id; $visitorInfo->ip = $ip; $visitorInfo->lasttime = time(); $visitorInfo->times = 1; $visitorInfo->intervals = $interval; if (!Yii::app()->user->isGuest) { $visitorInfo->uid = Yii::app()->user->id; } $visitorInfo->alltime = time(); $visitorInfo->refer = $_SERVER['HTTP_REFERER']; $visitorInfo->terminal = $_SERVER['HTTP_USER_AGENT']; UtilHelper::writeToFile($visitorInfo->attributes); // Yii::app()->end(); if ($visitorInfo->save()) { // echo "OK"; } else { // echo "Fail"; } } }
/** * 用户结束访问某页面时,添加相关访问信息 * @param unknown_type $id * @param unknown_type $interval */ public function visitEnd($id) { $model = Statistics::model()->findByPk($id); $model->endtime = time(); if (!$model->save()) { UtilHelper::writeToFile(CHtml::errorSummary($model), 'a+'); } else { echo "OKK"; } }
public function actionTest() { UtilHelper::writeToFile($_GET); }
/** * 此方法用于发布广告信息 */ public function actionRelease() { $this->layout = '//layouts/column1'; $model = new Advertisement(); // Uncomment the following line if AJAX validation is needed $this->performAjaxValidation($model); if (isset($_POST['Advertisement'])) { $model->attributes = $_POST['Advertisement']; $model->start = strtotime($model->start); $model->end = strtotime($model->end); $model->hasimg = UtilMatch::hasImage($model->content); $model->imginfo = UtilMatch::getAllImageInfo($model->content); // UtilHelper::dump(UtilMatch::hasImage($model->content)); // UtilHelper::dump(UtilMatch::getAllImageInfo($model->content)); // UtilHelper::writeToFile($model->attributes); // // die(); $return = array(); if ($model->save()) { $return = array('status' => 'ok', 'data' => CHtml::link('继续添加广告', array('/archiver/release', 'uid' => $model->uid)) . CHtml::link('/查看刚发布的广告', array('/info/view', 'uid' => $model->uid, 'id' => $model->id))); } else { $return = array('status' => 'false', 'data' => CHtml::errorSummary($model)); } UtilHelper::writeToFile($return, 'a+'); echo json_encode($return); die; } $this->render('release', array('model' => $model)); }
/** * 开启当前注册人所在地广告栏 */ public function addForerunner($user, $region) { $regions = explode('-', $region); foreach ($regions as $area) { $area = intval($area); $model = Region::model()->find(array('condition' => 'id = :id AND forerunner IS NULL', 'params' => array(':id' => $area))); // UtilHelper::dump($model->attributes); if ($model) { $model->forerunner = $user->id; if (!$model->save()) { UtilHelper::writeToFile(CHtml::errorSummary($model)); } } } }
public function actionCreateRegion() { $todo = array(); $str = "天津市:市辖区 和平区 河东区 河西区 南开区 河北区 红桥区 塘沽区 汉沽区 大港区 东丽区 西青区 津南区 北辰区 武清区 宝坻区 宁河县 静海县 蓟 县 "; $str = str_replace(' ', '', $str); $dd = explode(':', $str); $todo['dd'] = $dd[0]; $todo['tt'] = explode(' ', $dd[1]); // UtilHelper::dump($todo); $result = array(); $file = file('./public/datas/region.txt'); $i = 0; foreach ($file as $province) { $province = str_replace("\r\n", '', $province); $pos = strpos($province, ': '); if ($pos === false) { $region1 = $province; } else { $str = str_replace(' ', '', $province); $mv = explode(': ', $str); $county = explode(' ', $mv[1]); $result[$region1][$mv[0]] = $county; } } $return = array(); $id = 1; $pid = 0; foreach ($result as $key => $item) { $return[] = array('id' => $id, 'pid' => $pid, 'region' => $key); $pid1 = $id; $id++; foreach ($item as $key2 => $item2) { $return[] = array('id' => $id, 'pid' => $pid1, 'region' => $key2); $pid2 = $id; $id++; foreach ($item2 as $item3) { if ($item3 !== '') { $return[] = array('id' => $id, 'pid' => $pid2, 'region' => $item3); $id++; } } } } $fp = fopen('./public/region.txt', 'w+'); //格式化记录到新文件 foreach ($return as $todo) { $content = '|' . $todo['id'] . '|' . $todo['region'] . "|1|" . $todo['pid'] . "|0" . "\r\n"; fwrite($fp, $content); $region = new Region(); $region->id = $todo['id']; $region->region = $todo['region']; $region->pid = $todo['pid']; $region->uid = 1; if (!$region->save()) { UtilHelper::writeToFile(CHtml::errorSummary($model)); } } fclose($fp); UtilHelper::dump($return); }