本文整理汇总了PHP中YII类的典型用法代码示例。如果您正苦于以下问题:PHP YII类的具体用法?PHP YII怎么用?PHP YII使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了YII类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
public function __construct($url, $passwrod)
{
YII::import('application.modules.site.components.sharedkey_api.curl.ACurl');
$this->type = Yii::app()->params->serviceType;
$this->host = $url;
$this->password = $passwrod;
}
示例2: actionSubmit
public function actionSubmit()
{
$data = array('email' => YII::app()->request->getParam('email', null), 'name' => YII::app()->request->getParam('name', null), 'message' => YII::app()->request->getParam('message', null));
$model = new ContactusForm();
$model->setAttributes($data);
$isValid = $model->validate();
$emails = array(Yii::app()->params['contactusEmail']);
if (Yii::app()->user->isGuest) {
if ($model->validate()) {
$this->_send($model);
//redirect
Yii::app()->request->redirect(basePath('contactus/confirm'));
} else {
//render errors
$this->layout = "main";
$this->render('guest', array('email' => $data['email'], 'name' => $data['name'], 'contact' => Yii::app()->params['contactusEmail'], 'message' => $data['message'], 'errors' => $model->getErrors()));
}
} else {
$model->email = Yii::app()->user->getState('email');
if ($model->validate()) {
$this->_send($model);
//redirect
Yii::app()->request->redirect(basePath('contactus/confirm'));
} else {
//render errors
$this->layout = "app";
$this->render('user', array('email' => $data['email'], 'name' => $data['name'], 'contact' => Yii::app()->params['contactusEmail'], 'message' => $data['message'], 'errors' => $model->getErrors()));
}
}
}
示例3: getPrincipalByPath
public function getPrincipalByPath($path)
{
$base = YII::app()->createUrl("termine/dav", ["termin_id" => $this->termin_id]);
if ($path == 'principals/guest') {
return ['{DAV:}displayname' => 'Gast', 'uri' => "principals/guest"];
}
return null;
}
示例4: update
public function update()
{
$id = YII::app()->user->getState('id');
$userApi = sharedkeyApi::create('usersAPI');
$userApi->addParams(array('id' => $id, 'format' => 'json'));
$data = $userApi->byid('get');
$data = json_decode($data);
$this->setData((array) $data);
return true;
}
示例5: create
/**
*
*
* @param type $name
* @param type $access
* @param type $host
* @return serviceApi
*/
static function create($name, $access = 'default')
{
$host = YII::app()->params->type;
$names = explode('.', $name);
$className = array_pop($names);
$path = implode('.', $names);
YII::import('application.modules.site.components.sharedkey_api.services' . $path . '.' . $className);
$api = new $className(self::getHosts($host), self::getPassword($access));
return $api;
}
示例6: actionEmail
public function actionEmail()
{
$data = $_GET;
$data['email_confirm'] = isset($data['email']) ? $data['email'] : '';
$validator = new signUpModel();
$validator->setAttributes($data);
$validator->validate();
$emailError = $validator->getError('email');
$valid = $emailError != null ? false : true;
echo json_encode($valid);
YII::app()->end();
}
示例7: actionDeleteActive
public function actionDeleteActive()
{
if ($this->access > UserAccessTable::FULL_ACCESS) {
return 0;
}
$data = array();
$data['property_id'] = Yii::app()->user->getState('property_id', 0);
$data['id'] = YII::app()->request->getPost('id', 0);
$api = sharedkeyApi::create('keycontactAPI');
$api->addParams($data);
$result = $api->byContactId('delete');
$result = json_decode($result);
$this->renderPartial('delete', array('result' => $result->result));
}
示例8: loadModel
public function loadModel()
{
$model = null;
if ($model == null) {
if (isset($_POST['User']['userId'])) {
$model = User::model()->findByPk($_POST['User']['userId']);
} else {
$model = User::model()->findByPk(YII::app()->user->userId);
}
if ($model === null) {
throw new CHttpException(404, '您访问的用户不存在');
}
}
return $model;
}
示例9: upload
/**
*上传多个key不同的文件这里头像解析就要注意了!字段名发生了变化
* @param $model
* @param array $array 上传表单的attribute
*/
public function upload($model, $array = array())
{
$files = array();
foreach ($array as $index => $attribute) {
$attach = CUploadedFile::getInstance($model, $attribute);
if ($attach) {
if (isset(YII::app()->user->userId)) {
$prefix = YII::app()->user->userId . time() . $index . '.';
} else {
$prefix = md5(microtime()) . $index . '.';
}
$imageName = $prefix . $attach->extensionName;
$attach->saveAs($this->savePath . $imageName);
$thumbName = $this->saveThumb($prefix, $attach->extensionName);
$model->{$attribute} = CJSON::encode(array('origin' => $imageName, 'thumb' => $thumbName));
}
}
}
示例10: run
public function run()
{
echo '<div>';
if ($this->all_time) {
echo 'Отработало за ' . sprintf('%0.5f', Yii::getLogger()->getExecutionTime()) . ' с. ';
}
if ($this->memory) {
echo 'Скушано памяти: ' . round(memory_get_peak_usage() / (1024 * 1024), 2) . ' MB';
}
echo '<br>';
$sql_stats = YII::app()->db->getStats();
if ($this->db_query) {
echo $sql_stats[0] . ' запросов к БД. ';
}
if ($this->db_time) {
echo 'время выполнения запросов - ' . sprintf('%0.5f', $sql_stats[1]) . ' c.';
}
echo '</div>';
}
示例11: __construct
function __construct($topic_name, $identity, $host_name = "kafka")
{
$conf = YII::app()->params[$host_name];
if ($conf == '' || $topic_name == '' || $identity == '') {
echo "error : no init param";
exit;
}
if (!in_array($identity, array('producer', 'consumer'))) {
echo "error : wrong identity";
exit;
}
$this->topic_name = $topic_name;
//初始化全局配置
$rd_conf = new RdKafka\Conf();
$rd_conf->set('metadata.broker.list', $conf['host']);
#$rd_conf -> set('socket.keepalive.enable',true);
#$rd_conf -> set('log_level',LOG_DEBUG);//Logging level (syslog(3) levels)
//print_r($rd_conf->dump());exit;
switch ($identity) {
case 'producer':
$rd_conf->set('compression.codec', 'none');
//Compression codec to use for compressing message sets: none, gzip or snappy;default none
$this->producer = new RdKafka\Producer($rd_conf);
break;
case 'consumer':
$rd_conf->set('fetch.message.max.bytes', self::CONSUMER_MESSAGE_MAX_BYTES);
$this->consumer = new RdKafka\Consumer($rd_conf);
$rd_topic_conf = new RdKafka\TopicConf();
$back = debug_backtrace();
$back = $back[1];
$group = $this->topic_name . "_" . $back['class'] . "_" . $back['function'];
$rd_topic_conf->set('group.id', $group);
$rd_topic_conf->set('auto.commit.interval.ms', 1000);
$rd_topic_conf->set("offset.store.path", $this->offset_path);
$rd_topic_conf->set('auto.offset.reset', 'smallest');
//$rd_topic_conf -> set('offset.store.method','broker');//flie(offset.store.path),broker
//$rd_topic_conf -> set('offset.store.sync.interval.ms',60000);//fsync() interval for the offset file, in milliseconds. Use -1 to disable syncing, and 0 for immediate sync after each write.
$this->consumer_topic = $this->consumer->newTopic($topic_name, $rd_topic_conf);
break;
}
}
示例12: generarPlantilla
public static function generarPlantilla($plantilla, $datos, $enPDF = false)
{
$contenido = self::obtenerPlantilla($plantilla);
if ($contenido == false) {
$resultado = 'No hay plantilla';
} else {
$claves = array_keys($datos);
$valores = array_values($datos);
foreach ($claves as $indice => $clave) {
$claves[$indice] = '{' . $clave . '}';
}
$resultado = str_replace($claves, $valores, $contenido);
}
if ($enPDF) {
$mpdf = YII::app()->ePdf->mpdf();
$mpdf->WriteHTML($resultado);
$mpdf->Output();
} else {
echo $resultado;
}
}
示例13: actionAdd
public function actionAdd()
{
$model = new Blogshop();
$categories = Category::getAllCategories();
$selected_categories = array();
if (isset($_POST['Blogshop'])) {
$model->attributes = $_POST['Blogshop'];
$model->openidurl = YII::app()->user->id;
if ($model->validate()) {
$selected_categories = $_POST['category'];
Yii::trace(print_r($_POST['category']), 'application');
if ($model->save()) {
$model->addCategories($model->id, $selected_categories);
$this->redirect(array('list'));
} else {
throw new CHttpException(500, 'Error in saving Blogshop.');
}
}
}
$this->render('add', array('model' => $model, 'categories' => $categories, 'selected' => $selected_categories));
}
示例14: actionUpdate
/**
* UPDATE action. Only accessible by author and admin
*/
public function actionUpdate($id)
{
$post = Post::model()->findByPk($id);
if (null == $post) {
throw new CHttpException(404, 'Post not found.');
}
if (!Yii::app()->user->isForumAdmin() && YII::app()->user->id != $post->author_id) {
throw new CHttpException(403, 'You are not allowed to edit this post.');
}
$thread = $post->thread;
if (isset($_POST['Post'])) {
if (!isset($_POST['YII_CSRF_TOKEN']) || $_POST['YII_CSRF_TOKEN'] != Yii::app()->getRequest()->getCsrfToken()) {
throw new CHttpException(400, 'Invalid request. Please do not repeat this request again.');
}
$post->attributes = $_POST['Post'];
if ($post->validate()) {
$post->save(false);
$this->redirect($post->thread->url);
}
}
$this->render('editpost', array('model' => $post, 'thread' => $thread));
}
示例15: actionIndex
public function actionIndex($propertyId)
{
$this->pageName = "billing";
if (Yii::app()->user->isGuest) {
$this->redirect(basePath('?url=property/' . $propertyId));
}
$this->updateActiveProperty($propertyId);
$property = Properties::model()->findByPk($propertyId);
YII::app()->user->setState("redirect_url", null);
//$property->trialPeriodStartDate != null &&
if (!UserAccessTable::checkUser2PropertyAccess(Yii::app()->user->getState('id'), $propertyId, UserAccessTable::OWNER)) {
Yii::app()->user->logout();
$this->redirect(basePath('?url=property/' . $propertyId));
}
$adminMode = false;
if (UserAccessTable::checkUser2PropertyAccess(Yii::app()->user->getState('id'), Yii::app()->user->getState('property_id'), UserAccessTable::OWNER)) {
$adminMode = true;
}
if ($property->getAttribute('isdeactivated') == 0 && $property->trialPeriodStartDate == null) {
$this->redirect(basePath('app/properties'));
}
//TODO Live
// $DaysAfterTrialWhenUserCanReturnProperty = 7;
// $TrialPeriod = 31;
if ($property->trialPeriodStartDate != null) {
$DaysAfterTrialWhenUserCanReturnProperty = 2;
$TrialPeriod = 2;
$allDays = $DaysAfterTrialWhenUserCanReturnProperty + $TrialPeriod;
$trialStartDate = new DateTime($property->trialPeriodStartDate);
$trialStartDate->modify("+{$allDays} day");
$nowDate = new DateTime();
if ($trialStartDate->format("Y/m/d") < $nowDate->format("Y/m/d")) {
$this->redirect(basePath('app/properties'));
}
}
$this->render('index', array('errors' => null, 'adminMode' => $adminMode, 'countries' => $this->getCountries(), 'provinces' => $this->getProvinces()));
}