本文整理匯總了PHP中Cake\Datasource\EntityInterface::toArray方法的典型用法代碼示例。如果您正苦於以下問題:PHP EntityInterface::toArray方法的具體用法?PHP EntityInterface::toArray怎麽用?PHP EntityInterface::toArray使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Cake\Datasource\EntityInterface
的用法示例。
在下文中一共展示了EntityInterface::toArray方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: resetPassword
/**
* Send the reset password email to the user
*
* @param EntityInterface $user User entity
* @param string $template string, note the first_name of the user will be prepended if exists
*
* @return array email send result
*/
protected function resetPassword(EntityInterface $user, $template = 'CakeDC/Users.reset_password')
{
$firstName = isset($user['first_name']) ? $user['first_name'] . ', ' : '';
$subject = __d('Users', '{0}Your reset password link', $firstName);
$user->hiddenProperties(['password', 'token_expires', 'api_token']);
$this->to($user['email'])->subject($subject)->viewVars($user->toArray())->template($template);
}
示例2: _sendEmail
/**
* Send the templated email to the user
*
* @param EntityInterface $user User entity
* @param string $subject Subject, note the first_name of the user will be prepended if exists
* @param Email $email instance, if null the default email configuration with the
* Users.validation template will be used, so set a ->template() if you pass an Email
* instance
*
* @return array email send result
*/
protected function _sendEmail(EntityInterface $user, $subject, Email $email = null)
{
$firstName = isset($user['first_name']) ? $user['first_name'] . ', ' : '';
$emailInstance = $this->_getEmailInstance($email)->to($user['email'])->subject($firstName . $subject)->viewVars($user->toArray());
if (empty($email)) {
$emailInstance->template('CakeDC/Users.validation');
}
return $emailInstance->send();
}
示例3: afterSaveCommit
public function afterSaveCommit(Event $event, EntityInterface $entity, \ArrayObject $options)
{
$rev = $this->_table->Revisions->newEntity();
unset($entity->revisions);
$rev->data = $entity->toArray();
$rev->ref = $this->_table->alias();
$rev->ref_id = $entity->id;
$this->_table->Revisions->save($rev);
}
示例4: beforeSave
/**
* beforeSave callback
*
* @param Event $event CakePHP Event
* @param Entity $entity Entity to be saved
* @param ArrayObject $options Additional options
* @return void
*/
public function beforeSave(Event $event, EntityInterface $entity, \ArrayObject $options)
{
if (!$entity->isNew() && $entity->dirty()) {
$fields = array_keys($entity->toArray());
$dirtyFields = $entity->extract($fields, true);
unset($dirtyFields['modified']);
$this->_dirtyFields[$entity->id] = array_keys($dirtyFields);
}
}
示例5: update_datetime_fields_timezone
/**
* When default server timezone is set as UTC (-> database stores dates as UTC) and the user's locale is not UTC, dates properties are updated in forms in the user's locale
* As CakePHP 3.0.0-alpha2 marshalls dates values sent from forms in the default locale UTC, the timezones must be corrected to be saved correctly
*
* Using this Listener allows to change the saved datetime timezones easily
*
* Usage:
* AppController:
*
* Configure::write('display_timezone', 'Europe/Zurich);
*
* UsersController:
*
* $this->Users->eventManager()->attach(new TimezoneEventListener());
*
* $user = $this->Users->patchEntity($user, $this->request->data);
*
* @param Event $event
* @param EntityInterface $entity
* @param unknown $options
* @param Validator $validator
* @return boolean
*/
public function update_datetime_fields_timezone(Event $event, EntityInterface $entity, $options = [], Validator $validator)
{
$display_timezone = isset($this->_config['display_timezone']) ? $this->_config['display_timezone'] : Configure::read('display_timezone');
$default_timezone = date_default_timezone_get();
if (!empty($display_timezone) && $display_timezone != $default_timezone) {
$data = $entity->toArray();
foreach ($data as $property => $value) {
if (!in_array($property, $this->_config['skipped_properties'])) {
$type = $event->subject()->schema()->columnType($property);
if ($type == 'datetime') {
if (is_a($data[$property], 'Cake\\I18n\\Time')) {
/*
* At this step, as the datetime has already been marshalled, the datetime has the value selected in the view, but its timezone is wrong
*
* Create a new Time object with the values from the saved datetime, but with the timezone used for display
*/
$timezoned_value = Time::create($data[$property]->year, $data[$property]->month, $data[$property]->day, $data[$property]->hour, $data[$property]->minute, $data[$property]->second, $display_timezone);
} elseif (is_array($data[$property])) {
/*
* Actually if the Listener is attached to 'Model.beforeValidate', we probably never fall here as the date array has already been marshalled
*/
$data[$property]['year'] = isset($data[$property]['year']) ? $data[$property]['year'] : null;
$data[$property]['month'] = isset($data[$property]['month']) ? $data[$property]['month'] : null;
$data[$property]['day'] = isset($data[$property]['day']) ? $data[$property]['day'] : null;
$data[$property]['hour'] = isset($data[$property]['hour']) ? $data[$property]['hour'] : null;
$data[$property]['minute'] = isset($data[$property]['minute']) ? $data[$property]['minute'] : null;
$data[$property]['second'] = isset($data[$property]['second']) ? $data[$property]['second'] : null;
$timezoned_value = Time::create($data[$property]['year'], $data[$property]['month'], $data[$property]['day'], $data[$property]['hour'], $data[$property]['minute'], $data[$property]['second'], $display_timezone);
}
if (isset($timezoned_value)) {
/*
* Transform the Time object to UTC timezone
*/
$timezoned_value->setTimezone($default_timezone);
$entity->set($property, $timezoned_value);
}
}
}
}
}
return true;
}
示例6: transform
public function transform(EntityInterface $entity)
{
return $entity->toArray();
}
示例7: sendResetPasswordEmail
/**
* Send the reset password email
*
* @param EntityInterface $user User entity
* @param Email $email instance, if null the default email configuration with the
* @param string $template email template
* Users.validation template will be used, so set a ->template() if you pass an Email
* instance
* @return array email send result
*/
public function sendResetPasswordEmail(EntityInterface $user, Email $email = null, $template = 'CakeDC/Users.reset_password')
{
$firstName = isset($user['first_name']) ? $user['first_name'] . ', ' : '';
$subject = __d('Users', '{0}Your reset password link', $firstName);
return $this->_getEmailInstance($email)->template($template)->to($user['email'])->subject($subject)->viewVars($user->toArray())->send();
}
示例8: _extractEntityWords
/**
* Extracts a list of words to by indexed for given entity.
*
* NOTE: Words can be repeated, this allows to search phrases.
*
* @param \Cake\Datasource\EntityInterface $entity The entity for which generate
* the list of words
* @return string Space-separated list of words. e.g. `cat dog this that`
*/
protected function _extractEntityWords(EntityInterface $entity)
{
$text = '';
$entityArray = $entity->toArray();
$entityArray = Hash::flatten($entityArray);
foreach ($entityArray as $key => $value) {
if (is_string($value) || is_numeric($value)) {
$text .= " {$value}";
}
}
$text = str_replace(["\n", "\r"], '', trim((string) $text));
// remove new lines
$text = strip_tags($text);
// remove HTML tags, but keep their content
$strict = $this->config('strict');
if (!empty($strict)) {
// only: space, digits (0-9), letters (any language), ".", ",", "-", "_", "/", "\"
$pattern = is_string($strict) ? $strict : '[^\\p{L}\\p{N}\\s\\@\\.\\,\\-\\_\\/\\0-9]';
$text = preg_replace('/' . $pattern . '/ui', ' ', $text);
}
$text = trim(preg_replace('/\\s{2,}/i', ' ', $text));
// remove double spaces
$text = mb_strtolower($text);
// all to lowercase
$text = $this->_filterText($text);
// filter
$text = iconv('UTF-8', 'UTF-8//IGNORE', mb_convert_encoding($text, 'UTF-8'));
// remove any invalid character
return trim($text);
}