本文整理汇总了PHP中Yii::import方法的典型用法代码示例。如果您正苦于以下问题:PHP Yii::import方法的具体用法?PHP Yii::import怎么用?PHP Yii::import使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Yii
的用法示例。
在下文中一共展示了Yii::import方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: run
public function run($class_name)
{
$path = realpath(Yii::app()->basePath . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'upload' . DIRECTORY_SEPARATOR . $class_name);
$class_name = ucfirst($class_name);
if ($path && is_dir($path) && is_writable($path)) {
$dir = key($_GET);
$filename = $_GET[$dir];
$pk = pathinfo($filename, PATHINFO_FILENAME);
$image = Images::model()->findByPk($pk);
if ($image != null) {
$image->resize($dir);
}
} elseif (class_exists($class_name)) {
$dir = key($_GET);
$filename = $_GET[$dir];
$size = explode('x', $dir);
$path = realpath(Yii::app()->basePath . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'upload' . DIRECTORY_SEPARATOR . $class_name);
if (YII_DEBUG && !file_exists($path . DIRECTORY_SEPARATOR . $dir)) {
mkdir($path . DIRECTORY_SEPARATOR . $dir, 0777);
}
if ($path !== FALSE && file_exists($path . DIRECTORY_SEPARATOR . $dir) && is_file($path . DIRECTORY_SEPARATOR . $filename) && $size[0] > 0 && $size[1] > 0) {
Yii::import('ext.iwi.Iwi');
$image = new Iwi($path . DIRECTORY_SEPARATOR . $filename);
$image->adaptive($size[0], $size[1]);
$image->save($path . DIRECTORY_SEPARATOR . $dir . DIRECTORY_SEPARATOR . $filename, 0644, TRUE);
$mime = CFileHelper::getMimeType($path . DIRECTORY_SEPARATOR . $filename);
header('Content-Type: ' . $mime);
$image->render();
exit;
}
}
return parent::run($class_name);
}
示例2: init
public function init()
{
if (isset($_GET[$this->grid_mode_var])) {
$this->grid_mode = $_GET[$this->grid_mode_var];
}
if (isset($_GET['exportType'])) {
$this->exportType = $_GET['exportType'];
}
$lib = Yii::getPathOfAlias($this->libPath) . '.php';
if ($this->grid_mode == 'export' and !file_exists($lib)) {
$this->grid_mode = 'grid';
Yii::log("PHP Excel lib not found({$lib}). Export disabled !", CLogger::LEVEL_WARNING, 'EExcelview');
}
if ($this->grid_mode == 'export') {
$this->title = $this->title ? $this->title : Yii::app()->getController()->getPageTitle();
$this->initColumns();
//parent::init();
//Autoload fix
spl_autoload_unregister(array('YiiBase', 'autoload'));
Yii::import($this->libPath, true);
$this->objPHPExcel = new PHPExcel();
spl_autoload_register(array('YiiBase', 'autoload'));
// Creating a workbook
$this->objPHPExcel->getProperties()->setCreator($this->creator);
$this->objPHPExcel->getProperties()->setTitle($this->title);
$this->objPHPExcel->getProperties()->setSubject($this->subject);
$this->objPHPExcel->getProperties()->setDescription($this->description);
$this->objPHPExcel->getProperties()->setCategory($this->category);
} else {
parent::init();
}
}
示例3: generateFeed
private function generateFeed($datasets)
{
Yii::import('ext.feed.*');
// specify feed type
$feed = new EFeed(EFeed::RSS1);
$feed->title = $this->title;
$feed->link = $this->rssLink;
$feed->description = $this->rssDescription;
$feed->RSS1ChannelAbout = $this->rssAbout;
foreach ($datasets as $key => $dataset) {
$title = $this->isDataset($dataset) ? $dataset->title : $dataset->message;
$link = $this->isDataset($dataset) ? Yii::app()->request->hostInfo . "/dataset/" . $dataset->identifier : Yii::app()->request->hostInfo;
$desc = $this->isDataset($dataset) ? $dataset->description : $dataset->message;
// create dataset item
$item = $feed->createNewItem();
$item->title = $title;
$item->link = $link;
$item->date = $dataset->publication_date;
$item->description = $desc;
$item->addTag('dc:subject', $title);
$feed->addItem($item);
}
if (count($datasets) == 0) {
echo "No Item";
} else {
$feed->generateFeed();
}
}
示例4: actionRegister
/**
* This is the action to handle external exceptions.
*/
public function actionRegister()
{
if (!Yii::app()->user->isGuest) {
$this->redirect('/member/index.html');
}
$this->pageTitle = "注册用户 - " . Yii::app()->name;
if (isset($_POST['username'])) {
$status = array();
if (!isset($_POST['username']) || !isset($_POST['password'])) {
$status = array('status' => 0, "info" => '用户名或者密码错误!');
} else {
Yii::import("application.models.form.RegeditForm", true);
$loginform = new RegeditForm();
$loginform->setAttributes($_POST);
if ($loginform->validate() && $loginform->save()) {
$status = array('status' => 1, "info" => '已经给你发送了激活邮件,如没有收到,可在会员中心重新发送。');
} else {
$error = $loginform->errors;
$status = array('status' => 0, "info" => current(current($error)));
}
}
echo json_encode($status);
Yii::app()->end();
}
$this->render('html5_regedit');
}
示例5: save
/**
* Logs in the user using the given username and password in the model.
* @return boolean whether login is successful
*/
public function save()
{
$user = new Users();
$user->setAttributes($this->attributes);
$user->setAttribute("password", BaseTool::ENPWD($this->password));
if ($user->validate() && $user->save()) {
$accountarray = array('user_id' => Yii::app()->db->getLastInsertID(), 'total' => 0, 'use_money' => 0, 'no_use_money' => 0, 'newworth' => 0);
$newAccount = new Account();
$newAccount->setAttributes($accountarray);
$newAccount->save();
//发送邮件
$activecode = BaseTool::getActiveMailCode($this->username);
$message = MailTemplet::getActiveEmail($this->username, $activecode);
$mail = Yii::app()->Smtpmail;
$mail->SetFrom(Yii::app()->params['adminEmail']);
$mail->Subject = "好帮贷测试邮件";
$mail->MsgHTML($message);
$mail->AddAddress($this->email);
if ($mail->Send()) {
$user->updateAll(array("regtaken" => $activecode, "regativetime" => time() + 60 * 60), "username=:username", array(":username" => $this->username));
}
Yii::import("application.models.form.LoginForm", true);
$loginform = new LoginForm();
$loginarray = array('rememberMe' => false, 'username' => $this->username, 'password' => $this->password);
$loginform->setAttributes($loginarray);
if ($loginform->validate() && $loginform->login()) {
}
return true;
} else {
$usererror = $user->errors;
$this->addError("username", current(current($usererror)));
return false;
}
}
示例6: getPdfLanguageSettings
/**
* getPdfLanguageSettings
*
* Usage: getPdfLanguageSettings($language)
*
* @return array ('pdffont','pdffontsize','lg'=>array('a_meta_charset','a_meta_dir','a_meta_language','w_page')
* @param string $language : language code for the PDF
*/
public static function getPdfLanguageSettings($language)
{
Yii::import('application.libraries.admin.pdf', true);
Yii::import('application.helpers.surveytranslator_helper', true);
$pdffont = Yii::app()->getConfig('pdfdefaultfont');
if ($pdffont == 'auto') {
$pdffont = PDF_FONT_NAME_DATA;
}
$pdfcorefont = array("freesans", "dejavusans", "courier", "helvetica", "freemono", "symbol", "times", "zapfdingbats");
if (in_array($pdffont, $pdfcorefont)) {
$alternatepdffontfile = Yii::app()->getConfig('alternatepdffontfile');
if (array_key_exists($language, $alternatepdffontfile)) {
$pdffont = $alternatepdffontfile[$language];
// Actually use only core font
}
}
$pdffontsize = Yii::app()->getConfig('pdffontsize');
if ($pdffontsize == 'auto') {
$pdffontsize = PDF_FONT_SIZE_MAIN;
}
$lg = array();
$lg['a_meta_charset'] = 'UTF-8';
if (getLanguageRTL($language)) {
$lg['a_meta_dir'] = 'rtl';
} else {
$lg['a_meta_dir'] = 'ltr';
}
$lg['a_meta_language'] = $language;
$lg['w_page'] = gT("page");
return array('pdffont' => $pdffont, 'pdffontsize' => $pdffontsize, 'lg' => $lg);
}
示例7: validateModel
public function validateModel($attribute, $params)
{
if ($this->hasErrors('model')) {
return;
}
$class = @Yii::import($this->model, true);
if (!is_string($class) || !$this->classExists($class)) {
$this->addError('model', "Class '{$this->model}' does not exist or has syntax error.");
} else {
if (!is_subclass_of($class, 'CActiveRecord')) {
$this->addError('model', "'{$this->model}' must extend from CActiveRecord.");
} else {
$table = CActiveRecord::model($class)->tableSchema;
if ($table->primaryKey === null) {
$this->addError('model', "Table '{$table->name}' does not have a primary key.");
} else {
if (is_array($table->primaryKey)) {
$this->addError('model', "Table '{$table->name}' has a composite primary key which is not supported by crud generator.");
} else {
$this->_modelClass = $class;
$this->_table = $table;
}
}
}
}
}
示例8: actionIndex
/**
* Configuration Action for Super Admins
*/
public function actionIndex()
{
Yii::import('library.forms.*');
$form = new LibraryAdminForm();
// uncomment the following code to enable ajax-based validation
//if (isset($_POST['ajax']) && $_POST['ajax'] === 'LibraryAdminForm') {
// echo CActiveForm::validate($form);
// Yii::app()->end();
//}
if (isset($_POST['LibraryAdminForm'])) {
$_POST['LibraryAdminForm'] = Yii::app()->input->stripClean($_POST['LibraryAdminForm']);
$form->attributes = $_POST['LibraryAdminForm'];
if ($form->validate()) {
$form->globalPublicLibrary = HSetting::Set('globalPublicLibrary', $form->globalPublicLibrary, 'library');
$form->disclaimerWidget = HSetting::Set('disclaimerWidget', $form->disclaimerWidget, 'library');
$form->disclaimerTitle = HSetting::Set('disclaimerTitle', $form->disclaimerTitle, 'library');
$form->disclaimerContent = HSetting::Set('disclaimerContent', $form->disclaimerContent, 'library');
$this->redirect(Yii::app()->createUrl('library/admin/index'));
}
} else {
$form->globalPublicLibrary = HSetting::Get('globalPublicLibrary', 'library');
$form->disclaimerWidget = HSetting::Get('disclaimerWidget', 'library');
$form->disclaimerTitle = HSetting::Get('disclaimerTitle', 'library');
$form->disclaimerContent = HSetting::Get('disclaimerContent', 'library');
}
$this->render('index', array('model' => $form));
}
示例9: validateAttribute
/**
* Validates the attribute of the object.
* If there is any error, the error message is added to the object.
* @param CModel $object the object being validated
* @param string $attribute the attribute being validated
*/
protected function validateAttribute($object, $attribute)
{
$value = $object->{$attribute};
if ($this->allowEmpty && $this->isEmpty($value)) {
return;
}
$className = $this->className === null ? get_class($object) : Yii::import($this->className);
$attributeName = $this->attributeName === null ? $attribute : $this->attributeName;
$finder = CActiveRecord::model($className);
$table = $finder->getTableSchema();
if (($column = $table->getColumn($attributeName)) === null) {
throw new CException(Yii::t('yii', 'Table "{table}" does not have a column named "{column}".', array('{column}' => $attributeName, '{table}' => $table->name)));
}
$columnName = $column->rawName;
$criteria = new CDbCriteria();
if ($this->criteria !== array()) {
$criteria->mergeWith($this->criteria);
}
$tableAlias = empty($criteria->alias) ? $finder->getTableAlias(true) : $criteria->alias;
$valueParamName = CDbCriteria::PARAM_PREFIX . CDbCriteria::$paramCount++;
$criteria->addCondition($this->caseSensitive ? "{$tableAlias}.{$columnName}={$valueParamName}" : "LOWER({$tableAlias}.{$columnName})=LOWER({$valueParamName})");
$criteria->params[$valueParamName] = $value;
if (!$finder->exists($criteria)) {
$message = $this->message !== null ? $this->message : Yii::t('yii', '{attribute} "{value}" is invalid.');
$this->addError($object, $attribute, $message, array('{value}' => CHtml::encode($value)));
}
}
示例10: createImageSet
protected function createImageSet($src_image)
{
Yii::import('application.extensions.ImageCropper');
//Yii::log("Load source img: ".memory_get_usage(true),"info","MemmorySize");
$cropper = new ImageCropper($src_image);
$parts = preg_split('/[\\/\\\\]/', $src_image);
$fileName = array_pop($parts);
foreach ($this->pictures() as $type => $pic) {
if (isset($pic['vertical']) || isset($pic['horizontal'])) {
$Info = getimagesize($src_image);
$orientation = $Info[0] < $Info[1] ? 'vertical' : 'horizontal';
if (isset($pic[$orientation])) {
$w = $pic[$orientation]['w'];
$h = $pic[$orientation]['h'];
}
} else {
$w = $pic['w'];
$h = $pic['h'];
}
$filePath = $_SERVER['DOCUMENT_ROOT'] . $pic['path'] . $fileName;
if ($w == null && $h == null) {
if (!copy($src_image, $filePath)) {
return false;
}
} else {
//Yii::log("Before resize \"".$type."\": ".memory_get_usage(true),"info","MemmorySize");
if (!$cropper->resize_and_crop($filePath, $w, $h)) {
return false;
}
//Yii::log("After resize \"".$type."\"".memory_get_usage(true),"info","MemmorySize");
}
}
$cropper = null;
return $fileName;
}
示例11: suggestIdentifier
public function suggestIdentifier($model)
{
if (!$model instanceof CActiveRecord) {
$model = CActiveRecord::model(Yii::import($model));
}
if (is_callable(array($model, 'getItemLabel'))) {
return 'itemLabel';
}
$nonNumericFound = false;
$columns = $model->tableSchema->columns;
foreach ($columns as $column) {
if ($column->isPrimaryKey) {
$fallbackName = $column->name;
}
// Use the first non-numeric column as a fallback
if (!$column->isForeignKey && !$column->isPrimaryKey && $column->type != 'BIGINT' && $column->type != 'INT' && $column->type != 'INTEGER' && $column->type != 'BOOLEAN' && !$nonNumericFound) {
$fallbackName = $column->name;
$nonNumericFound = true;
}
// Return the first title, name, label column, if found
if (in_array($column->name, array("title", "name", "label"))) {
$fallbackName = $column->name;
break;
}
}
return $fallbackName;
}
示例12: setLanguage
public static function setLanguage($cookieDays = 180)
{
if (Yii::app()->request->getPost('languageSelector') !== null && in_array($_POST['languageSelector'], self::getLanguagesList(), true)) {
Yii::app()->setLanguage($_POST['languageSelector']);
$cookie = new CHttpCookie('language', $_POST['languageSelector']);
$cookie->expire = time() + 60 * 60 * 24 * $cookieDays;
Yii::app()->request->cookies['language'] = $cookie;
} else {
if (isset(Yii::app()->request->cookies['language']) && in_array(Yii::app()->request->cookies['language']->value, self::getLanguagesList(), true)) {
Yii::app()->setLanguage(Yii::app()->request->cookies['language']->value);
} else {
if (isset(Yii::app()->request->cookies['language'])) {
// Invalid language
unset(Yii::app()->request->cookies['language']);
} else {
Yii::import('ext.EGeoIP');
try {
$geoIp = new EGeoIP();
$geoIp->locate();
$countryCode = strtolower($geoIp->getCountryCode());
if (!in_array($countryCode, self::getLanguagesList(), true)) {
return;
}
Yii::app()->setLanguage($countryCode);
$cookie = new CHttpCookie('language', $countryCode);
$cookie->expire = time() + 60 * 60 * 24 * $cookieDays;
Yii::app()->request->cookies['language'] = $cookie;
} catch (Exception $exception) {
Yii::log($exception->__toString(), 'error', 'app.widgets.languageSelector');
}
}
}
}
}
示例13: actionSendMail
public function actionSendMail()
{
if (!empty($_POST)) {
Yii::import('ext.yii-mail.YiiMailMessage');
$message = new YiiMailMessage();
$message->setBody($_POST['content']);
$message->subject = $_POST['subject'];
$message->from = $_POST['email'];
$message->to = Yii::app()->params['adminEmail'];
if (Yii::app()->mail->send($message)) {
$model = new Comments();
$model->title = $_POST['subject'];
$model->content = $_POST['content'];
$model->email = $_POST['email'];
$model->name = $_POST['fullName'];
$model->phone = $_POST['phone'];
$model->created = time();
if ($model->save()) {
return jsonOut(array('error' => false, 'message' => 'Cảm ơn bạn đã gửi thông tin, chúng tôi sẽ phản hồi cho bạn trong thời gian sớm nhất!'));
} else {
return json_encode(array('error' => true, 'message' => 'Lỗi hệ thống, gửi thông tin không thành công.'));
}
} else {
return json_encode(array('error' => true, 'message' => 'Gửi thông tin không thành công'));
}
}
}
示例14: import
/**
* Imports the a class or directory.
* The path alias is automatically prepended if applicable.
* @param string $alias path alias to be imported.
* @param boolean $forceInclude whether to include the class file immediately.
* @return string the class name or the directory that this alias refers to.
* @throws \CException if the alias is invalid.
*/
public function import($alias, $forceInclude = false)
{
if (($baseAlias = $this->getAlias()) !== null) {
$alias = $baseAlias . '.' . $alias;
}
return Yii::import($alias, $forceInclude);
}
示例15: run
/**
* Run method for EMailing System
*
* @param type $args
*/
public function run($args)
{
$this->printHeader('E-Mail Interface');
if (!isset($args[0]) || $args[0] != "daily" && $args[0] != 'hourly') {
print "\n Run with parameter:\n" . "\t daily - for Daily Mailings\n" . "\t hourly - for Hourly Mailings\n";
print "\n\n";
exit;
}
$this->mode = $args[0];
Yii::import("application.modules_core.wall.*", true);
$users = User::model()->with('httpSessions')->findAllByAttributes(array('status' => User::STATUS_ENABLED));
foreach ($users as $user) {
print "Processing : " . $user->email . ": ";
$notificationContent = $this->getNotificationContent($user);
$activityContent = $this->getActivityContent($user);
// Something new?
if ($notificationContent == "" && $activityContent == "") {
print "Nothing new! \n";
continue;
}
$message = new HMailMessage();
$message->view = 'application.views.mail.EMailing';
$message->addFrom(HSetting::Get('systemEmailAddress', 'mailing'), HSetting::Get('systemEmailName', 'mailing'));
$message->addTo($user->email);
if ($this->mode == 'hourly') {
$message->subject = Yii::t('base', "Latest news");
} else {
$message->subject = Yii::t('base', "Your daily summary");
}
$message->setBody(array('notificationContent' => $notificationContent, 'activityContent' => $activityContent, 'user' => $user), 'text/html');
Yii::app()->mail->send($message);
print "Sent! \n";
}
print "\nEMailing completed.\n";
}