本文整理汇总了PHP中Yii::App方法的典型用法代码示例。如果您正苦于以下问题:PHP Yii::App方法的具体用法?PHP Yii::App怎么用?PHP Yii::App使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Yii
的用法示例。
在下文中一共展示了Yii::App方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: actionSearch
function actionSearch($q = null, $page = 1)
{
$pages = new CPagination();
$pages->pageSize = 50;
$pages->currentPage = $page;
$p = new CHtmlPurifier();
$q = CHtml::encode($p->purify($q));
$searchCriteria = new stdClass();
$searchCriteria->select = 'id';
$searchCriteria->query = $q . '*';
$searchCriteria->paginator = $pages;
$searchCriteria->from = join(",", $this->indexes);
// Получаем данные в виде массива
$resArray = Yii::App()->search->searchRaw($searchCriteria);
$news = null;
if (is_array($resArray['matches'])) {
$c = new CDbCriteria();
$c->order = 'FIELD(id,' . join(",", array_keys($resArray['matches'])) . ')';
$news = News::model()->findAllByPk(array_keys($resArray['matches']), $c);
}
$this->render("search_results", array('news' => $news));
}
示例2: fetchData
protected function fetchData()
{
if ($this->criteria->filters["make"]) {
$make = $this->criteria->filters["make"];
$make_num = $make / 1000000;
$search = "search_" . $make_num;
$this->criteria->from = $this->criteria->from . "_{$make}";
$search = Yii::app()->{$search};
} else {
$search = Yii::App()->search;
}
$search->setArrayResult($this->arrayResult);
$search->setMatchMode($this->matchMode);
$search->setMaxQueryTime($this->maxQueryTime);
if (($pagination = $this->getPagination()) !== false) {
$pagination->setItemCount($this->getTotalItemCount());
$limit = $pagination->getLimit();
$offset = $pagination->getOffset();
$this->criteria->paginator = $pagination;
}
$search->SetLimits($offset, $limit);
$searchCriteria = $this->criteria;
$rs = $search->searchRaw($searchCriteria);
if ($rs["total_found"]) {
$this->totalNum = $rs["total_found"];
}
return $rs["matches"];
}
示例3: authenticate
public function authenticate()
{
if ($this->username == 'admin' && $this->password == 'admin') {
$this->errorCode = self::ERROR_NONE;
$this->_id = 0;
Yii::app()->session['role'] = 0;
return !$this->errorCode;
}
$username = $this->username;
$connection = Yii::App()->db;
$sql = "select id,level,email_id,password from login where email_id = :email_id";
$users = $connection->createCommand($sql)->bindValue('email_id', $username)->queryRow();
$sql = "select email_id,password where `email_id`='" . $username . "';";
if (!isset($users['email_id'])) {
$this->errorCode = self::ERROR_USERNAME_INVALID;
} elseif ($users['password'] !== md5($this->password)) {
$this->errorCode = self::ERROR_PASSWORD_INVALID;
} else {
$this->_id = $users['id'];
Yii::app()->session['role'] = $users["level"];
$this->_email_id = $users["email_id"];
$this->_level = $users["level"];
$this->errorCode = self::ERROR_NONE;
}
return !$this->errorCode;
}
示例4: actionViewJobProfiles
public function actionViewJobProfiles()
{
$sqlcount = $count = Yii::app()->db->createCommand("SELECT COUNT(*) FROM job_profile t2 WHERE t2.c_id = " . Yii::App()->user->id)->queryScalar();
$sql = "SELECT * FROM job_profile t2 WHERE t2.c_id = " . Yii::App()->user->id;
$dataprovider = new CSqlDataProvider($sql, array('db' => Yii::app()->db, 'keyField' => 'j_id', 'totalItemCount' => $sqlcount));
$this->render('viewjobprofiles', array('dataprovider' => $dataprovider));
}
示例5: getOrder
/**
* Lazy loading of order.
* Order ID should be passed from a parameter.
*
* @return type
*/
public function getOrder()
{
if ($this->_order === null) {
$orderId = Yii::App()->request->getParam('order_id');
$this->_order = Order::model()->findByPk($orderId);
}
return $this->_order;
}
示例6: actionUserpage
public function actionUserpage()
{
$criteria = new CDbCriteria();
$criteria->condition = 'user_id="' . Yii::App()->user->id . '"';
$criteria->order = 'title ASC';
$dataProvider = new CActiveDataProvider('Page', array('criteria' => $criteria));
$this->render('userpage', array('dataProvider' => $dataProvider, 'model' => $model));
}
示例7: actionRegistration
/**
* Displays the login page
*/
public function actionRegistration()
{
$model = new User();
if (isset($_POST['User'])) {
$model->attributes = $_POST['User'];
if ($model->save()) {
Yii::App()->user->setFlash('registration', '');
$this->redirect(array('/page/room'));
}
}
$this->render('registration', array('model' => $model));
}
示例8: actionFinish
public function actionFinish($id)
{
if (Yii::App()->request->isPostRequest) {
$model = $this->loadModel($id);
if ($model->finish()) {
echo CJSON::encode(array('error' => 0));
} else {
echo CJSON::encode(array('error' => 1, 'message' => Yii::t('app', $model->getError('state'))));
}
} else {
throw new CHttpException(400, 'Invalid page request!');
}
}
示例9: actionAccept
public function actionAccept($j_id, $c_id)
{
if (Yii::app()->session['role'] == 1) {
$offerAcCount = count(Yii::app()->db->createCommand("select c_id from offers where st_id = " . Yii::app()->user->id . " and ppo <> 'Y' and accepted = 'Y'")->queryAll());
if ($offerAcCount == 0) {
$connection = Yii::App()->db;
$sql = "UPDATE offers set accepted = 'Y' where j_id = :j_id and c_id = :c_id and st_id = " . Yii::app()->user->id;
$command = $connection->createCommand($sql);
$command->bindParam(":j_id", $j_id, PDO::PARAM_STR);
$command->bindParam(":c_id", $c_id, PDO::PARAM_STR);
$command->execute();
Yii::app()->user->setFlash('success', 'Accepted');
$this->redirect(array('student/viewOffers'));
} else {
Yii::app()->user->setFlash('error', 'Slow down! You are already placed. Let others have a chance my friend');
$this->redirect(array('student/viewOffers'));
}
}
}
示例10: init
public function init()
{
$app = Yii::App();
// Register dropbox autoload
spl_autoload_unregister(array('YiiBase', 'autoload'));
require_once 'protected/vendors/dropbox-sdk-php/lib/Dropbox/autoload.php';
spl_autoload_register(array('YiiBase', 'autoload'));
// There are two WebUser to not have conflicts, one for the front-end and one for the back-end, this sets it to the front-end
if (isset(Yii::app()->userFront)) {
Yii::app()->setComponent('user', Yii::app()->userFront);
}
// Register JS and CSS files
$app->clientScript->registerCoreScript('jquery');
$app->clientScript->registerScriptFile('/javascript/bootstrap.min.js', CClientScript::POS_HEAD);
$app->clientScript->registerScriptFile('/javascript/ie10-viewport-bug-workaround.js', CClientScript::POS_HEAD);
$app->clientScript->registerScriptFile('/javascript/global.js', CClientScript::POS_HEAD);
// Makes it so it throws and error if an alias exist for the current route and hasn't been used
$app->urlManager->forceAliases();
}
示例11: actionInlineEdit
public function actionInlineEdit()
{
if (!Yii::app()->request->isPostRequest || !Yii::app()->request->isAjaxRequest) {
throw new CHttpException(404);
}
$pk = Yii::app()->request->getPost('pk');
$value = Yii::app()->request->getPost('value');
$name = Yii::app()->request->getPost('name');
if (!isset($pk, $name)) {
throw new CHttpException(404);
}
$model = AuthItem::model()->find('name = :name', array(':name' => $pk));
if (null === $model) {
throw new CHttpException(403);
}
$model->{$name} = $value;
if (!$model->save()) {
throw new CHttpException(500, $model->getError($name));
}
Yii::App()->ajax->success();
}
示例12: log_request
/**
* Log each appropiate request on the application
*
*/
private function log_request()
{
$command = Yii::app()->db->createCommand();
//Do NOT log some specific actions in some specific conditions
//ie:We should not be logging each user subject fetch unless there is a new subject(that would be a line in the log every 10 sec)
if ($this->action->Id == 'js') {
$this->no_log = true;
}
if (Log::is_bot($_SERVER['HTTP_USER_AGENT'])) {
$this->no_log = true;
}
///Dont log if its a bot request
if ($this->no_log == false) {
try {
$command->insert('log', array('time' => SiteLibrary::utc_time(), 'session_id' => Yii::app()->getSession()->getSessionID(), 'user_id' => (int) Yii::app()->user->id, 'controller' => $this->id, 'action' => $this->action->Id, 'uri' => Yii::App()->request->getRequestUri(), 'model' => get_class($this->model), 'model_id' => isset($this->model->id) ? (int) $this->model->id : 0, 'theme' => Yii::app()->getTheme() ? strtolower(substr(Yii::app()->getTheme()->getName(), 0, 2)) : 're'));
//Get real clients ip if from a proxy
$client_ip = "";
$client_host = !empty($_SERVER["HTTP_X_FORWARDED_HOST"]) ? $_SERVER["HTTP_X_FORWARDED_HOST"] : "";
if (!empty($_SERVER["HTTP_CLIENT_IP"])) {
$client_ip = $_SERVER["HTTP_CLIENT_IP"];
//first verify ip from share internet
} elseif (!empty($_SERVER["HTTP_X_FORWARDED_FOR"])) {
$client_ip = $_SERVER["HTTP_X_FORWARDED_FOR"];
//if not then for a proxy user
} else {
}
//Only the first request should go here
//if(Yii::App()->request->getCookies()->getCount() == 0)//If cookies are not set this might be the first request
if (Yii::app()->session->get('site_loaded') != "yes") {
$command->insert('log_detail', array('log_id' => Yii::app()->db->getLastInsertID(), 'session' => Yii::app()->getSession()->getSessionID(), 'client_ip' => $client_ip, 'client_host' => $client_host, 'request_ip' => $_SERVER['REMOTE_ADDR'], 'request_host' => $_SERVER['REMOTE_HOST'], 'agent' => $_SERVER['HTTP_USER_AGENT'], 'referer' => $_SERVER['HTTP_REFERER'], 'charset' => $_SERVER['HTTP_ACCEPT_CHARSET'], 'language' => $_SERVER['HTTP_ACCEPT_LANGUAGE'], 'device' => substr(SiteLibrary::get_device(), 0, 2)));
}
} catch (CException $e) {
Yii::log($e, 'warning', 'system.web.Controller');
}
//'params'=>serialize($this->actionParams)
}
}
示例13: array
<?php
Flaticon::Register("/css/flaticon");
$this->pageTitle = "Tananyagok";
$this->breadcrumbs = array('Tantárgyak' => array('subject/index'), $data->name => array('subject/details', 'id' => $data->subject_id), 'Fájlok');
$form_target = Yii::App()->createUrl("file/upload", array("id" => $data->subject_id));
function GetMaxUploadFileSize()
{
$val = trim(ini_get("post_max_size"));
$last = strtolower($val[strlen($val) - 1]);
switch ($last) {
case 'g':
$val *= 1024;
case 'm':
$val *= 1024;
case 'k':
$val *= 1024;
}
return $val;
}
$formatter = new CFormatter();
$UploadLimit = $formatter->formatSize(GetMaxUploadFileSize());
?>
<div class="container">
<div class="row">
<div class="col-xs-12">
<h2><?php
print $data->name;
?>
</h2>
示例14:
/js/autosize/jquery.autosize.min.js"></script>
<script src="<?php
echo Yii::App()->baseUrl;
?>
/js/bootstrap-hover-dropdown.js"></script>
<script src="<?php
echo Yii::App()->baseUrl;
?>
/js/bootstrap-hover-dropdown.min.js"></script>
<script src="<?php
echo Yii::App()->baseUrl;
?>
/js/jquery.blockUI.js"></script>
<script src="<?php
echo Yii::App()->baseUrl;
?>
/js/linxbooks.lbInvoice.js"></script>
<?php
//Yii::app()->editable->init();
?>
<script src="<?php
echo Yii::app()->baseUrl;
?>
/js/application.js"></script>
<script>hljs.initHighlightingOnLoad();</script>
<script type="text/javascript" src="<?php
echo Yii::app()->baseUrl;
?>
/js/jquery.contactable.min.js"></script>
示例15: createLink
protected function createLink($directory)
{
return Yii::App()->params['home_url'] . "/{$directory}";
}