code
stringlengths
17
247k
docstring
stringlengths
30
30.3k
func_name
stringlengths
1
89
language
stringclasses
1 value
repo
stringlengths
7
63
path
stringlengths
7
153
url
stringlengths
51
209
license
stringclasses
4 values
public function setReturnUrl($url) { Yii::$app->getSession()->set($this->returnUrlParam, $url); }
Remembers the URL in the session so that it can be retrieved back later by [[getReturnUrl()]]. @param string|array $url the URL that the user should be redirected to after login. If an array is given, [[UrlManager::createUrl()]] will be called to create the corresponding URL. The first element of the array should be the route, and the rest of the name-value pairs are GET parameters used to construct the URL. For example, ```php ['admin/index', 'ref' => 1] ```
setReturnUrl
php
yiisoft/yii2
framework/web/User.php
https://github.com/yiisoft/yii2/blob/master/framework/web/User.php
BSD-3-Clause
public function loginRequired($checkAjax = true, $checkAcceptHeader = true) { $request = Yii::$app->getRequest(); $canRedirect = !$checkAcceptHeader || $this->checkRedirectAcceptable(); if ( $this->enableSession && $request->getIsGet() && (!$checkAjax || !$request->getIsAjax()) && $canRedirect ) { $this->setReturnUrl($request->getAbsoluteUrl()); } if ($this->loginUrl !== null && $canRedirect) { $loginUrl = (array) $this->loginUrl; if ($loginUrl[0] !== Yii::$app->requestedRoute) { return Yii::$app->getResponse()->redirect($this->loginUrl); } } throw new ForbiddenHttpException(Yii::t('yii', 'Login Required')); }
Redirects the user browser to the login page. Before the redirection, the current URL (if it's not an AJAX url) will be kept as [[returnUrl]] so that the user browser may be redirected back to the current page after successful login. Make sure you set [[loginUrl]] so that the user browser can be redirected to the specified login URL after calling this method. Note that when [[loginUrl]] is set, calling this method will NOT terminate the application execution. @param bool $checkAjax whether to check if the request is an AJAX request. When this is true and the request is an AJAX request, the current URL (for AJAX request) will NOT be set as the return URL. @param bool $checkAcceptHeader whether to check if the request accepts HTML responses. Defaults to `true`. When this is true and the request does not accept HTML responses the current URL will not be SET as the return URL. Also instead of redirecting the user an ForbiddenHttpException is thrown. This parameter is available since version 2.0.8. @return Response the redirection response if [[loginUrl]] is set @throws ForbiddenHttpException the "Access Denied" HTTP exception if [[loginUrl]] is not set or a redirect is not applicable.
loginRequired
php
yiisoft/yii2
framework/web/User.php
https://github.com/yiisoft/yii2/blob/master/framework/web/User.php
BSD-3-Clause
protected function beforeLogin($identity, $cookieBased, $duration) { $event = new UserEvent([ 'identity' => $identity, 'cookieBased' => $cookieBased, 'duration' => $duration, ]); $this->trigger(self::EVENT_BEFORE_LOGIN, $event); return $event->isValid; }
This method is called before logging in a user. The default implementation will trigger the [[EVENT_BEFORE_LOGIN]] event. If you override this method, make sure you call the parent implementation so that the event is triggered. @param IdentityInterface $identity the user identity information @param bool $cookieBased whether the login is cookie-based @param int $duration number of seconds that the user can remain in logged-in status. If 0, it means login till the user closes the browser or the session is manually destroyed. @return bool whether the user should continue to be logged in
beforeLogin
php
yiisoft/yii2
framework/web/User.php
https://github.com/yiisoft/yii2/blob/master/framework/web/User.php
BSD-3-Clause
protected function afterLogin($identity, $cookieBased, $duration) { $this->trigger(self::EVENT_AFTER_LOGIN, new UserEvent([ 'identity' => $identity, 'cookieBased' => $cookieBased, 'duration' => $duration, ])); }
This method is called after the user is successfully logged in. The default implementation will trigger the [[EVENT_AFTER_LOGIN]] event. If you override this method, make sure you call the parent implementation so that the event is triggered. @param IdentityInterface $identity the user identity information @param bool $cookieBased whether the login is cookie-based @param int $duration number of seconds that the user can remain in logged-in status. If 0, it means login till the user closes the browser or the session is manually destroyed.
afterLogin
php
yiisoft/yii2
framework/web/User.php
https://github.com/yiisoft/yii2/blob/master/framework/web/User.php
BSD-3-Clause
protected function beforeLogout($identity) { $event = new UserEvent([ 'identity' => $identity, ]); $this->trigger(self::EVENT_BEFORE_LOGOUT, $event); return $event->isValid; }
This method is invoked when calling [[logout()]] to log out a user. The default implementation will trigger the [[EVENT_BEFORE_LOGOUT]] event. If you override this method, make sure you call the parent implementation so that the event is triggered. @param IdentityInterface $identity the user identity information @return bool whether the user should continue to be logged out
beforeLogout
php
yiisoft/yii2
framework/web/User.php
https://github.com/yiisoft/yii2/blob/master/framework/web/User.php
BSD-3-Clause
protected function afterLogout($identity) { $this->trigger(self::EVENT_AFTER_LOGOUT, new UserEvent([ 'identity' => $identity, ])); }
This method is invoked right after a user is logged out via [[logout()]]. The default implementation will trigger the [[EVENT_AFTER_LOGOUT]] event. If you override this method, make sure you call the parent implementation so that the event is triggered. @param IdentityInterface $identity the user identity information
afterLogout
php
yiisoft/yii2
framework/web/User.php
https://github.com/yiisoft/yii2/blob/master/framework/web/User.php
BSD-3-Clause
protected function renewIdentityCookie() { $name = $this->identityCookie['name']; $value = Yii::$app->getRequest()->getCookies()->getValue($name); if ($value !== null) { $data = json_decode($value, true); if (is_array($data) && isset($data[2])) { $cookie = Yii::createObject(array_merge($this->identityCookie, [ 'class' => 'yii\web\Cookie', 'value' => $value, 'expire' => time() + (int) $data[2], ])); Yii::$app->getResponse()->getCookies()->add($cookie); } } }
Renews the identity cookie. This method will set the expiration time of the identity cookie to be the current time plus the originally specified cookie duration.
renewIdentityCookie
php
yiisoft/yii2
framework/web/User.php
https://github.com/yiisoft/yii2/blob/master/framework/web/User.php
BSD-3-Clause
protected function sendIdentityCookie($identity, $duration) { $cookie = Yii::createObject(array_merge($this->identityCookie, [ 'class' => 'yii\web\Cookie', 'value' => json_encode([ $identity->getId(), $identity->getAuthKey(), $duration, ], JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE), 'expire' => time() + $duration, ])); Yii::$app->getResponse()->getCookies()->add($cookie); }
Sends an identity cookie. This method is used when [[enableAutoLogin]] is true. It saves [[id]], [[IdentityInterface::getAuthKey()|auth key]], and the duration of cookie-based login information in the cookie. @param IdentityInterface $identity @param int $duration number of seconds that the user can remain in logged-in status. @see loginByCookie()
sendIdentityCookie
php
yiisoft/yii2
framework/web/User.php
https://github.com/yiisoft/yii2/blob/master/framework/web/User.php
BSD-3-Clause
protected function removeIdentityCookie() { Yii::$app->getResponse()->getCookies()->remove(Yii::createObject(array_merge($this->identityCookie, [ 'class' => 'yii\web\Cookie', ]))); }
Removes the identity cookie. This method is used when [[enableAutoLogin]] is true. @since 2.0.9
removeIdentityCookie
php
yiisoft/yii2
framework/web/User.php
https://github.com/yiisoft/yii2/blob/master/framework/web/User.php
BSD-3-Clause
public function switchIdentity($identity, $duration = 0) { $this->setIdentity($identity); if (!$this->enableSession) { return; } /* Ensure any existing identity cookies are removed. */ if ($this->enableAutoLogin && ($this->autoRenewCookie || $identity === null)) { $this->removeIdentityCookie(); } $session = Yii::$app->getSession(); $session->regenerateID(true); $session->remove($this->idParam); $session->remove($this->authTimeoutParam); $session->remove($this->authKeyParam); if ($identity) { $session->set($this->idParam, $identity->getId()); $session->set($this->authKeyParam, $identity->getAuthKey()); if ($this->authTimeout !== null) { $session->set($this->authTimeoutParam, time() + $this->authTimeout); } if ($this->absoluteAuthTimeout !== null) { $session->set($this->absoluteAuthTimeoutParam, time() + $this->absoluteAuthTimeout); } if ($this->enableAutoLogin && $duration > 0) { $this->sendIdentityCookie($identity, $duration); } } }
Switches to a new identity for the current user. When [[enableSession]] is true, this method may use session and/or cookie to store the user identity information, according to the value of `$duration`. Please refer to [[login()]] for more details. This method is mainly called by [[login()]], [[logout()]] and [[loginByCookie()]] when the current user needs to be associated with the corresponding identity information. @param IdentityInterface|null $identity the identity information to be associated with the current user. If null, it means switching the current user to be a guest. @param int $duration number of seconds that the user can remain in logged-in status. This parameter is used only when `$identity` is not null.
switchIdentity
php
yiisoft/yii2
framework/web/User.php
https://github.com/yiisoft/yii2/blob/master/framework/web/User.php
BSD-3-Clause
public function can($permissionName, $params = [], $allowCaching = true) { if ($allowCaching && empty($params) && isset($this->_access[$permissionName])) { return $this->_access[$permissionName]; } if (($accessChecker = $this->getAccessChecker()) === null) { return false; } $access = $accessChecker->checkAccess($this->getId(), $permissionName, $params); if ($allowCaching && empty($params)) { $this->_access[$permissionName] = $access; } return $access; }
Checks if the user can perform the operation as specified by the given permission. Note that you must configure "authManager" application component in order to use this method. Otherwise it will always return false. @param string $permissionName the name of the permission (e.g. "edit post") that needs access check. @param array $params name-value pairs that would be passed to the rules associated with the roles and permissions assigned to the user. @param bool $allowCaching whether to allow caching the result of access check. When this parameter is true (default), if the access check of an operation was performed before, its result will be directly returned when calling this method to check the same operation. If this parameter is false, this method will always call [[\yii\rbac\CheckAccessInterface::checkAccess()]] to obtain the up-to-date access result. Note that this caching is effective only within the same request and only works when `$params = []`. @return bool whether the user can perform the operation as specified by the given permission.
can
php
yiisoft/yii2
framework/web/User.php
https://github.com/yiisoft/yii2/blob/master/framework/web/User.php
BSD-3-Clause
public function checkRedirectAcceptable() { $acceptableTypes = Yii::$app->getRequest()->getAcceptableContentTypes(); if (empty($acceptableTypes) || (count($acceptableTypes) === 1 && array_keys($acceptableTypes)[0] === '*/*')) { return true; } foreach ($acceptableTypes as $type => $params) { if (in_array($type, $this->acceptableRedirectTypes, true)) { return true; } } return false; }
Checks if the `Accept` header contains a content type that allows redirection to the login page. The login page is assumed to serve `text/html` or `application/xhtml+xml` by default. You can change acceptable content types by modifying [[acceptableRedirectTypes]] property. @return bool whether this request may be redirected to the login page. @see acceptableRedirectTypes @since 2.0.8
checkRedirectAcceptable
php
yiisoft/yii2
framework/web/User.php
https://github.com/yiisoft/yii2/blob/master/framework/web/User.php
BSD-3-Clause
protected function getAuthManager() { return Yii::$app->getAuthManager(); }
Returns auth manager associated with the user component. By default this is the `authManager` application component. You may override this method to return a different auth manager instance if needed. @return \yii\rbac\ManagerInterface @since 2.0.6 @deprecated since version 2.0.9, to be removed in 2.1. Use [[getAccessChecker()]] instead.
getAuthManager
php
yiisoft/yii2
framework/web/User.php
https://github.com/yiisoft/yii2/blob/master/framework/web/User.php
BSD-3-Clause
protected function getAccessChecker() { return $this->accessChecker !== null ? $this->accessChecker : $this->getAuthManager(); }
Returns the access checker used for checking access. @return CheckAccessInterface @since 2.0.9
getAccessChecker
php
yiisoft/yii2
framework/web/User.php
https://github.com/yiisoft/yii2/blob/master/framework/web/User.php
BSD-3-Clause
public function __construct($cookies = [], $config = []) { $this->_cookies = $cookies; parent::__construct($config); }
Constructor. @param array $cookies the cookies that this collection initially contains. This should be an array of name-value pairs. @param array $config name-value pairs that will be used to initialize the object properties
__construct
php
yiisoft/yii2
framework/web/CookieCollection.php
https://github.com/yiisoft/yii2/blob/master/framework/web/CookieCollection.php
BSD-3-Clause
public function getIterator() { return new ArrayIterator($this->_cookies); }
Returns an iterator for traversing the cookies in the collection. This method is required by the SPL interface [[\IteratorAggregate]]. It will be implicitly called when you use `foreach` to traverse the collection. @return ArrayIterator<string, Cookie> an iterator for traversing the cookies in the collection.
getIterator
php
yiisoft/yii2
framework/web/CookieCollection.php
https://github.com/yiisoft/yii2/blob/master/framework/web/CookieCollection.php
BSD-3-Clause
public function getCount() { return count($this->_cookies); }
Returns the number of cookies in the collection. @return int the number of cookies in the collection.
getCount
php
yiisoft/yii2
framework/web/CookieCollection.php
https://github.com/yiisoft/yii2/blob/master/framework/web/CookieCollection.php
BSD-3-Clause
public function get($name) { return isset($this->_cookies[$name]) ? $this->_cookies[$name] : null; }
Returns the cookie with the specified name. @param string $name the cookie name @return Cookie|null the cookie with the specified name. Null if the named cookie does not exist. @see getValue()
get
php
yiisoft/yii2
framework/web/CookieCollection.php
https://github.com/yiisoft/yii2/blob/master/framework/web/CookieCollection.php
BSD-3-Clause
public function getValue($name, $defaultValue = null) { return isset($this->_cookies[$name]) ? $this->_cookies[$name]->value : $defaultValue; }
Returns the value of the named cookie. @param string $name the cookie name @param mixed $defaultValue the value that should be returned when the named cookie does not exist. @return mixed the value of the named cookie. @see get()
getValue
php
yiisoft/yii2
framework/web/CookieCollection.php
https://github.com/yiisoft/yii2/blob/master/framework/web/CookieCollection.php
BSD-3-Clause
public function has($name) { return isset($this->_cookies[$name]) && $this->_cookies[$name]->value !== '' && ($this->_cookies[$name]->expire === null || $this->_cookies[$name]->expire === 0 || ( (is_string($this->_cookies[$name]->expire) && strtotime($this->_cookies[$name]->expire) >= time()) || ( interface_exists('\\DateTimeInterface') && $this->_cookies[$name]->expire instanceof \DateTimeInterface && $this->_cookies[$name]->expire->getTimestamp() >= time() ) || $this->_cookies[$name]->expire >= time() ) ); }
Returns whether there is a cookie with the specified name. Note that if a cookie is marked for deletion from browser or its value is an empty string, this method will return false. @param string $name the cookie name @return bool whether the named cookie exists @see remove()
has
php
yiisoft/yii2
framework/web/CookieCollection.php
https://github.com/yiisoft/yii2/blob/master/framework/web/CookieCollection.php
BSD-3-Clause
public function add($cookie) { if ($this->readOnly) { throw new InvalidCallException('The cookie collection is read only.'); } $this->_cookies[$cookie->name] = $cookie; }
Adds a cookie to the collection. If there is already a cookie with the same name in the collection, it will be removed first. @param Cookie $cookie the cookie to be added @throws InvalidCallException if the cookie collection is read only
add
php
yiisoft/yii2
framework/web/CookieCollection.php
https://github.com/yiisoft/yii2/blob/master/framework/web/CookieCollection.php
BSD-3-Clause
public function remove($cookie, $removeFromBrowser = true) { if ($this->readOnly) { throw new InvalidCallException('The cookie collection is read only.'); } if ($cookie instanceof Cookie) { $cookie->expire = 1; $cookie->value = ''; } else { $cookie = Yii::createObject([ 'class' => 'yii\web\Cookie', 'name' => $cookie, 'expire' => 1, ]); } if ($removeFromBrowser) { $this->_cookies[$cookie->name] = $cookie; } else { unset($this->_cookies[$cookie->name]); } }
Removes a cookie. If `$removeFromBrowser` is true, the cookie will be removed from the browser. In this case, a cookie with outdated expiry will be added to the collection. @param Cookie|string $cookie the cookie object or the name of the cookie to be removed. @param bool $removeFromBrowser whether to remove the cookie from browser @throws InvalidCallException if the cookie collection is read only
remove
php
yiisoft/yii2
framework/web/CookieCollection.php
https://github.com/yiisoft/yii2/blob/master/framework/web/CookieCollection.php
BSD-3-Clause
public function toArray() { return $this->_cookies; }
Returns the collection as a PHP array. @return Cookie[] the array representation of the collection. The array keys are cookie names, and the array values are the corresponding cookie objects.
toArray
php
yiisoft/yii2
framework/web/CookieCollection.php
https://github.com/yiisoft/yii2/blob/master/framework/web/CookieCollection.php
BSD-3-Clause
public function fromArray(array $array) { $this->_cookies = $array; }
Populates the cookie collection from an array. @param array $array the cookies to populate from @since 2.0.3
fromArray
php
yiisoft/yii2
framework/web/CookieCollection.php
https://github.com/yiisoft/yii2/blob/master/framework/web/CookieCollection.php
BSD-3-Clause
public function offsetSet($name, $cookie) { $this->add($cookie); }
Adds the cookie to the collection. This method is required by the SPL interface [[\ArrayAccess]]. It is implicitly called when you use something like `$collection[$name] = $cookie;`. This is equivalent to [[add()]]. @param string $name the cookie name @param Cookie $cookie the cookie to be added
offsetSet
php
yiisoft/yii2
framework/web/CookieCollection.php
https://github.com/yiisoft/yii2/blob/master/framework/web/CookieCollection.php
BSD-3-Clause
public function toOriginalArray() { return \array_map(function ($normalizedName) { return $this->_headers[$normalizedName]; }, \array_flip($this->_originalHeaderNames)); }
Returns the collection as a PHP array but instead of using normalized header names as keys (like [[toArray()]]) it uses original header names (case-sensitive). @return array the array representation of the collection. @since 2.0.45
toOriginalArray
php
yiisoft/yii2
framework/web/HeaderCollection.php
https://github.com/yiisoft/yii2/blob/master/framework/web/HeaderCollection.php
BSD-3-Clause
public function send(?MailerInterface $mailer = null) { if ($mailer === null && $this->mailer === null) { $mailer = Yii::$app->getMailer(); } elseif ($mailer === null) { $mailer = $this->mailer; } return $mailer->send($this); }
Sends this email message. @param MailerInterface|null $mailer the mailer that should be used to send this message. If no mailer is given it will first check if [[mailer]] is set and if not, the "mailer" application component will be used instead. @return bool whether this message is sent successfully.
send
php
yiisoft/yii2
framework/mail/BaseMessage.php
https://github.com/yiisoft/yii2/blob/master/framework/mail/BaseMessage.php
BSD-3-Clause
protected function createView(array $config) { if (!array_key_exists('class', $config)) { $config['class'] = View::className(); } return Yii::createObject($config); }
Creates view instance from given configuration. @param array $config view configuration. @return View view instance.
createView
php
yiisoft/yii2
framework/mail/BaseMailer.php
https://github.com/yiisoft/yii2/blob/master/framework/mail/BaseMailer.php
BSD-3-Clause
protected function createMessage() { $config = $this->messageConfig; if (!array_key_exists('class', $config)) { $config['class'] = $this->messageClass; } $config['mailer'] = $this; return Yii::createObject($config); }
Creates a new message instance. The newly created instance will be initialized with the configuration specified by [[messageConfig]]. If the configuration does not specify a 'class', the [[messageClass]] will be used as the class of the new message instance. @return MessageInterface message instance.
createMessage
php
yiisoft/yii2
framework/mail/BaseMailer.php
https://github.com/yiisoft/yii2/blob/master/framework/mail/BaseMailer.php
BSD-3-Clause
public function send($message) { if (!$this->beforeSend($message)) { return false; } $address = $message->getTo(); if (is_array($address)) { $address = implode(', ', array_keys($address)); } Yii::info('Sending email "' . $message->getSubject() . '" to "' . $address . '"', __METHOD__); if ($this->useFileTransport) { $isSuccessful = $this->saveMessage($message); } else { $isSuccessful = $this->sendMessage($message); } $this->afterSend($message, $isSuccessful); return $isSuccessful; }
Sends the given email message. This method will log a message about the email being sent. If [[useFileTransport]] is true, it will save the email as a file under [[fileTransportPath]]. Otherwise, it will call [[sendMessage()]] to send the email to its recipient(s). Child classes should implement [[sendMessage()]] with the actual email sending logic. @param MessageInterface $message email message instance to be sent @return bool whether the message has been sent successfully
send
php
yiisoft/yii2
framework/mail/BaseMailer.php
https://github.com/yiisoft/yii2/blob/master/framework/mail/BaseMailer.php
BSD-3-Clause
public function sendMultiple(array $messages) { $successCount = 0; foreach ($messages as $message) { if ($this->send($message)) { $successCount++; } } return $successCount; }
Sends multiple messages at once. The default implementation simply calls [[send()]] multiple times. Child classes may override this method to implement more efficient way of sending multiple messages. @param array $messages list of email messages, which should be sent. @return int number of messages that are successfully sent.
sendMultiple
php
yiisoft/yii2
framework/mail/BaseMailer.php
https://github.com/yiisoft/yii2/blob/master/framework/mail/BaseMailer.php
BSD-3-Clause
protected function saveMessage($message) { $path = Yii::getAlias($this->fileTransportPath); if (!is_dir($path)) { mkdir($path, 0777, true); } if ($this->fileTransportCallback !== null) { $file = $path . '/' . call_user_func($this->fileTransportCallback, $this, $message); } else { $file = $path . '/' . $this->generateMessageFileName(); } file_put_contents($file, $message->toString()); return true; }
Saves the message as a file under [[fileTransportPath]]. @param MessageInterface $message @return bool whether the message is saved successfully
saveMessage
php
yiisoft/yii2
framework/mail/BaseMailer.php
https://github.com/yiisoft/yii2/blob/master/framework/mail/BaseMailer.php
BSD-3-Clause
public function beforeSend($message) { $event = new MailEvent(['message' => $message]); $this->trigger(self::EVENT_BEFORE_SEND, $event); return $event->isValid; }
This method is invoked right before mail send. You may override this method to do last-minute preparation for the message. If you override this method, please make sure you call the parent implementation first. @param MessageInterface $message @return bool whether to continue sending an email.
beforeSend
php
yiisoft/yii2
framework/mail/BaseMailer.php
https://github.com/yiisoft/yii2/blob/master/framework/mail/BaseMailer.php
BSD-3-Clause
public function log($message, $level, $category = 'application') { $time = microtime(true); $traces = []; if ($this->traceLevel > 0) { $count = 0; $ts = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS); array_pop($ts); // remove the last trace since it would be the entry script, not very useful foreach ($ts as $trace) { if (isset($trace['file'], $trace['line']) && strpos($trace['file'], YII2_PATH) !== 0) { unset($trace['object'], $trace['args']); $traces[] = $trace; if (++$count >= $this->traceLevel) { break; } } } } $data = [$message, $level, $category, $time, $traces, memory_get_usage()]; if ($this->profilingAware && in_array($level, [self::LEVEL_PROFILE_BEGIN, self::LEVEL_PROFILE_END])) { $this->messages[($level == self::LEVEL_PROFILE_BEGIN ? 'begin-' : 'end-') . md5(json_encode($message))] = $data; } else { $this->messages[] = $data; } if ($this->flushInterval > 0 && count($this->messages) >= $this->flushInterval) { $this->flush(); } }
Logs a message with the given type and category. If [[traceLevel]] is greater than 0, additional call stack information about the application code will be logged as well. @param string|array $message the message to be logged. This can be a simple string or a more complex data structure that will be handled by a [[Target|log target]]. @param int $level the level of the message. This must be one of the following: `Logger::LEVEL_ERROR`, `Logger::LEVEL_WARNING`, `Logger::LEVEL_INFO`, `Logger::LEVEL_TRACE`, `Logger::LEVEL_PROFILE`, `Logger::LEVEL_PROFILE_BEGIN`, `Logger::LEVEL_PROFILE_END`. @param string $category the category of the message.
log
php
yiisoft/yii2
framework/log/Logger.php
https://github.com/yiisoft/yii2/blob/master/framework/log/Logger.php
BSD-3-Clause
public function getLogger() { if ($this->_logger === null) { $this->setLogger(Yii::getLogger()); } return $this->_logger; }
Gets the connected logger. If not set, [[Yii::getLogger()]] will be used. @property Logger the logger. If not set, [[Yii::getLogger()]] will be used. @return Logger the logger.
getLogger
php
yiisoft/yii2
framework/log/Dispatcher.php
https://github.com/yiisoft/yii2/blob/master/framework/log/Dispatcher.php
BSD-3-Clause
public function setLogger($value) { if (is_string($value) || is_array($value)) { $value = Yii::createObject($value); } $this->_logger = $value; $this->_logger->dispatcher = $this; }
Sets the connected logger. @param Logger|string|array $value the logger to be used. This can either be a logger instance or a configuration that will be used to create one using [[Yii::createObject()]]. If you are providing custom logger configuration and would like it to be used for the whole application and not just for the dispatcher you should use [[Yii::setLogger()]] instead.
setLogger
php
yiisoft/yii2
framework/log/Dispatcher.php
https://github.com/yiisoft/yii2/blob/master/framework/log/Dispatcher.php
BSD-3-Clause
public function getTraceLevel() { return $this->getLogger()->traceLevel; }
@return int how many application call stacks should be logged together with each message. This method returns the value of [[Logger::traceLevel]]. Defaults to 0.
getTraceLevel
php
yiisoft/yii2
framework/log/Dispatcher.php
https://github.com/yiisoft/yii2/blob/master/framework/log/Dispatcher.php
BSD-3-Clause
public function setTraceLevel($value) { $this->getLogger()->traceLevel = $value; }
@param int $value how many application call stacks should be logged together with each message. This method will set the value of [[Logger::traceLevel]]. If the value is greater than 0, at most that number of call stacks will be logged. Note that only application call stacks are counted. Defaults to 0.
setTraceLevel
php
yiisoft/yii2
framework/log/Dispatcher.php
https://github.com/yiisoft/yii2/blob/master/framework/log/Dispatcher.php
BSD-3-Clause
public function getFlushInterval() { return $this->getLogger()->flushInterval; }
@return int how many messages should be logged before they are sent to targets. This method returns the value of [[Logger::flushInterval]].
getFlushInterval
php
yiisoft/yii2
framework/log/Dispatcher.php
https://github.com/yiisoft/yii2/blob/master/framework/log/Dispatcher.php
BSD-3-Clause
public function setFlushInterval($value) { $this->getLogger()->flushInterval = $value; }
@param int $value how many messages should be logged before they are sent to targets. This method will set the value of [[Logger::flushInterval]]. Defaults to 1000, meaning the [[Logger::flush()]] method will be invoked once every 1000 messages logged. Set this property to be 0 if you don't want to flush messages until the application terminates. This property mainly affects how much memory will be taken by the logged messages. A smaller value means less memory, but will increase the execution time due to the overhead of [[Logger::flush()]].
setFlushInterval
php
yiisoft/yii2
framework/log/Dispatcher.php
https://github.com/yiisoft/yii2/blob/master/framework/log/Dispatcher.php
BSD-3-Clause
public function dispatch($messages, $final) { $targetErrors = []; foreach ($this->targets as $target) { if (!$target->enabled) { continue; } try { $target->collect($messages, $final); } catch (\Throwable $t) { $target->enabled = false; $targetErrors[] = $this->generateTargetFailErrorMessage($target, $t, __METHOD__); } catch (\Exception $e) { $target->enabled = false; $targetErrors[] = $this->generateTargetFailErrorMessage($target, $e, __METHOD__); } } if (!empty($targetErrors)) { $this->dispatch($targetErrors, true); } }
Dispatches the logged messages to [[targets]]. @param array $messages the logged messages @param bool $final whether this method is called at the end of the current application
dispatch
php
yiisoft/yii2
framework/log/Dispatcher.php
https://github.com/yiisoft/yii2/blob/master/framework/log/Dispatcher.php
BSD-3-Clause
public static function transliterate($string, $transliterator = null) { if (empty($string)) { return (string) $string; } if (static::hasIntl()) { if ($transliterator === null) { $transliterator = static::$transliterator; } return transliterator_transliterate($transliterator, $string); } return strtr($string, static::$transliteration); }
Returns transliterated version of a string. If intl extension isn't available uses fallback that converts latin characters only and removes the rest. You may customize characters map via $transliteration property of the helper. @param string $string input string @param string|\Transliterator|null $transliterator either a [[\Transliterator]] or a string from which a [[\Transliterator]] can be built. @return string @since 2.0.7 this method is public.
transliterate
php
yiisoft/yii2
framework/helpers/BaseInflector.php
https://github.com/yiisoft/yii2/blob/master/framework/helpers/BaseInflector.php
BSD-3-Clause
public static function keyExists($key, $array, $caseSensitive = true) { // ToDo: This check can be removed when the minimum PHP version is >= 8.1 (Yii2.2) if (is_float($key)) { $key = (int)$key; } if ($caseSensitive) { if (is_array($array) && array_key_exists($key, $array)) { return true; } // Cannot use `array_has_key` on Objects for PHP 7.4+, therefore we need to check using [[ArrayAccess::offsetExists()]] return $array instanceof ArrayAccess && $array->offsetExists($key); } if ($array instanceof ArrayAccess) { throw new InvalidArgumentException('Second parameter($array) cannot be ArrayAccess in case insensitive mode'); } foreach (array_keys($array) as $k) { if (strcasecmp($key, $k) === 0) { return true; } } return false; }
Checks if the given array contains the specified key. This method enhances the `array_key_exists()` function by supporting case-insensitive key comparison. @param string|int $key the key to check @param array|ArrayAccess $array the array with keys to check @param bool $caseSensitive whether the key comparison should be case-sensitive @return bool whether the array contains the specified key
keyExists
php
yiisoft/yii2
framework/helpers/BaseArrayHelper.php
https://github.com/yiisoft/yii2/blob/master/framework/helpers/BaseArrayHelper.php
BSD-3-Clause
public static function isIn($needle, $haystack, $strict = false) { if (!static::isTraversable($haystack)) { throw new InvalidArgumentException('Argument $haystack must be an array or implement Traversable'); } if (is_array($haystack)) { return in_array($needle, $haystack, $strict); } foreach ($haystack as $value) { if ($strict ? $needle === $value : $needle == $value) { return true; } } return false; }
Check whether an array or [[Traversable]] contains an element. This method does the same as the PHP function [in_array()](https://www.php.net/manual/en/function.in-array.php) but additionally works for objects that implement the [[Traversable]] interface. @param mixed $needle The value to look for. @param iterable $haystack The set of values to search. @param bool $strict Whether to enable strict (`===`) comparison. @return bool `true` if `$needle` was found in `$haystack`, `false` otherwise. @throws InvalidArgumentException if `$haystack` is neither traversable nor an array. @see https://www.php.net/manual/en/function.in-array.php @since 2.0.7
isIn
php
yiisoft/yii2
framework/helpers/BaseArrayHelper.php
https://github.com/yiisoft/yii2/blob/master/framework/helpers/BaseArrayHelper.php
BSD-3-Clause
public static function isSubset($needles, $haystack, $strict = false) { if (!static::isTraversable($needles)) { throw new InvalidArgumentException('Argument $needles must be an array or implement Traversable'); } foreach ($needles as $needle) { if (!static::isIn($needle, $haystack, $strict)) { return false; } } return true; }
Checks whether an array or [[Traversable]] is a subset of another array or [[Traversable]]. This method will return `true`, if all elements of `$needles` are contained in `$haystack`. If at least one element is missing, `false` will be returned. @param iterable $needles The values that must **all** be in `$haystack`. @param iterable $haystack The set of value to search. @param bool $strict Whether to enable strict (`===`) comparison. @return bool `true` if `$needles` is a subset of `$haystack`, `false` otherwise. @throws InvalidArgumentException if `$haystack` or `$needles` is neither traversable nor an array. @since 2.0.7
isSubset
php
yiisoft/yii2
framework/helpers/BaseArrayHelper.php
https://github.com/yiisoft/yii2/blob/master/framework/helpers/BaseArrayHelper.php
BSD-3-Clause
public static function getIpVersion($ip) { return strpos($ip, ':') === false ? self::IPV4 : self::IPV6; }
Gets the IP version. Does not perform IP address validation. @param string $ip the valid IPv4 or IPv6 address. @return int [[IPV4]] or [[IPV6]]
getIpVersion
php
yiisoft/yii2
framework/helpers/BaseIpHelper.php
https://github.com/yiisoft/yii2/blob/master/framework/helpers/BaseIpHelper.php
BSD-3-Clause
public static function inRange($subnet, $range) { list($ip, $mask) = array_pad(explode('/', $subnet), 2, null); list($net, $netMask) = array_pad(explode('/', $range), 2, null); $ipVersion = static::getIpVersion($ip); $netVersion = static::getIpVersion($net); if ($ipVersion !== $netVersion) { return false; } $maxMask = $ipVersion === self::IPV4 ? self::IPV4_ADDRESS_LENGTH : self::IPV6_ADDRESS_LENGTH; $mask = isset($mask) ? $mask : $maxMask; $netMask = isset($netMask) ? $netMask : $maxMask; $binIp = static::ip2bin($ip); $binNet = static::ip2bin($net); return substr($binIp, 0, $netMask) === substr($binNet, 0, $netMask) && $mask >= $netMask; }
Checks whether IP address or subnet $subnet is contained by $subnet. For example, the following code checks whether subnet `192.168.1.0/24` is in subnet `192.168.0.0/22`: ```php IpHelper::inRange('192.168.1.0/24', '192.168.0.0/22'); // true ``` In case you need to check whether a single IP address `192.168.1.21` is in the subnet `192.168.1.0/24`, you can use any of theses examples: ```php IpHelper::inRange('192.168.1.21', '192.168.1.0/24'); // true IpHelper::inRange('192.168.1.21/32', '192.168.1.0/24'); // true ``` @param string $subnet the valid IPv4 or IPv6 address or CIDR range, e.g.: `10.0.0.0/8` or `2001:af::/64` @param string $range the valid IPv4 or IPv6 CIDR range, e.g. `10.0.0.0/8` or `2001:af::/64` @return bool whether $subnet is contained by $range @throws NotSupportedException @see https://en.wikipedia.org/wiki/Classless_Inter-Domain_Routing
inRange
php
yiisoft/yii2
framework/helpers/BaseIpHelper.php
https://github.com/yiisoft/yii2/blob/master/framework/helpers/BaseIpHelper.php
BSD-3-Clause
public static function expandIPv6($ip) { $hex = unpack('H*hex', inet_pton($ip)); return substr(preg_replace('/([a-f0-9]{4})/i', '$1:', $hex['hex']), 0, -1); }
Expands an IPv6 address to it's full notation. For example `2001:db8::1` will be expanded to `2001:0db8:0000:0000:0000:0000:0000:0001` @param string $ip the original valid IPv6 address @return string the expanded IPv6 address
expandIPv6
php
yiisoft/yii2
framework/helpers/BaseIpHelper.php
https://github.com/yiisoft/yii2/blob/master/framework/helpers/BaseIpHelper.php
BSD-3-Clause
public static function encode($content, $doubleEncode = true) { return htmlspecialchars((string)$content, ENT_QUOTES | ENT_SUBSTITUTE, Yii::$app ? Yii::$app->charset : 'UTF-8', $doubleEncode); }
Encodes special characters into HTML entities. The [[\yii\base\Application::charset|application charset]] will be used for encoding. @param string $content the content to be encoded @param bool $doubleEncode whether to encode HTML entities in `$content`. If false, HTML entities in `$content` will not be further encoded. @return string the encoded content @see decode() @see https://www.php.net/manual/en/function.htmlspecialchars.php
encode
php
yiisoft/yii2
framework/helpers/BaseHtml.php
https://github.com/yiisoft/yii2/blob/master/framework/helpers/BaseHtml.php
BSD-3-Clause
public static function decode($content) { return htmlspecialchars_decode($content, ENT_QUOTES); }
Decodes special HTML entities back to the corresponding characters. This is the opposite of [[encode()]]. @param string $content the content to be decoded @return string the decoded content @see encode() @see https://www.php.net/manual/en/function.htmlspecialchars-decode.php
decode
php
yiisoft/yii2
framework/helpers/BaseHtml.php
https://github.com/yiisoft/yii2/blob/master/framework/helpers/BaseHtml.php
BSD-3-Clause
public static function tag($name, $content = '', $options = []) { if ($name === null || $name === false) { return $content; } $html = "<$name" . static::renderTagAttributes($options) . '>'; return isset(static::$voidElements[strtolower($name)]) ? $html : "$html$content</$name>"; }
Generates a complete HTML tag. @param string|bool|null $name the tag name. If $name is `null` or `false`, the corresponding content will be rendered without any tag. @param string $content the content to be enclosed between the start and end tags. It will not be HTML-encoded. If this is coming from end users, you should consider [[encode()]] it to prevent XSS attacks. @param array $options the HTML tag attributes (HTML options) in terms of name-value pairs. These will be rendered as the attributes of the resulting tag. The values will be HTML-encoded using [[encode()]]. If a value is null, the corresponding attribute will not be rendered. For example when using `['class' => 'my-class', 'target' => '_blank', 'value' => null]` it will result in the html attributes rendered like this: `class="my-class" target="_blank"`. See [[renderTagAttributes()]] for details on how attributes are being rendered. @return string the generated HTML tag @see beginTag() @see endTag()
tag
php
yiisoft/yii2
framework/helpers/BaseHtml.php
https://github.com/yiisoft/yii2/blob/master/framework/helpers/BaseHtml.php
BSD-3-Clause
public static function beginTag($name, $options = []) { if ($name === null || $name === false) { return ''; } return "<$name" . static::renderTagAttributes($options) . '>'; }
Generates a start tag. @param string|bool|null $name the tag name. If $name is `null` or `false`, the corresponding content will be rendered without any tag. @param array $options the tag options in terms of name-value pairs. These will be rendered as the attributes of the resulting tag. The values will be HTML-encoded using [[encode()]]. If a value is null, the corresponding attribute will not be rendered. See [[renderTagAttributes()]] for details on how attributes are being rendered. @return string the generated start tag @see endTag() @see tag()
beginTag
php
yiisoft/yii2
framework/helpers/BaseHtml.php
https://github.com/yiisoft/yii2/blob/master/framework/helpers/BaseHtml.php
BSD-3-Clause
public static function style($content, $options = []) { $view = Yii::$app->getView(); if ($view instanceof \yii\web\View && !empty($view->styleOptions)) { $options = array_merge($view->styleOptions, $options); } return static::tag('style', $content, $options); }
Generates a style tag. @param string $content the style content @param array $options the tag options in terms of name-value pairs. These will be rendered as the attributes of the resulting tag. The values will be HTML-encoded using [[encode()]]. If a value is null, the corresponding attribute will not be rendered. See [[renderTagAttributes()]] for details on how attributes are being rendered. @return string the generated style tag
style
php
yiisoft/yii2
framework/helpers/BaseHtml.php
https://github.com/yiisoft/yii2/blob/master/framework/helpers/BaseHtml.php
BSD-3-Clause
public static function script($content, $options = []) { $view = Yii::$app->getView(); if ($view instanceof \yii\web\View && !empty($view->scriptOptions)) { $options = array_merge($view->scriptOptions, $options); } return static::tag('script', $content, $options); }
Generates a script tag. @param string $content the script content @param array $options the tag options in terms of name-value pairs. These will be rendered as the attributes of the resulting tag. The values will be HTML-encoded using [[encode()]]. If a value is null, the corresponding attribute will not be rendered. See [[renderTagAttributes()]] for details on how attributes are being rendered. @return string the generated script tag
script
php
yiisoft/yii2
framework/helpers/BaseHtml.php
https://github.com/yiisoft/yii2/blob/master/framework/helpers/BaseHtml.php
BSD-3-Clause
public static function jsFile($url, $options = []) { $options['src'] = Url::to($url); if (isset($options['condition'])) { $condition = $options['condition']; unset($options['condition']); return self::wrapIntoCondition(static::tag('script', '', $options), $condition); } return static::tag('script', '', $options); }
Generates a script tag that refers to an external JavaScript file. @param string $url the URL of the external JavaScript file. This parameter will be processed by [[Url::to()]]. @param array $options the tag options in terms of name-value pairs. The following option is specially handled: - condition: specifies the conditional comments for IE, e.g., `lt IE 9`. When this is specified, the generated `script` tag will be enclosed within the conditional comments. This is mainly useful for supporting old versions of IE browsers. The rest of the options will be rendered as the attributes of the resulting script tag. The values will be HTML-encoded using [[encode()]]. If a value is null, the corresponding attribute will not be rendered. See [[renderTagAttributes()]] for details on how attributes are being rendered. @return string the generated script tag @see Url::to()
jsFile
php
yiisoft/yii2
framework/helpers/BaseHtml.php
https://github.com/yiisoft/yii2/blob/master/framework/helpers/BaseHtml.php
BSD-3-Clause
private static function wrapIntoCondition($content, $condition) { if (strpos($condition, '!IE') !== false) { return "<!--[if $condition]><!-->\n" . $content . "\n<!--<![endif]-->"; } return "<!--[if $condition]>\n" . $content . "\n<![endif]-->"; }
Wraps given content into conditional comments for IE, e.g., `lt IE 9`. @param string $content raw HTML content. @param string $condition condition string. @return string generated HTML.
wrapIntoCondition
php
yiisoft/yii2
framework/helpers/BaseHtml.php
https://github.com/yiisoft/yii2/blob/master/framework/helpers/BaseHtml.php
BSD-3-Clause
public static function beginForm($action = '', $method = 'post', $options = []) { $action = Url::to($action); $hiddenInputs = []; $request = Yii::$app->getRequest(); if ($request instanceof Request) { if (strcasecmp($method, 'get') && strcasecmp($method, 'post')) { // simulate PUT, DELETE, etc. via POST $hiddenInputs[] = static::hiddenInput($request->methodParam, $method); $method = 'post'; } $csrf = ArrayHelper::remove($options, 'csrf', true); if ($csrf && $request->enableCsrfValidation && strcasecmp($method, 'post') === 0) { $hiddenInputs[] = static::hiddenInput($request->csrfParam, $request->getCsrfToken()); } } if (!strcasecmp($method, 'get') && ($pos = strpos($action, '?')) !== false) { // query parameters in the action are ignored for GET method // we use hidden fields to add them back foreach (explode('&', substr($action, $pos + 1)) as $pair) { if (($pos1 = strpos($pair, '=')) !== false) { $hiddenInputs[] = static::hiddenInput( urldecode(substr($pair, 0, $pos1)), urldecode(substr($pair, $pos1 + 1)) ); } else { $hiddenInputs[] = static::hiddenInput(urldecode($pair), ''); } } $action = substr($action, 0, $pos); } $options['action'] = $action; $options['method'] = $method; $form = static::beginTag('form', $options); if (!empty($hiddenInputs)) { $form .= "\n" . implode("\n", $hiddenInputs); } return $form; }
Generates a form start tag. @param array|string $action the form action URL. This parameter will be processed by [[Url::to()]]. @param string $method the form submission method, such as "post", "get", "put", "delete" (case-insensitive). Since most browsers only support "post" and "get", if other methods are given, they will be simulated using "post", and a hidden input will be added which contains the actual method type. See [[\yii\web\Request::methodParam]] for more details. @param array $options the tag options in terms of name-value pairs. These will be rendered as the attributes of the resulting tag. The values will be HTML-encoded using [[encode()]]. If a value is null, the corresponding attribute will not be rendered. See [[renderTagAttributes()]] for details on how attributes are being rendered. Special options: - `csrf`: whether to generate the CSRF hidden input. Defaults to true. @return string the generated form start tag. @see endForm()
beginForm
php
yiisoft/yii2
framework/helpers/BaseHtml.php
https://github.com/yiisoft/yii2/blob/master/framework/helpers/BaseHtml.php
BSD-3-Clause
public static function a($text, $url = null, $options = []) { if ($url !== null) { $options['href'] = Url::to($url); } return static::tag('a', $text, $options); }
Generates a hyperlink tag. @param string $text link body. It will NOT be HTML-encoded. Therefore you can pass in HTML code such as an image tag. If this is coming from end users, you should consider [[encode()]] it to prevent XSS attacks. @param array|string|null $url the URL for the hyperlink tag. This parameter will be processed by [[Url::to()]] and will be used for the "href" attribute of the tag. If this parameter is null, the "href" attribute will not be generated. If you want to use an absolute url you can call [[Url::to()]] yourself, before passing the URL to this method, like this: ```php Html::a('link text', Url::to($url, true)) ``` @param array $options the tag options in terms of name-value pairs. These will be rendered as the attributes of the resulting tag. The values will be HTML-encoded using [[encode()]]. If a value is null, the corresponding attribute will not be rendered. See [[renderTagAttributes()]] for details on how attributes are being rendered. @return string the generated hyperlink @see \yii\helpers\Url::to()
a
php
yiisoft/yii2
framework/helpers/BaseHtml.php
https://github.com/yiisoft/yii2/blob/master/framework/helpers/BaseHtml.php
BSD-3-Clause
public static function label($content, $for = null, $options = []) { $options['for'] = $for; return static::tag('label', $content, $options); }
Generates a label tag. @param string $content label text. It will NOT be HTML-encoded. Therefore you can pass in HTML code such as an image tag. If this is is coming from end users, you should [[encode()]] it to prevent XSS attacks. @param string|null $for the ID of the HTML element that this label is associated with. If this is null, the "for" attribute will not be generated. @param array $options the tag options in terms of name-value pairs. These will be rendered as the attributes of the resulting tag. The values will be HTML-encoded using [[encode()]]. If a value is null, the corresponding attribute will not be rendered. See [[renderTagAttributes()]] for details on how attributes are being rendered. @return string the generated label tag
label
php
yiisoft/yii2
framework/helpers/BaseHtml.php
https://github.com/yiisoft/yii2/blob/master/framework/helpers/BaseHtml.php
BSD-3-Clause
public static function button($content = 'Button', $options = []) { if (!isset($options['type'])) { $options['type'] = 'button'; } return static::tag('button', $content, $options); }
Generates a button tag. @param string $content the content enclosed within the button tag. It will NOT be HTML-encoded. Therefore you can pass in HTML code such as an image tag. If this is is coming from end users, you should consider [[encode()]] it to prevent XSS attacks. @param array $options the tag options in terms of name-value pairs. These will be rendered as the attributes of the resulting tag. The values will be HTML-encoded using [[encode()]]. If a value is null, the corresponding attribute will not be rendered. See [[renderTagAttributes()]] for details on how attributes are being rendered. @return string the generated button tag
button
php
yiisoft/yii2
framework/helpers/BaseHtml.php
https://github.com/yiisoft/yii2/blob/master/framework/helpers/BaseHtml.php
BSD-3-Clause
public static function submitButton($content = 'Submit', $options = []) { $options['type'] = 'submit'; return static::button($content, $options); }
Generates a submit button tag. Be careful when naming form elements such as submit buttons. According to the [jQuery documentation](https://api.jquery.com/submit/) there are some reserved names that can cause conflicts, e.g. `submit`, `length`, or `method`. @param string $content the content enclosed within the button tag. It will NOT be HTML-encoded. Therefore you can pass in HTML code such as an image tag. If this is is coming from end users, you should consider [[encode()]] it to prevent XSS attacks. @param array $options the tag options in terms of name-value pairs. These will be rendered as the attributes of the resulting tag. The values will be HTML-encoded using [[encode()]]. If a value is null, the corresponding attribute will not be rendered. See [[renderTagAttributes()]] for details on how attributes are being rendered. @return string the generated submit button tag
submitButton
php
yiisoft/yii2
framework/helpers/BaseHtml.php
https://github.com/yiisoft/yii2/blob/master/framework/helpers/BaseHtml.php
BSD-3-Clause
public static function resetButton($content = 'Reset', $options = []) { $options['type'] = 'reset'; return static::button($content, $options); }
Generates a reset button tag. @param string $content the content enclosed within the button tag. It will NOT be HTML-encoded. Therefore you can pass in HTML code such as an image tag. If this is is coming from end users, you should consider [[encode()]] it to prevent XSS attacks. @param array $options the tag options in terms of name-value pairs. These will be rendered as the attributes of the resulting tag. The values will be HTML-encoded using [[encode()]]. If a value is null, the corresponding attribute will not be rendered. See [[renderTagAttributes()]] for details on how attributes are being rendered. @return string the generated reset button tag
resetButton
php
yiisoft/yii2
framework/helpers/BaseHtml.php
https://github.com/yiisoft/yii2/blob/master/framework/helpers/BaseHtml.php
BSD-3-Clause
public static function input($type, $name = null, $value = null, $options = []) { if (!isset($options['type'])) { $options['type'] = $type; } $options['name'] = $name; $options['value'] = $value === null ? null : (string) $value; return static::tag('input', '', $options); }
Generates an input type of the given type. @param string $type the type attribute. @param string|null $name the name attribute. If it is null, the name attribute will not be generated. @param string|null $value the value attribute. If it is null, the value attribute will not be generated. @param array $options the tag options in terms of name-value pairs. These will be rendered as the attributes of the resulting tag. The values will be HTML-encoded using [[encode()]]. If a value is null, the corresponding attribute will not be rendered. See [[renderTagAttributes()]] for details on how attributes are being rendered. @return string the generated input tag
input
php
yiisoft/yii2
framework/helpers/BaseHtml.php
https://github.com/yiisoft/yii2/blob/master/framework/helpers/BaseHtml.php
BSD-3-Clause
public static function buttonInput($label = 'Button', $options = []) { $options['type'] = 'button'; $options['value'] = $label; return static::tag('input', '', $options); }
Generates an input button. @param string|null $label the value attribute. If it is null, the value attribute will not be generated. @param array $options the tag options in terms of name-value pairs. These will be rendered as the attributes of the resulting tag. The values will be HTML-encoded using [[encode()]]. If a value is null, the corresponding attribute will not be rendered. See [[renderTagAttributes()]] for details on how attributes are being rendered. @return string the generated button tag
buttonInput
php
yiisoft/yii2
framework/helpers/BaseHtml.php
https://github.com/yiisoft/yii2/blob/master/framework/helpers/BaseHtml.php
BSD-3-Clause
public static function submitInput($label = 'Submit', $options = []) { $options['type'] = 'submit'; $options['value'] = $label; return static::tag('input', '', $options); }
Generates a submit input button. Be careful when naming form elements such as submit buttons. According to the [jQuery documentation](https://api.jquery.com/submit/) there are some reserved names that can cause conflicts, e.g. `submit`, `length`, or `method`. @param string|null $label the value attribute. If it is null, the value attribute will not be generated. @param array $options the tag options in terms of name-value pairs. These will be rendered as the attributes of the resulting tag. The values will be HTML-encoded using [[encode()]]. If a value is null, the corresponding attribute will not be rendered. See [[renderTagAttributes()]] for details on how attributes are being rendered. @return string the generated button tag
submitInput
php
yiisoft/yii2
framework/helpers/BaseHtml.php
https://github.com/yiisoft/yii2/blob/master/framework/helpers/BaseHtml.php
BSD-3-Clause
public static function resetInput($label = 'Reset', $options = []) { $options['type'] = 'reset'; $options['value'] = $label; return static::tag('input', '', $options); }
Generates a reset input button. @param string|null $label the value attribute. If it is null, the value attribute will not be generated. @param array $options the attributes of the button tag. The values will be HTML-encoded using [[encode()]]. Attributes whose value is null will be ignored and not put in the tag returned. See [[renderTagAttributes()]] for details on how attributes are being rendered. @return string the generated button tag
resetInput
php
yiisoft/yii2
framework/helpers/BaseHtml.php
https://github.com/yiisoft/yii2/blob/master/framework/helpers/BaseHtml.php
BSD-3-Clause
public static function textInput($name, $value = null, $options = []) { return static::input('text', $name, $value, $options); }
Generates a text input field. @param string $name the name attribute. @param string|null $value the value attribute. If it is null, the value attribute will not be generated. @param array $options the tag options in terms of name-value pairs. These will be rendered as the attributes of the resulting tag. The values will be HTML-encoded using [[encode()]]. If a value is null, the corresponding attribute will not be rendered. See [[renderTagAttributes()]] for details on how attributes are being rendered. @return string the generated text input tag
textInput
php
yiisoft/yii2
framework/helpers/BaseHtml.php
https://github.com/yiisoft/yii2/blob/master/framework/helpers/BaseHtml.php
BSD-3-Clause
public static function hiddenInput($name, $value = null, $options = []) { return static::input('hidden', $name, $value, $options); }
Generates a hidden input field. @param string $name the name attribute. @param string|null $value the value attribute. If it is null, the value attribute will not be generated. @param array $options the tag options in terms of name-value pairs. These will be rendered as the attributes of the resulting tag. The values will be HTML-encoded using [[encode()]]. If a value is null, the corresponding attribute will not be rendered. See [[renderTagAttributes()]] for details on how attributes are being rendered. @return string the generated hidden input tag
hiddenInput
php
yiisoft/yii2
framework/helpers/BaseHtml.php
https://github.com/yiisoft/yii2/blob/master/framework/helpers/BaseHtml.php
BSD-3-Clause
public static function passwordInput($name, $value = null, $options = []) { return static::input('password', $name, $value, $options); }
Generates a password input field. @param string $name the name attribute. @param string|null $value the value attribute. If it is null, the value attribute will not be generated. @param array $options the tag options in terms of name-value pairs. These will be rendered as the attributes of the resulting tag. The values will be HTML-encoded using [[encode()]]. If a value is null, the corresponding attribute will not be rendered. See [[renderTagAttributes()]] for details on how attributes are being rendered. @return string the generated password input tag
passwordInput
php
yiisoft/yii2
framework/helpers/BaseHtml.php
https://github.com/yiisoft/yii2/blob/master/framework/helpers/BaseHtml.php
BSD-3-Clause
public static function fileInput($name, $value = null, $options = []) { return static::input('file', $name, $value, $options); }
Generates a file input field. To use a file input field, you should set the enclosing form's "enctype" attribute to be "multipart/form-data". After the form is submitted, the uploaded file information can be obtained via $_FILES[$name] (see PHP documentation). @param string $name the name attribute. @param string|null $value the value attribute. If it is null, the value attribute will not be generated. @param array $options the tag options in terms of name-value pairs. These will be rendered as the attributes of the resulting tag. The values will be HTML-encoded using [[encode()]]. If a value is null, the corresponding attribute will not be rendered. See [[renderTagAttributes()]] for details on how attributes are being rendered. @return string the generated file input tag
fileInput
php
yiisoft/yii2
framework/helpers/BaseHtml.php
https://github.com/yiisoft/yii2/blob/master/framework/helpers/BaseHtml.php
BSD-3-Clause
public static function textarea($name, $value = '', $options = []) { $options['name'] = $name; $doubleEncode = ArrayHelper::remove($options, 'doubleEncode', true); return static::tag('textarea', static::encode($value, $doubleEncode), $options); }
Generates a text area input. @param string $name the input name @param string $value the input value. Note that it will be encoded using [[encode()]]. @param array $options the tag options in terms of name-value pairs. These will be rendered as the attributes of the resulting tag. The values will be HTML-encoded using [[encode()]]. If a value is null, the corresponding attribute will not be rendered. See [[renderTagAttributes()]] for details on how attributes are being rendered. The following special options are recognized: - `doubleEncode`: whether to double encode HTML entities in `$value`. If `false`, HTML entities in `$value` will not be further encoded. This option is available since version 2.0.11. @return string the generated text area tag
textarea
php
yiisoft/yii2
framework/helpers/BaseHtml.php
https://github.com/yiisoft/yii2/blob/master/framework/helpers/BaseHtml.php
BSD-3-Clause
public static function radio($name, $checked = false, $options = []) { return static::booleanInput('radio', $name, $checked, $options); }
Generates a radio button input. @param string $name the name attribute. @param bool $checked whether the radio button should be checked. @param array $options the tag options in terms of name-value pairs. See [[booleanInput()]] for details about accepted attributes. @return string the generated radio button tag
radio
php
yiisoft/yii2
framework/helpers/BaseHtml.php
https://github.com/yiisoft/yii2/blob/master/framework/helpers/BaseHtml.php
BSD-3-Clause
public static function checkbox($name, $checked = false, $options = []) { return static::booleanInput('checkbox', $name, $checked, $options); }
Generates a checkbox input. @param string $name the name attribute. @param bool $checked whether the checkbox should be checked. @param array $options the tag options in terms of name-value pairs. See [[booleanInput()]] for details about accepted attributes. @return string the generated checkbox tag
checkbox
php
yiisoft/yii2
framework/helpers/BaseHtml.php
https://github.com/yiisoft/yii2/blob/master/framework/helpers/BaseHtml.php
BSD-3-Clause
protected static function booleanInput($type, $name, $checked = false, $options = []) { // 'checked' option has priority over $checked argument if (!isset($options['checked'])) { $options['checked'] = (bool) $checked; } $value = array_key_exists('value', $options) ? $options['value'] : '1'; if (isset($options['uncheck'])) { // add a hidden field so that if the checkbox is not selected, it still submits a value $hiddenOptions = []; if (isset($options['form'])) { $hiddenOptions['form'] = $options['form']; } // make sure disabled input is not sending any value if (!empty($options['disabled'])) { $hiddenOptions['disabled'] = $options['disabled']; } $hidden = static::hiddenInput($name, $options['uncheck'], $hiddenOptions); unset($options['uncheck']); } else { $hidden = ''; } if (isset($options['label'])) { $label = $options['label']; $labelOptions = isset($options['labelOptions']) ? $options['labelOptions'] : []; unset($options['label'], $options['labelOptions']); $content = static::label(static::input($type, $name, $value, $options) . ' ' . $label, null, $labelOptions); return $hidden . $content; } return $hidden . static::input($type, $name, $value, $options); }
Generates a boolean input. @param string $type the input type. This can be either `radio` or `checkbox`. @param string $name the name attribute. @param bool $checked whether the checkbox should be checked. @param array $options the tag options in terms of name-value pairs. The following options are specially handled: - uncheck: string, the value associated with the uncheck state of the checkbox. When this attribute is present, a hidden input will be generated so that if the checkbox is not checked and is submitted, the value of this attribute will still be submitted to the server via the hidden input. - label: string, a label displayed next to the checkbox. It will NOT be HTML-encoded. Therefore you can pass in HTML code such as an image tag. If this is is coming from end users, you should [[encode()]] it to prevent XSS attacks. When this option is specified, the checkbox will be enclosed by a label tag. - labelOptions: array, the HTML attributes for the label tag. Do not set this option unless you set the "label" option. The rest of the options will be rendered as the attributes of the resulting checkbox tag. The values will be HTML-encoded using [[encode()]]. If a value is null, the corresponding attribute will not be rendered. See [[renderTagAttributes()]] for details on how attributes are being rendered. @return string the generated checkbox tag @since 2.0.9
booleanInput
php
yiisoft/yii2
framework/helpers/BaseHtml.php
https://github.com/yiisoft/yii2/blob/master/framework/helpers/BaseHtml.php
BSD-3-Clause
public static function ul($items, $options = []) { $tag = ArrayHelper::remove($options, 'tag', 'ul'); $encode = ArrayHelper::remove($options, 'encode', true); $formatter = ArrayHelper::remove($options, 'item'); $separator = ArrayHelper::remove($options, 'separator', "\n"); $itemOptions = ArrayHelper::remove($options, 'itemOptions', []); if (empty($items)) { return static::tag($tag, '', $options); } $results = []; foreach ($items as $index => $item) { if ($formatter !== null) { $results[] = call_user_func($formatter, $item, $index); } else { $results[] = static::tag('li', $encode ? static::encode($item) : $item, $itemOptions); } } return static::tag( $tag, $separator . implode($separator, $results) . $separator, $options ); }
Generates an unordered list. @param array|\Traversable $items the items for generating the list. Each item generates a single list item. Note that items will be automatically HTML encoded if `$options['encode']` is not set or true. @param array $options options (name => config) for the radio button list. The following options are supported: - encode: boolean, whether to HTML-encode the items. Defaults to true. This option is ignored if the `item` option is specified. - separator: string, the HTML code that separates items. Defaults to a simple newline (`"\n"`). This option is available since version 2.0.7. - itemOptions: array, the HTML attributes for the `li` tags. This option is ignored if the `item` option is specified. - item: callable, a callback that is used to generate each individual list item. The signature of this callback must be: ```php function ($item, $index) ``` where $index is the array key corresponding to `$item` in `$items`. The callback should return the whole list item tag. See [[renderTagAttributes()]] for details on how attributes are being rendered. @return string the generated unordered list. An empty list tag will be returned if `$items` is empty.
ul
php
yiisoft/yii2
framework/helpers/BaseHtml.php
https://github.com/yiisoft/yii2/blob/master/framework/helpers/BaseHtml.php
BSD-3-Clause
public static function ol($items, $options = []) { $options['tag'] = 'ol'; return static::ul($items, $options); }
Generates an ordered list. @param array|\Traversable $items the items for generating the list. Each item generates a single list item. Note that items will be automatically HTML encoded if `$options['encode']` is not set or true. @param array $options options (name => config) for the radio button list. The following options are supported: - encode: boolean, whether to HTML-encode the items. Defaults to true. This option is ignored if the `item` option is specified. - itemOptions: array, the HTML attributes for the `li` tags. This option is ignored if the `item` option is specified. - item: callable, a callback that is used to generate each individual list item. The signature of this callback must be: ```php function ($item, $index) ``` where $index is the array key corresponding to `$item` in `$items`. The callback should return the whole list item tag. See [[renderTagAttributes()]] for details on how attributes are being rendered. @return string the generated ordered list. An empty string is returned if `$items` is empty.
ol
php
yiisoft/yii2
framework/helpers/BaseHtml.php
https://github.com/yiisoft/yii2/blob/master/framework/helpers/BaseHtml.php
BSD-3-Clause
public static function activeLabel($model, $attribute, $options = []) { $for = ArrayHelper::remove($options, 'for', static::getInputId($model, $attribute)); $attribute = static::getAttributeName($attribute); $label = ArrayHelper::remove($options, 'label', static::encode($model->getAttributeLabel($attribute))); return static::label($label, $for, $options); }
Generates a label tag for the given model attribute. The label text is the label associated with the attribute, obtained via [[Model::getAttributeLabel()]]. @param Model $model the model object @param string $attribute the attribute name or expression. See [[getAttributeName()]] for the format about attribute expression. @param array $options the tag options in terms of name-value pairs. These will be rendered as the attributes of the resulting tag. The values will be HTML-encoded using [[encode()]]. If a value is null, the corresponding attribute will not be rendered. The following options are specially handled: - label: this specifies the label to be displayed. Note that this will NOT be [[encode()|encoded]]. If this is not set, [[Model::getAttributeLabel()]] will be called to get the label for display (after encoding). See [[renderTagAttributes()]] for details on how attributes are being rendered. @return string the generated label tag
activeLabel
php
yiisoft/yii2
framework/helpers/BaseHtml.php
https://github.com/yiisoft/yii2/blob/master/framework/helpers/BaseHtml.php
BSD-3-Clause
public static function activeHint($model, $attribute, $options = []) { $attribute = static::getAttributeName($attribute); $hint = isset($options['hint']) ? $options['hint'] : $model->getAttributeHint($attribute); if (empty($hint)) { return ''; } $tag = ArrayHelper::remove($options, 'tag', 'div'); unset($options['hint']); return static::tag($tag, $hint, $options); }
Generates a hint tag for the given model attribute. The hint text is the hint associated with the attribute, obtained via [[Model::getAttributeHint()]]. If no hint content can be obtained, method will return an empty string. @param Model $model the model object @param string $attribute the attribute name or expression. See [[getAttributeName()]] for the format about attribute expression. @param array $options the tag options in terms of name-value pairs. These will be rendered as the attributes of the resulting tag. The values will be HTML-encoded using [[encode()]]. If a value is null, the corresponding attribute will not be rendered. The following options are specially handled: - hint: this specifies the hint to be displayed. Note that this will NOT be [[encode()|encoded]]. If this is not set, [[Model::getAttributeHint()]] will be called to get the hint for display (without encoding). See [[renderTagAttributes()]] for details on how attributes are being rendered. @return string the generated hint tag @since 2.0.4
activeHint
php
yiisoft/yii2
framework/helpers/BaseHtml.php
https://github.com/yiisoft/yii2/blob/master/framework/helpers/BaseHtml.php
BSD-3-Clause
public static function errorSummary($models, $options = []) { $header = isset($options['header']) ? $options['header'] : '<p>' . Yii::t('yii', 'Please fix the following errors:') . '</p>'; $footer = ArrayHelper::remove($options, 'footer', ''); $encode = ArrayHelper::remove($options, 'encode', true); $showAllErrors = ArrayHelper::remove($options, 'showAllErrors', false); $emptyClass = ArrayHelper::remove($options, 'emptyClass', null); unset($options['header']); $lines = self::collectErrors($models, $encode, $showAllErrors); if (empty($lines)) { // still render the placeholder for client-side validation use $content = '<ul></ul>'; if ($emptyClass !== null) { $options['class'] = $emptyClass; } else { $options['style'] = isset($options['style']) ? rtrim($options['style'], ';') . '; display:none' : 'display:none'; } } else { $content = '<ul><li>' . implode("</li>\n<li>", $lines) . '</li></ul>'; } return Html::tag('div', $header . $content . $footer, $options); }
Generates a summary of the validation errors. If there is no validation error, an empty error summary markup will still be generated, but it will be hidden. @param Model|Model[] $models the model(s) whose validation errors are to be displayed. @param array $options the tag options in terms of name-value pairs. The following options are specially handled: - header: string, the header HTML for the error summary. If not set, a default prompt string will be used. - footer: string, the footer HTML for the error summary. Defaults to empty string. - encode: boolean, if set to false then the error messages won't be encoded. Defaults to `true`. - showAllErrors: boolean, if set to true every error message for each attribute will be shown otherwise only the first error message for each attribute will be shown. Defaults to `false`. Option is available since 2.0.10. - emptyClass: string, the class name that is added to an empty summary. The rest of the options will be rendered as the attributes of the container tag. @return string the generated error summary
errorSummary
php
yiisoft/yii2
framework/helpers/BaseHtml.php
https://github.com/yiisoft/yii2/blob/master/framework/helpers/BaseHtml.php
BSD-3-Clause
public static function error($model, $attribute, $options = []) { $attribute = static::getAttributeName($attribute); $errorSource = ArrayHelper::remove($options, 'errorSource'); if ($errorSource !== null) { $error = call_user_func($errorSource, $model, $attribute); } else { $error = $model->getFirstError($attribute); } $tag = ArrayHelper::remove($options, 'tag', 'div'); $encode = ArrayHelper::remove($options, 'encode', true); return Html::tag($tag, $encode ? Html::encode($error) : $error, $options); }
Generates a tag that contains the first validation error of the specified model attribute. Note that even if there is no validation error, this method will still return an empty error tag. @param Model $model the model object @param string $attribute the attribute name or expression. See [[getAttributeName()]] for the format about attribute expression. @param array $options the tag options in terms of name-value pairs. The values will be HTML-encoded using [[encode()]]. If a value is null, the corresponding attribute will not be rendered. The following options are specially handled: - tag: this specifies the tag name. If not set, "div" will be used. See also [[tag()]]. - encode: boolean, if set to false then the error message won't be encoded. - errorSource (since 2.0.14): \Closure|callable, callback that will be called to obtain an error message. The signature of the callback must be: `function ($model, $attribute)` and return a string. When not set, the `$model->getFirstError()` method will be called. See [[renderTagAttributes()]] for details on how attributes are being rendered. @return string the generated label tag
error
php
yiisoft/yii2
framework/helpers/BaseHtml.php
https://github.com/yiisoft/yii2/blob/master/framework/helpers/BaseHtml.php
BSD-3-Clause
public static function activeInput($type, $model, $attribute, $options = []) { $name = isset($options['name']) ? $options['name'] : static::getInputName($model, $attribute); $value = isset($options['value']) ? $options['value'] : static::getAttributeValue($model, $attribute); if (!array_key_exists('id', $options)) { $options['id'] = static::getInputId($model, $attribute); } static::setActivePlaceholder($model, $attribute, $options); self::normalizeMaxLength($model, $attribute, $options); return static::input($type, $name, $value, $options); }
Generates an input tag for the given model attribute. This method will generate the "name" and "value" tag attributes automatically for the model attribute unless they are explicitly specified in `$options`. @param string $type the input type (e.g. 'text', 'password') @param Model $model the model object @param string $attribute the attribute name or expression. See [[getAttributeName()]] for the format about attribute expression. @param array $options the tag options in terms of name-value pairs. These will be rendered as the attributes of the resulting tag. The values will be HTML-encoded using [[encode()]]. See [[renderTagAttributes()]] for details on how attributes are being rendered. @return string the generated input tag
activeInput
php
yiisoft/yii2
framework/helpers/BaseHtml.php
https://github.com/yiisoft/yii2/blob/master/framework/helpers/BaseHtml.php
BSD-3-Clause
private static function normalizeMaxLength($model, $attribute, &$options) { if (isset($options['maxlength']) && $options['maxlength'] === true) { unset($options['maxlength']); $attrName = static::getAttributeName($attribute); foreach ($model->getActiveValidators($attrName) as $validator) { if ($validator instanceof StringValidator && ($validator->max !== null || $validator->length !== null)) { $options['maxlength'] = max($validator->max, $validator->length); break; } } } }
If `maxlength` option is set true and the model attribute is validated by a string validator, the `maxlength` option will take the max value of [[\yii\validators\StringValidator::max]] and [[\yii\validators\StringValidator::length]]. @param Model $model the model object @param string $attribute the attribute name or expression. @param array $options the tag options in terms of name-value pairs.
normalizeMaxLength
php
yiisoft/yii2
framework/helpers/BaseHtml.php
https://github.com/yiisoft/yii2/blob/master/framework/helpers/BaseHtml.php
BSD-3-Clause
public static function activeTextInput($model, $attribute, $options = []) { return static::activeInput('text', $model, $attribute, $options); }
Generates a text input tag for the given model attribute. This method will generate the "name" and "value" tag attributes automatically for the model attribute unless they are explicitly specified in `$options`. @param Model $model the model object @param string $attribute the attribute name or expression. See [[getAttributeName()]] for the format about attribute expression. @param array $options the tag options in terms of name-value pairs. These will be rendered as the attributes of the resulting tag. The values will be HTML-encoded using [[encode()]]. See [[renderTagAttributes()]] for details on how attributes are being rendered. The following special options are recognized: - maxlength: integer|boolean, when `maxlength` is set true and the model attribute is validated by a string validator, the `maxlength` option will take the max value of [[\yii\validators\StringValidator::max]] and [[\yii\validators\StringValidator::length]. This is available since version 2.0.3 and improved taking `length` into account since version 2.0.42. - placeholder: string|boolean, when `placeholder` equals `true`, the attribute label from the $model will be used as a placeholder (this behavior is available since version 2.0.14). @return string the generated input tag
activeTextInput
php
yiisoft/yii2
framework/helpers/BaseHtml.php
https://github.com/yiisoft/yii2/blob/master/framework/helpers/BaseHtml.php
BSD-3-Clause
protected static function setActivePlaceholder($model, $attribute, &$options = []) { if (isset($options['placeholder']) && $options['placeholder'] === true) { $attribute = static::getAttributeName($attribute); $options['placeholder'] = $model->getAttributeLabel($attribute); } }
Generate placeholder from model attribute label. @param Model $model the model object @param string $attribute the attribute name or expression. See [[getAttributeName()]] for the format about attribute expression. @param array $options the tag options in terms of name-value pairs. These will be rendered as the attributes of the resulting tag. The values will be HTML-encoded using [[encode()]]. @since 2.0.14
setActivePlaceholder
php
yiisoft/yii2
framework/helpers/BaseHtml.php
https://github.com/yiisoft/yii2/blob/master/framework/helpers/BaseHtml.php
BSD-3-Clause
public static function activeHiddenInput($model, $attribute, $options = []) { return static::activeInput('hidden', $model, $attribute, $options); }
Generates a hidden input tag for the given model attribute. This method will generate the "name" and "value" tag attributes automatically for the model attribute unless they are explicitly specified in `$options`. @param Model $model the model object @param string $attribute the attribute name or expression. See [[getAttributeName()]] for the format about attribute expression. @param array $options the tag options in terms of name-value pairs. These will be rendered as the attributes of the resulting tag. The values will be HTML-encoded using [[encode()]]. See [[renderTagAttributes()]] for details on how attributes are being rendered. @return string the generated input tag
activeHiddenInput
php
yiisoft/yii2
framework/helpers/BaseHtml.php
https://github.com/yiisoft/yii2/blob/master/framework/helpers/BaseHtml.php
BSD-3-Clause
public static function activePasswordInput($model, $attribute, $options = []) { return static::activeInput('password', $model, $attribute, $options); }
Generates a password input tag for the given model attribute. This method will generate the "name" and "value" tag attributes automatically for the model attribute unless they are explicitly specified in `$options`. @param Model $model the model object @param string $attribute the attribute name or expression. See [[getAttributeName()]] for the format about attribute expression. @param array $options the tag options in terms of name-value pairs. These will be rendered as the attributes of the resulting tag. The values will be HTML-encoded using [[encode()]]. See [[renderTagAttributes()]] for details on how attributes are being rendered. The following special options are recognized: - maxlength: integer|boolean, when `maxlength` is set true and the model attribute is validated by a string validator, the `maxlength` option will take the max value of [[\yii\validators\StringValidator::max]] and [[\yii\validators\StringValidator::length]. This is available since version 2.0.6 and improved taking `length` into account since version 2.0.42. - placeholder: string|boolean, when `placeholder` equals `true`, the attribute label from the $model will be used as a placeholder (this behavior is available since version 2.0.14). @return string the generated input tag
activePasswordInput
php
yiisoft/yii2
framework/helpers/BaseHtml.php
https://github.com/yiisoft/yii2/blob/master/framework/helpers/BaseHtml.php
BSD-3-Clause
public static function activeTextarea($model, $attribute, $options = []) { $name = isset($options['name']) ? $options['name'] : static::getInputName($model, $attribute); if (isset($options['value'])) { $value = $options['value']; unset($options['value']); } else { $value = static::getAttributeValue($model, $attribute); } if (!array_key_exists('id', $options)) { $options['id'] = static::getInputId($model, $attribute); } self::normalizeMaxLength($model, $attribute, $options); static::setActivePlaceholder($model, $attribute, $options); return static::textarea($name, $value, $options); }
Generates a textarea tag for the given model attribute. The model attribute value will be used as the content in the textarea. @param Model $model the model object @param string $attribute the attribute name or expression. See [[getAttributeName()]] for the format about attribute expression. @param array $options the tag options in terms of name-value pairs. These will be rendered as the attributes of the resulting tag. The values will be HTML-encoded using [[encode()]]. See [[renderTagAttributes()]] for details on how attributes are being rendered. The following special options are recognized: - maxlength: integer|boolean, when `maxlength` is set true and the model attribute is validated by a string validator, the `maxlength` option will take the max value of [[\yii\validators\StringValidator::max]] and [[\yii\validators\StringValidator::length]. This is available since version 2.0.6 and improved taking `length` into account since version 2.0.42. - placeholder: string|boolean, when `placeholder` equals `true`, the attribute label from the $model will be used as a placeholder (this behavior is available since version 2.0.14). @return string the generated textarea tag
activeTextarea
php
yiisoft/yii2
framework/helpers/BaseHtml.php
https://github.com/yiisoft/yii2/blob/master/framework/helpers/BaseHtml.php
BSD-3-Clause
public static function activeRadio($model, $attribute, $options = []) { return static::activeBooleanInput('radio', $model, $attribute, $options); }
Generates a radio button tag together with a label for the given model attribute. This method will generate the "checked" tag attribute according to the model attribute value. @param Model $model the model object @param string $attribute the attribute name or expression. See [[getAttributeName()]] for the format about attribute expression. @param array $options the tag options in terms of name-value pairs. See [[booleanInput()]] for details about accepted attributes. @return string the generated radio button tag
activeRadio
php
yiisoft/yii2
framework/helpers/BaseHtml.php
https://github.com/yiisoft/yii2/blob/master/framework/helpers/BaseHtml.php
BSD-3-Clause
public static function activeCheckbox($model, $attribute, $options = []) { return static::activeBooleanInput('checkbox', $model, $attribute, $options); }
Generates a checkbox tag together with a label for the given model attribute. This method will generate the "checked" tag attribute according to the model attribute value. @param Model $model the model object @param string $attribute the attribute name or expression. See [[getAttributeName()]] for the format about attribute expression. @param array $options the tag options in terms of name-value pairs. See [[booleanInput()]] for details about accepted attributes. @return string the generated checkbox tag
activeCheckbox
php
yiisoft/yii2
framework/helpers/BaseHtml.php
https://github.com/yiisoft/yii2/blob/master/framework/helpers/BaseHtml.php
BSD-3-Clause
public static function activeCheckboxList($model, $attribute, $items, $options = []) { return static::activeListInput('checkboxList', $model, $attribute, $items, $options); }
Generates a list of checkboxes. A checkbox list allows multiple selection, like [[listBox()]]. As a result, the corresponding submitted value is an array. The selection of the checkbox list is taken from the value of the model attribute. @param Model $model the model object @param string $attribute the attribute name or expression. See [[getAttributeName()]] for the format about attribute expression. @param array $items the data item used to generate the checkboxes. The array keys are the checkbox values, and the array values are the corresponding labels. @param array $options options (name => config) for the checkbox list container tag. The following options are specially handled: - tag: string|false, the tag name of the container element. False to render checkbox without container. See also [[tag()]]. - unselect: string, the value that should be submitted when none of the checkboxes is selected. You may set this option to be null to prevent default value submission. If this option is not set, an empty string will be submitted. - encode: boolean, whether to HTML-encode the checkbox labels. Defaults to true. This option is ignored if `item` option is set. - separator: string, the HTML code that separates items. - itemOptions: array, the options for generating the checkbox tag using [[checkbox()]]. - item: callable, a callback that can be used to customize the generation of the HTML code corresponding to a single item in $items. The signature of this callback must be: ```php function ($index, $label, $name, $checked, $value) ``` where $index is the zero-based index of the checkbox in the whole list; $label is the label for the checkbox; and $name, $value and $checked represent the name, value and the checked status of the checkbox input. See [[renderTagAttributes()]] for details on how attributes are being rendered. @return string the generated checkbox list
activeCheckboxList
php
yiisoft/yii2
framework/helpers/BaseHtml.php
https://github.com/yiisoft/yii2/blob/master/framework/helpers/BaseHtml.php
BSD-3-Clause
public static function activeRadioList($model, $attribute, $items, $options = []) { return static::activeListInput('radioList', $model, $attribute, $items, $options); }
Generates a list of radio buttons. A radio button list is like a checkbox list, except that it only allows single selection. The selection of the radio buttons is taken from the value of the model attribute. @param Model $model the model object @param string $attribute the attribute name or expression. See [[getAttributeName()]] for the format about attribute expression. @param array $items the data item used to generate the radio buttons. The array keys are the radio values, and the array values are the corresponding labels. @param array $options options (name => config) for the radio button list container tag. The following options are specially handled: - tag: string|false, the tag name of the container element. False to render radio button without container. See also [[tag()]]. - unselect: string, the value that should be submitted when none of the radio buttons is selected. You may set this option to be null to prevent default value submission. If this option is not set, an empty string will be submitted. - encode: boolean, whether to HTML-encode the checkbox labels. Defaults to true. This option is ignored if `item` option is set. - separator: string, the HTML code that separates items. - itemOptions: array, the options for generating the radio button tag using [[radio()]]. - item: callable, a callback that can be used to customize the generation of the HTML code corresponding to a single item in $items. The signature of this callback must be: ```php function ($index, $label, $name, $checked, $value) ``` where $index is the zero-based index of the radio button in the whole list; $label is the label for the radio button; and $name, $value and $checked represent the name, value and the checked status of the radio button input. See [[renderTagAttributes()]] for details on how attributes are being rendered. @return string the generated radio button list
activeRadioList
php
yiisoft/yii2
framework/helpers/BaseHtml.php
https://github.com/yiisoft/yii2/blob/master/framework/helpers/BaseHtml.php
BSD-3-Clause
protected static function activeListInput($type, $model, $attribute, $items, $options = []) { $name = ArrayHelper::remove($options, 'name', static::getInputName($model, $attribute)); $selection = ArrayHelper::remove($options, 'value', static::getAttributeValue($model, $attribute)); if (!array_key_exists('unselect', $options)) { $options['unselect'] = ''; } if (!array_key_exists('id', $options)) { $options['id'] = static::getInputId($model, $attribute); } return static::$type($name, $selection, $items, $options); }
Generates a list of input fields. This method is mainly called by [[activeListBox()]], [[activeRadioList()]] and [[activeCheckboxList()]]. @param string $type the input type. This can be 'listBox', 'radioList', or 'checkBoxList'. @param Model $model the model object @param string $attribute the attribute name or expression. See [[getAttributeName()]] for the format about attribute expression. @param array $items the data item used to generate the input fields. The array keys are the input values, and the array values are the corresponding labels. @param array $options options (name => config) for the input list. The supported special options depend on the input type specified by `$type`. @return string the generated input list
activeListInput
php
yiisoft/yii2
framework/helpers/BaseHtml.php
https://github.com/yiisoft/yii2/blob/master/framework/helpers/BaseHtml.php
BSD-3-Clause
public static function removeCssClass(&$options, $class) { if (isset($options['class'])) { if (is_array($options['class'])) { $classes = array_diff($options['class'], (array) $class); if (empty($classes)) { unset($options['class']); } else { $options['class'] = $classes; } } else { $classes = preg_split('/\s+/', $options['class'], -1, PREG_SPLIT_NO_EMPTY); $classes = array_diff($classes, (array) $class); if (empty($classes)) { unset($options['class']); } else { $options['class'] = implode(' ', $classes); } } } }
Removes a CSS class from the specified options. @param array $options the options to be modified. @param string|array $class the CSS class(es) to be removed @see addCssClass()
removeCssClass
php
yiisoft/yii2
framework/helpers/BaseHtml.php
https://github.com/yiisoft/yii2/blob/master/framework/helpers/BaseHtml.php
BSD-3-Clause
public static function getInputName($model, $attribute) { $formName = $model->formName(); if (!preg_match(static::$attributeRegex, $attribute, $matches)) { throw new InvalidArgumentException('Attribute name must contain word characters only.'); } $prefix = $matches[1]; $attribute = $matches[2]; $suffix = $matches[3]; if ($formName === '' && $prefix === '') { return $attribute . $suffix; } elseif ($formName !== '') { return $formName . $prefix . "[$attribute]" . $suffix; } throw new InvalidArgumentException(get_class($model) . '::formName() cannot be empty for tabular inputs.'); }
Generates an appropriate input name for the specified attribute name or expression. This method generates a name that can be used as the input name to collect user input for the specified attribute. The name is generated according to the [[Model::formName|form name]] of the model and the given attribute name. For example, if the form name of the `Post` model is `Post`, then the input name generated for the `content` attribute would be `Post[content]`. See [[getAttributeName()]] for explanation of attribute expression. @param Model $model the model object @param string $attribute the attribute name or expression @return string the generated input name @throws InvalidArgumentException if the attribute name contains non-word characters.
getInputName
php
yiisoft/yii2
framework/helpers/BaseHtml.php
https://github.com/yiisoft/yii2/blob/master/framework/helpers/BaseHtml.php
BSD-3-Clause
public static function getInputIdByName($name) { $charset = Yii::$app ? Yii::$app->charset : 'UTF-8'; $name = mb_strtolower($name, $charset); return str_replace(['[]', '][', '[', ']', ' ', '.', '--'], ['', '-', '-', '', '-', '-', '-'], $name); }
Converts input name to ID. For example, if `$name` is `Post[content]`, this method will return `post-content`. @param string $name the input name @return string the generated input ID @since 2.0.43
getInputIdByName
php
yiisoft/yii2
framework/helpers/BaseHtml.php
https://github.com/yiisoft/yii2/blob/master/framework/helpers/BaseHtml.php
BSD-3-Clause
public static function getInputId($model, $attribute) { $name = static::getInputName($model, $attribute); return static::getInputIdByName($name); }
Generates an appropriate input ID for the specified attribute name or expression. @param Model $model the model object @param string $attribute the attribute name or expression. See [[getAttributeName()]] for explanation of attribute expression. @return string the generated input ID. @throws InvalidArgumentException if the attribute name contains non-word characters.
getInputId
php
yiisoft/yii2
framework/helpers/BaseHtml.php
https://github.com/yiisoft/yii2/blob/master/framework/helpers/BaseHtml.php
BSD-3-Clause
public static function escapeJsRegularExpression($regexp) { $pattern = preg_replace('/\\\\x\{?([0-9a-fA-F]+)\}?/', '\u$1', $regexp); $deliminator = substr($pattern, 0, 1); $pos = strrpos($pattern, $deliminator, 1); $flag = substr($pattern, $pos + 1); if ($deliminator !== '/') { $pattern = '/' . str_replace('/', '\\/', substr($pattern, 1, $pos - 1)) . '/'; } else { $pattern = substr($pattern, 0, $pos + 1); } if (!empty($flag)) { $pattern .= preg_replace('/[^igmu]/', '', $flag); } return $pattern; }
Escapes regular expression to use in JavaScript. @param string $regexp the regular expression to be escaped. @return string the escaped result. @since 2.0.6
escapeJsRegularExpression
php
yiisoft/yii2
framework/helpers/BaseHtml.php
https://github.com/yiisoft/yii2/blob/master/framework/helpers/BaseHtml.php
BSD-3-Clause
public static function convertDatePhpToIcu($pattern) { // https://www.php.net/manual/en/function.date $result = strtr($pattern, [ "'" => "''''", // single `'` should be encoded as `''`, which internally should be encoded as `''''` // Day '\d' => "'d'", 'd' => 'dd', // Day of the month, 2 digits with leading zeros β€” 01 to 31 '\D' => "'D'", 'D' => 'eee', // A textual representation of a day, three letters β€” Mon through Sun '\j' => "'j'", 'j' => 'd', // Day of the month without leading zeros β€” 1 to 31 '\l' => "'l'", 'l' => 'eeee', // A full textual representation of the day of the week β€” Sunday through Saturday '\N' => "'N'", 'N' => 'e', // ISO-8601 numeric representation of the day of the week, 1 (for Monday) through 7 (for Sunday) '\S' => "'S'", 'S' => '', // English ordinal suffix for the day of the month, 2 characters β€” st, nd, rd or th. Works well with j '\w' => "'w'", 'w' => '', // Numeric representation of the day of the week β€” 0 (for Sunday) through 6 (for Saturday) '\z' => "'z'", 'z' => 'D', // The day of the year (starting from 0) β€” 0 through 365 // Week '\W' => "'W'", 'W' => 'w', // ISO-8601 week number of year, weeks starting on Monday (added in PHP 4.1.0) β€” Example: 42 (the 42nd week in the year) // Month '\F' => "'F'", 'F' => 'MMMM', // A full textual representation of a month, January through December '\m' => "'m'", 'm' => 'MM', // Numeric representation of a month, with leading zeros β€” 01 through 12 '\M' => "'M'", 'M' => 'MMM', // A short textual representation of a month, three letters β€” Jan through Dec '\n' => "'n'", 'n' => 'M', // Numeric representation of a month, without leading zeros β€” 1 through 12, not supported by ICU but we fallback to "with leading zero" '\t' => "'t'", 't' => '', // Number of days in the given month β€” 28 through 31 // Year '\L' => "'L'", 'L' => '', // Whether it's a leap year, 1 if it is a leap year, 0 otherwise. '\o' => "'o'", 'o' => 'Y', // ISO-8601 year number. This has the same value as Y, except that if the ISO week number (W) belongs to the previous or next year, that year is used instead. '\Y' => "'Y'", 'Y' => 'yyyy', // A full numeric representation of a year, 4 digits β€” Examples: 1999 or 2003 '\y' => "'y'", 'y' => 'yy', // A two digit representation of a year β€” Examples: 99 or 03 // Time '\a' => "'a'", 'a' => 'a', // Lowercase Ante meridiem and Post meridiem, am or pm '\A' => "'A'", 'A' => 'a', // Uppercase Ante meridiem and Post meridiem, AM or PM, not supported by ICU but we fallback to lowercase '\B' => "'B'", 'B' => '', // Swatch Internet time β€” 000 through 999 '\g' => "'g'", 'g' => 'h', // 12-hour format of an hour without leading zeros β€” 1 through 12 '\G' => "'G'", 'G' => 'H', // 24-hour format of an hour without leading zeros 0 to 23h '\h' => "'h'", 'h' => 'hh', // 12-hour format of an hour with leading zeros, 01 to 12 h '\H' => "'H'", 'H' => 'HH', // 24-hour format of an hour with leading zeros, 00 to 23 h '\i' => "'i'", 'i' => 'mm', // Minutes with leading zeros β€” 00 to 59 '\s' => "'s'", 's' => 'ss', // Seconds, with leading zeros β€” 00 through 59 '\u' => "'u'", 'u' => '', // Microseconds. Example: 654321 // Timezone '\e' => "'e'", 'e' => 'VV', // Timezone identifier. Examples: UTC, GMT, Atlantic/Azores '\I' => "'I'", 'I' => '', // Whether or not the date is in daylight saving time, 1 if Daylight Saving Time, 0 otherwise. '\O' => "'O'", 'O' => 'xx', // Difference to Greenwich time (GMT) in hours, Example: +0200 '\P' => "'P'", 'P' => 'xxx', // Difference to Greenwich time (GMT) with colon between hours and minutes, Example: +02:00 '\T' => "'T'", 'T' => 'zzz', // Timezone abbreviation, Examples: EST, MDT ... '\Z' => "'Z'", 'Z' => '', // Timezone offset in seconds. The offset for timezones west of UTC is always negative, and for those east of UTC is always positive. -43200 through 50400 // Full Date/Time '\c' => "'c'", 'c' => "yyyy-MM-dd'T'HH:mm:ssxxx", // ISO 8601 date, e.g. 2004-02-12T15:19:21+00:00 '\r' => "'r'", 'r' => 'eee, dd MMM yyyy HH:mm:ss xx', // RFC 2822 formatted date, Example: Thu, 21 Dec 2000 16:01:07 +0200 '\U' => "'U'", 'U' => '', // Seconds since the Unix Epoch (January 1 1970 00:00:00 GMT) '\\\\' => '\\', ]); // remove `''` - they're result of consecutive escaped chars (`\A\B` will be `'A''B'`, but should be `'AB'`) // real `'` are encoded as `''''` return strtr($result, [ "''''" => "''", "''" => '', ]); }
Converts a date format pattern from [PHP `date()` function format](https://www.php.net/manual/en/function.date) to [ICU format](https://unicode-org.github.io/icu/userguide/format_parse/datetime/#datetime-format-syntax). Pattern constructs that are not supported by the ICU format will be removed. Since 2.0.13 it handles escaped characters correctly. @param string $pattern date format pattern in PHP `date()` function format. @return string The converted date format pattern.
convertDatePhpToIcu
php
yiisoft/yii2
framework/helpers/BaseFormatConverter.php
https://github.com/yiisoft/yii2/blob/master/framework/helpers/BaseFormatConverter.php
BSD-3-Clause
public static function convertDateIcuToJui($pattern, $type = 'date', $locale = null) { if (isset(self::$_icuShortFormats[$pattern])) { if (extension_loaded('intl')) { $pattern = self::createFormatter($locale, $type, $pattern); } else { return static::$juiFallbackDatePatterns[$pattern][$type]; } } // https://unicode-org.github.io/icu/userguide/format_parse/datetime/#datetime-format-syntax // escaped text $escaped = []; if (preg_match_all('/(?<!\')\'.*?[^\']\'(?!\')/', $pattern, $matches)) { foreach ($matches[0] as $match) { $escaped[$match] = $match; } } return strtr($pattern, array_merge($escaped, [ 'G' => '', // era designator like (Anno Domini) 'Y' => '', // 4digit year of "Week of Year" 'y' => 'yy', // 4digit year e.g. 2014 'yyyy' => 'yy', // 4digit year e.g. 2014 'yy' => 'y', // 2digit year number eg. 14 'u' => '', // extended year e.g. 4601 'U' => '', // cyclic year name, as in Chinese lunar calendar 'r' => '', // related Gregorian year e.g. 1996 'Q' => '', // number of quarter 'QQ' => '', // number of quarter '02' 'QQQ' => '', // quarter 'Q2' 'QQQQ' => '', // quarter '2nd quarter' 'QQQQQ' => '', // number of quarter '2' 'q' => '', // number of Stand Alone quarter 'qq' => '', // number of Stand Alone quarter '02' 'qqq' => '', // Stand Alone quarter 'Q2' 'qqqq' => '', // Stand Alone quarter '2nd quarter' 'qqqqq' => '', // number of Stand Alone quarter '2' 'M' => 'm', // Numeric representation of a month, without leading zeros 'MM' => 'mm', // Numeric representation of a month, with leading zeros 'MMM' => 'M', // A short textual representation of a month, three letters 'MMMM' => 'MM', // A full textual representation of a month, such as January or March 'MMMMM' => '', 'L' => 'm', // Stand alone month in year 'LL' => 'mm', // Stand alone month in year 'LLL' => 'M', // Stand alone month in year 'LLLL' => 'MM', // Stand alone month in year 'LLLLL' => '', // Stand alone month in year 'w' => '', // ISO-8601 week number of year 'ww' => '', // ISO-8601 week number of year 'W' => '', // week of the current month 'd' => 'd', // day without leading zeros 'dd' => 'dd', // day with leading zeros 'D' => 'o', // day of the year 0 to 365 'F' => '', // Day of Week in Month. eg. 2nd Wednesday in July 'g' => '', // Modified Julian day. This is different from the conventional Julian day number in two regards. 'E' => 'D', // day of week written in short form eg. Sun 'EE' => 'D', 'EEE' => 'D', 'EEEE' => 'DD', // day of week fully written eg. Sunday 'EEEEE' => '', 'EEEEEE' => '', 'e' => '', // ISO-8601 numeric representation of the day of the week 1=Mon to 7=Sun 'ee' => '', // php 'w' 0=Sun to 6=Sat isn't supported by ICU -> 'w' means week number of year 'eee' => 'D', 'eeee' => '', 'eeeee' => '', 'eeeeee' => '', 'c' => '', // ISO-8601 numeric representation of the day of the week 1=Mon to 7=Sun 'cc' => '', // php 'w' 0=Sun to 6=Sat isn't supported by ICU -> 'w' means week number of year 'ccc' => 'D', 'cccc' => 'DD', 'ccccc' => '', 'cccccc' => '', 'a' => '', // am/pm marker 'h' => '', // 12-hour format of an hour without leading zeros 1 to 12h 'hh' => '', // 12-hour format of an hour with leading zeros, 01 to 12 h 'H' => '', // 24-hour format of an hour without leading zeros 0 to 23h 'HH' => '', // 24-hour format of an hour with leading zeros, 00 to 23 h 'k' => '', // hour in day (1~24) 'kk' => '', // hour in day (1~24) 'K' => '', // hour in am/pm (0~11) 'KK' => '', // hour in am/pm (0~11) 'm' => '', // Minutes without leading zeros, not supported by php but we fallback 'mm' => '', // Minutes with leading zeros 's' => '', // Seconds, without leading zeros, not supported by php but we fallback 'ss' => '', // Seconds, with leading zeros 'S' => '', // fractional second 'SS' => '', // fractional second 'SSS' => '', // fractional second 'SSSS' => '', // fractional second 'A' => '', // milliseconds in day 'z' => '', // Timezone abbreviation 'zz' => '', // Timezone abbreviation 'zzz' => '', // Timezone abbreviation 'zzzz' => '', // Timezone full name, not supported by php but we fallback 'Z' => '', // Difference to Greenwich time (GMT) in hours 'ZZ' => '', // Difference to Greenwich time (GMT) in hours 'ZZZ' => '', // Difference to Greenwich time (GMT) in hours 'ZZZZ' => '', // Time Zone: long localized GMT (=OOOO) e.g. GMT-08:00 'ZZZZZ' => '', // Time Zone: ISO8601 extended hms? (=XXXXX) 'O' => '', // Time Zone: short localized GMT e.g. GMT-8 'OOOO' => '', // Time Zone: long localized GMT (=ZZZZ) e.g. GMT-08:00 'v' => '', // Time Zone: generic non-location (falls back first to VVVV and then to OOOO) using the ICU defined fallback here 'vvvv' => '', // Time Zone: generic non-location (falls back first to VVVV and then to OOOO) using the ICU defined fallback here 'V' => '', // Time Zone: short time zone ID 'VV' => '', // Time Zone: long time zone ID 'VVV' => '', // Time Zone: time zone exemplar city 'VVVV' => '', // Time Zone: generic location (falls back to OOOO) using the ICU defined fallback here 'X' => '', // Time Zone: ISO8601 basic hm?, with Z for 0, e.g. -08, +0530, Z 'XX' => '', // Time Zone: ISO8601 basic hm, with Z, e.g. -0800, Z 'XXX' => '', // Time Zone: ISO8601 extended hm, with Z, e.g. -08:00, Z 'XXXX' => '', // Time Zone: ISO8601 basic hms?, with Z, e.g. -0800, -075258, Z 'XXXXX' => '', // Time Zone: ISO8601 extended hms?, with Z, e.g. -08:00, -07:52:58, Z 'x' => '', // Time Zone: ISO8601 basic hm?, without Z for 0, e.g. -08, +0530 'xx' => '', // Time Zone: ISO8601 basic hm, without Z, e.g. -0800 'xxx' => '', // Time Zone: ISO8601 extended hm, without Z, e.g. -08:00 'xxxx' => '', // Time Zone: ISO8601 basic hms?, without Z, e.g. -0800, -075258 'xxxxx' => '', // Time Zone: ISO8601 extended hms?, without Z, e.g. -08:00, -07:52:58 ])); }
Converts a date format pattern from [ICU format](https://unicode-org.github.io/icu/userguide/format_parse/datetime/#datetime-format-syntax) to [jQuery UI date format](https://api.jqueryui.com/datepicker/#utility-formatDate). Pattern constructs that are not supported by the jQuery UI format will be removed. @param string $pattern date format pattern in ICU format. @param string $type 'date', 'time', or 'datetime'. @param string|null $locale the locale to use for converting ICU short patterns `short`, `medium`, `long` and `full`. If not given, `Yii::$app->language` will be used. @return string The converted date format pattern. @throws \Exception
convertDateIcuToJui
php
yiisoft/yii2
framework/helpers/BaseFormatConverter.php
https://github.com/yiisoft/yii2/blob/master/framework/helpers/BaseFormatConverter.php
BSD-3-Clause
public static function convertDatePhpToJui($pattern) { // https://www.php.net/manual/en/function.date return strtr($pattern, [ // Day 'd' => 'dd', // Day of the month, 2 digits with leading zeros β€” 01 to 31 'D' => 'D', // A textual representation of a day, three letters β€” Mon through Sun 'j' => 'd', // Day of the month without leading zeros β€” 1 to 31 'l' => 'DD', // A full textual representation of the day of the week β€” Sunday through Saturday 'N' => '', // ISO-8601 numeric representation of the day of the week, 1 (for Monday) through 7 (for Sunday) 'S' => '', // English ordinal suffix for the day of the month, 2 characters β€” st, nd, rd or th. Works well with j 'w' => '', // Numeric representation of the day of the week β€” 0 (for Sunday) through 6 (for Saturday) 'z' => 'o', // The day of the year (starting from 0) β€” 0 through 365 // Week 'W' => '', // ISO-8601 week number of year, weeks starting on Monday (added in PHP 4.1.0) β€” Example: 42 (the 42nd week in the year) // Month 'F' => 'MM', // A full textual representation of a month, January through December 'm' => 'mm', // Numeric representation of a month, with leading zeros β€” 01 through 12 'M' => 'M', // A short textual representation of a month, three letters β€” Jan through Dec 'n' => 'm', // Numeric representation of a month, without leading zeros β€” 1 through 12 't' => '', // Number of days in the given month β€” 28 through 31 // Year 'L' => '', // Whether it's a leap year, 1 if it is a leap year, 0 otherwise. 'o' => '', // ISO-8601 year number. This has the same value as Y, except that if the ISO week number (W) belongs to the previous or next year, that year is used instead. 'Y' => 'yy', // A full numeric representation of a year, 4 digits β€” Examples: 1999 or 2003 'y' => 'y', // A two digit representation of a year β€” Examples: 99 or 03 // Time 'a' => '', // Lowercase Ante meridiem and Post meridiem, am or pm 'A' => '', // Uppercase Ante meridiem and Post meridiem, AM or PM, not supported by ICU but we fallback to lowercase 'B' => '', // Swatch Internet time β€” 000 through 999 'g' => '', // 12-hour format of an hour without leading zeros β€” 1 through 12 'G' => '', // 24-hour format of an hour without leading zeros 0 to 23h 'h' => '', // 12-hour format of an hour with leading zeros, 01 to 12 h 'H' => '', // 24-hour format of an hour with leading zeros, 00 to 23 h 'i' => '', // Minutes with leading zeros β€” 00 to 59 's' => '', // Seconds, with leading zeros β€” 00 through 59 'u' => '', // Microseconds. Example: 654321 // Timezone 'e' => '', // Timezone identifier. Examples: UTC, GMT, Atlantic/Azores 'I' => '', // Whether or not the date is in daylight saving time, 1 if Daylight Saving Time, 0 otherwise. 'O' => '', // Difference to Greenwich time (GMT) in hours, Example: +0200 'P' => '', // Difference to Greenwich time (GMT) with colon between hours and minutes, Example: +02:00 'T' => '', // Timezone abbreviation, Examples: EST, MDT ... 'Z' => '', // Timezone offset in seconds. The offset for timezones west of UTC is always negative, and for those east of UTC is always positive. -43200 through 50400 // Full Date/Time 'c' => 'yyyy-MM-dd', // ISO 8601 date, e.g. 2004-02-12T15:19:21+00:00, skipping the time here because it is not supported 'r' => 'D, d M yy', // RFC 2822 formatted date, Example: Thu, 21 Dec 2000 16:01:07 +0200, skipping the time here because it is not supported 'U' => '@', // Seconds since the Unix Epoch (January 1 1970 00:00:00 GMT) ]); }
Converts a date format pattern from [PHP `date()` function format](https://www.php.net/manual/en/function.date) to [jQuery UI date format](https://api.jqueryui.com/datepicker/#utility-formatDate). The conversion is limited to date patterns that do not use escaped characters. Patterns like `jS \o\f F Y` which will result in a date like `1st of December 2014` may not be converted correctly because of the use of escaped characters. Pattern constructs that are not supported by the jQuery UI format will be removed. @param string $pattern date format pattern in PHP `date()` function format. @return string The converted date format pattern.
convertDatePhpToJui
php
yiisoft/yii2
framework/helpers/BaseFormatConverter.php
https://github.com/yiisoft/yii2/blob/master/framework/helpers/BaseFormatConverter.php
BSD-3-Clause