本文整理汇总了PHP中Craft::requirePackage方法的典型用法代码示例。如果您正苦于以下问题:PHP Craft::requirePackage方法的具体用法?PHP Craft::requirePackage怎么用?PHP Craft::requirePackage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Craft
的用法示例。
在下文中一共展示了Craft::requirePackage方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getTableName
<?php
namespace Craft;
/**
* Craft by Pixel & Tonic
*
* @package Craft
* @author Pixel & Tonic, Inc.
* @copyright Copyright (c) 2013, Pixel & Tonic, Inc.
* @license http://buildwithcraft.com/license1.0.html Craft License
* @link http://buildwithcraft.com
*/
Craft::requirePackage(CraftPackage::Users);
/**
*
*/
class UserGroupRecord extends BaseRecord
{
/**
* @return string
*/
public function getTableName()
{
return 'usergroups';
}
/**
* @access protected
* @return array
*/
protected function defineAttributes()
示例2: actionSaveUser
/**
* Registers a new user, or saves an existing user's account settings.
*/
public function actionSaveUser()
{
$this->requirePostRequest();
if (Craft::hasPackage(CraftPackage::Users)) {
$userId = craft()->request->getPost('userId');
if ($userId) {
craft()->userSession->requireLogin();
}
} else {
craft()->userSession->requireLogin();
$userId = craft()->userSession->getUser()->id;
}
$publicRegistration = false;
$canRegisterUsers = false;
// Are we editing an existing user?
if ($userId) {
if ($userId != craft()->userSession->getUser()->id) {
craft()->userSession->requirePermission('editUsers');
}
$user = craft()->users->getUserById($userId);
if (!$user) {
throw new Exception(Craft::t('No user exists with the ID “{id}”.', array('id' => $userId)));
}
} else {
// Users package is required
Craft::requirePackage(CraftPackage::Users);
// Are they already logged in?
if (craft()->userSession->getUser()) {
// Make sure they have permission to register users, regardless of if public registration is enabled or not.
craft()->userSession->requirePermission('registerUsers');
$canRegisterUsers = true;
} else {
// Is public registration enabled?
if (craft()->systemSettings->getSetting('users', 'allowPublicRegistration', false)) {
$publicRegistration = true;
}
}
// If there is no public registration and the current user can't register users, complain loudly.
if (!$publicRegistration && !$canRegisterUsers) {
// Sorry pal.
throw new HttpException(403);
}
$user = new UserModel();
}
// Can only change sensitive fields if you are an admin or this is your account.
if (craft()->userSession->isAdmin() || $user->isCurrent()) {
// Validate stuff.
$valid = $this->_validateSensitiveFields($userId, $user, $publicRegistration || $canRegisterUsers);
} else {
$valid = true;
}
if ($valid) {
$userName = craft()->request->getPost('username');
if (!$userId) {
$user->email = craft()->request->getPost('email');
// If it is a new user, grab the password from post.
if (!$userId && !craft()->request->isCpRequest()) {
$user->newPassword = craft()->request->getPost('password');
}
}
// If no username was provided, set it to the email.
$userName = $userName == null ? $user->email : $userName;
$user->username = $userName;
$user->firstName = craft()->request->getPost('firstName');
$user->lastName = craft()->request->getPost('lastName');
$user->preferredLocale = craft()->request->getPost('preferredLocale');
// If it's a new user, set the verificationRequired bit.
if (!$user->id) {
$user->verificationRequired = true;
}
// Only admins can require users to reset their passwords
if (craft()->userSession->isAdmin()) {
$user->passwordResetRequired = (bool) craft()->request->getPost('passwordResetRequired');
}
try {
if (craft()->users->saveUser($user)) {
if ($publicRegistration) {
$this->_assignDefaultGroupToUser($user->id);
}
craft()->userSession->setNotice(Craft::t('User saved.'));
// TODO: Remove for 2.0
if (isset($_POST['redirect']) && strpos($_POST['redirect'], '{userId}') !== false) {
Craft::log('The {userId} token within the ‘redirect’ param on users/saveUser requests has been deprecated. Use {id} instead.', LogLevel::Warning);
$_POST['redirect'] = str_replace('{userId}', '{id}', $_POST['redirect']);
}
$this->redirectToPostedUrl($user);
} else {
craft()->userSession->setError(Craft::t('Couldn’t save user.'));
}
} catch (\phpmailerException $e) {
craft()->userSession->setError(Craft::t('Registered user, but couldn’t send activation email. Check your email settings.'));
// Still assign the default group
if (($publicRegistration || $canRegisterUsers) && !craft()->request->isCpRequest()) {
$this->_assignDefaultGroupToUser($user->id);
}
}
}
//.........这里部分代码省略.........
示例3: defineAttributes
<?php
namespace Craft;
/**
* Craft by Pixel & Tonic
*
* @package Craft
* @author Pixel & Tonic, Inc.
* @copyright Copyright (c) 2013, Pixel & Tonic, Inc.
* @license http://buildwithcraft.com/license Craft License Agreement
* @link http://buildwithcraft.com
*/
Craft::requirePackage(CraftPackage::PublishPro);
/**
*
*/
class EntryVersionModel extends EntryModel
{
/**
* @access protected
* @return array
*/
protected function defineAttributes()
{
$attributes = parent::defineAttributes();
$attributes['versionId'] = AttributeType::Number;
$attributes['creatorId'] = AttributeType::Number;
$attributes['notes'] = AttributeType::String;
$attributes['dateCreated'] = AttributeType::DateTime;
return $attributes;
示例4: array
<?php
namespace Craft;
/**
* Craft by Pixel & Tonic
*
* @package Craft
* @author Pixel & Tonic, Inc.
* @copyright Copyright (c) 2013, Pixel & Tonic, Inc.
* @license http://buildwithcraft.com/license Craft License Agreement
* @link http://buildwithcraft.com
*/
Craft::requirePackage(CraftPackage::Cloud);
/**
* S3 source type class
*/
class S3AssetSourceType extends BaseAssetSourceType
{
/**
* A list of predefined endpoints.
*
* @var array
*/
private static $_predefinedEndpoints = array('US' => 's3.amazonaws.com', 'EU' => 's3-eu-west-1.amazonaws.com');
/**
* @var \S3
*/
private $_s3;
/**
* Returns the name of the source type.
示例5: getTableName
<?php
namespace Craft;
/**
* Craft by Pixel & Tonic
*
* @package Craft
* @author Pixel & Tonic, Inc.
* @copyright Copyright (c) 2013, Pixel & Tonic, Inc.
* @license http://buildwithcraft.com/license1.0.html Craft License
* @link http://buildwithcraft.com
*/
Craft::requirePackage(CraftPackage::Rebrand);
/**
*
*/
class EmailMessageRecord extends BaseRecord
{
/**
* @return string
*/
public function getTableName()
{
return 'emailmessages';
}
/**
* @access protected
* @return array
*/
protected function defineAttributes()
示例6: saveProfile
/**
* Saves a user's profile.
*
* @param UserModel $user
* @return bool
*/
public function saveProfile(UserModel $user)
{
Craft::requirePackage(CraftPackage::Users);
$fieldLayout = craft()->fields->getLayoutByType(ElementType::User);
if (craft()->content->saveElementContent($user, $fieldLayout)) {
// Fire an 'onSaveProfile' event
$this->onSaveProfile(new Event($this, array('user' => $user)));
return true;
} else {
return false;
}
}
示例7: actionAddLocale
<?php
namespace Craft;
/**
* Craft by Pixel & Tonic
*
* @package Craft
* @author Pixel & Tonic, Inc.
* @copyright Copyright (c) 2013, Pixel & Tonic, Inc.
* @license http://buildwithcraft.com/license1.0.html Craft License
* @link http://buildwithcraft.com
*/
Craft::requirePackage(CraftPackage::Localize);
/**
* Handles localization actions.
*/
class LocalizationController extends BaseController
{
/**
* Adds a new a locale.
*/
public function actionAddLocale()
{
$this->requirePostRequest();
$this->requireAjaxRequest();
$locale = craft()->request->getRequiredPost('id');
$success = craft()->i18n->addSiteLocale($locale);
$this->returnJson(array('success' => $success));
}
/**
示例8: actionGetGoogleCloudBuckets
/**
* Get Google Cloud Storage buckets.
*/
public function actionGetGoogleCloudBuckets()
{
craft()->userSession->requireAdmin();
Craft::requirePackage(CraftPackage::Cloud);
$keyId = craft()->request->getRequiredPost('keyId');
$secret = craft()->request->getRequiredPost('secret');
try {
$this->returnJson(GoogleCloudAssetSourceType::getBucketList($keyId, $secret));
} catch (Exception $exception) {
$this->returnErrorJson($exception->getMessage());
}
}