code
stringlengths 17
296k
| 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 getName()
{
return basename($this->getId());
} | Returns the name of this module.
The default implementation simply returns {@link id}.
You may override this method to customize the name of this module.
@return string the name of this module. | getName | php | yiisoft/yii | framework/web/CWebModule.php | https://github.com/yiisoft/yii/blob/master/framework/web/CWebModule.php | BSD-3-Clause |
public function getDescription()
{
return '';
} | Returns the description of this module.
The default implementation returns an empty string.
You may override this method to customize the description of this module.
@return string the description of this module. | getDescription | php | yiisoft/yii | framework/web/CWebModule.php | https://github.com/yiisoft/yii/blob/master/framework/web/CWebModule.php | BSD-3-Clause |
public function getVersion()
{
return '1.0';
} | Returns the version of this module.
The default implementation returns '1.0'.
You may override this method to customize the version of this module.
@return string the version of this module. | getVersion | php | yiisoft/yii | framework/web/CWebModule.php | https://github.com/yiisoft/yii/blob/master/framework/web/CWebModule.php | BSD-3-Clause |
public function getControllerPath()
{
if($this->_controllerPath!==null)
return $this->_controllerPath;
else
return $this->_controllerPath=$this->getBasePath().DIRECTORY_SEPARATOR.'controllers';
} | @return string the directory that contains the controller classes. Defaults to 'moduleDir/controllers' where
moduleDir is the directory containing the module class. | getControllerPath | php | yiisoft/yii | framework/web/CWebModule.php | https://github.com/yiisoft/yii/blob/master/framework/web/CWebModule.php | BSD-3-Clause |
public function getViewPath()
{
if($this->_viewPath!==null)
return $this->_viewPath;
else
return $this->_viewPath=$this->getBasePath().DIRECTORY_SEPARATOR.'views';
} | @return string the root directory of view files. Defaults to 'moduleDir/views' where
moduleDir is the directory containing the module class. | getViewPath | php | yiisoft/yii | framework/web/CWebModule.php | https://github.com/yiisoft/yii/blob/master/framework/web/CWebModule.php | BSD-3-Clause |
public function getLayoutPath()
{
if($this->_layoutPath!==null)
return $this->_layoutPath;
else
return $this->_layoutPath=$this->getViewPath().DIRECTORY_SEPARATOR.'layouts';
} | @return string the root directory of layout files. Defaults to 'moduleDir/views/layouts' where
moduleDir is the directory containing the module class. | getLayoutPath | php | yiisoft/yii | framework/web/CWebModule.php | https://github.com/yiisoft/yii/blob/master/framework/web/CWebModule.php | BSD-3-Clause |
public function afterControllerAction($controller,$action)
{
if(($parent=$this->getParentModule())===null)
$parent=Yii::app();
$parent->afterControllerAction($controller,$action);
} | The post-filter for controller actions.
This method is invoked after the currently requested controller action and all its filters
are executed. If you override this method, make sure you call the parent implementation at the end.
@param CController $controller the controller
@param CAction $action the action | afterControllerAction | php | yiisoft/yii | framework/web/CWebModule.php | https://github.com/yiisoft/yii/blob/master/framework/web/CWebModule.php | BSD-3-Clause |
public function getId()
{
return $this->_id;
} | Returns the ID that uniquely identifies the data provider.
@return string the unique ID that uniquely identifies the data provider among all data providers. | getId | php | yiisoft/yii | framework/web/CDataProvider.php | https://github.com/yiisoft/yii/blob/master/framework/web/CDataProvider.php | BSD-3-Clause |
public function getPagination($className='CPagination')
{
if($this->_pagination===null)
{
$this->_pagination=new $className;
if(($id=$this->getId())!='')
$this->_pagination->pageVar=$id.'_page';
}
return $this->_pagination;
} | Returns the pagination object.
@param string $className the pagination object class name. Parameter is available since version 1.1.13.
@return CPagination|false the pagination object. If this is false, it means the pagination is disabled. | getPagination | php | yiisoft/yii | framework/web/CDataProvider.php | https://github.com/yiisoft/yii/blob/master/framework/web/CDataProvider.php | BSD-3-Clause |
public function setPagination($value)
{
if(is_array($value))
{
if(isset($value['class']))
{
$pagination=$this->getPagination($value['class']);
unset($value['class']);
}
else
$pagination=$this->getPagination();
foreach($value as $k=>$v)
$pagination->$k=$v;
}
else
$this->_pagination=$value;
} | Sets the pagination for this data provider.
@param mixed $value the pagination to be used by this data provider. This could be a {@link CPagination} object
or an array used to configure the pagination object. If this is false, it means the pagination should be disabled.
You can configure this property same way as a component:
<pre>
array(
'class' => 'MyPagination',
'pageSize' => 20,
),
</pre> | setPagination | php | yiisoft/yii | framework/web/CDataProvider.php | https://github.com/yiisoft/yii/blob/master/framework/web/CDataProvider.php | BSD-3-Clause |
public function setSort($value)
{
if(is_array($value))
{
if(isset($value['class']))
{
$sort=$this->getSort($value['class']);
unset($value['class']);
}
else
$sort=$this->getSort();
foreach($value as $k=>$v)
$sort->$k=$v;
}
else
$this->_sort=$value;
} | Sets the sorting for this data provider.
@param mixed $value the sorting to be used by this data provider. This could be a {@link CSort} object
or an array used to configure the sorting object. If this is false, it means the sorting should be disabled.
You can configure this property same way as a component:
<pre>
array(
'class' => 'MySort',
'attributes' => array('name', 'weight'),
),
</pre> | setSort | php | yiisoft/yii | framework/web/CDataProvider.php | https://github.com/yiisoft/yii/blob/master/framework/web/CDataProvider.php | BSD-3-Clause |
public function getData($refresh=false)
{
if($this->_data===null || $refresh)
$this->_data=$this->fetchData();
return $this->_data;
} | Returns the data items currently available.
@param boolean $refresh whether the data should be re-fetched from persistent storage.
@return array the list of data items currently available in this data provider. | getData | php | yiisoft/yii | framework/web/CDataProvider.php | https://github.com/yiisoft/yii/blob/master/framework/web/CDataProvider.php | BSD-3-Clause |
public function setData($value)
{
$this->_data=$value;
} | Sets the data items for this provider.
@param array $value put the data items into this provider. | setData | php | yiisoft/yii | framework/web/CDataProvider.php | https://github.com/yiisoft/yii/blob/master/framework/web/CDataProvider.php | BSD-3-Clause |
public function setKeys($value)
{
$this->_keys=$value;
} | Sets the data item keys for this provider.
@param array $value put the data item keys into this provider. | setKeys | php | yiisoft/yii | framework/web/CDataProvider.php | https://github.com/yiisoft/yii/blob/master/framework/web/CDataProvider.php | BSD-3-Clause |
public function getItemCount($refresh=false)
{
return count($this->getData($refresh));
} | Returns the number of data items in the current page.
This is equivalent to <code>count($provider->getData())</code>.
When {@link pagination} is set false, this returns the same value as {@link totalItemCount}.
@param boolean $refresh whether the number of data items should be re-calculated.
@return integer the number of data items in the current page. | getItemCount | php | yiisoft/yii | framework/web/CDataProvider.php | https://github.com/yiisoft/yii/blob/master/framework/web/CDataProvider.php | BSD-3-Clause |
public function getTotalItemCount($refresh=false)
{
if($this->_totalItemCount===null || $refresh)
$this->_totalItemCount=$this->calculateTotalItemCount();
return $this->_totalItemCount;
} | Returns the total number of data items.
When {@link pagination} is set false, this returns the same value as {@link itemCount}.
@param boolean $refresh whether the total number of data items should be re-calculated.
@return integer total number of possible data items. | getTotalItemCount | php | yiisoft/yii | framework/web/CDataProvider.php | https://github.com/yiisoft/yii/blob/master/framework/web/CDataProvider.php | BSD-3-Clause |
public function setTotalItemCount($value)
{
$this->_totalItemCount=$value;
} | Sets the total number of data items.
This method is provided in case when the total number cannot be determined by {@link calculateTotalItemCount}.
@param integer $value the total number of data items.
@since 1.1.1 | setTotalItemCount | php | yiisoft/yii | framework/web/CDataProvider.php | https://github.com/yiisoft/yii/blob/master/framework/web/CDataProvider.php | BSD-3-Clause |
public function init()
{
$this->_cache=Yii::app()->getComponent($this->cacheID);
if(!($this->_cache instanceof ICache))
throw new CException(Yii::t('yii','CCacheHttpSession.cacheID is invalid. Please make sure "{id}" refers to a valid cache application component.',
array('{id}'=>$this->cacheID)));
parent::init();
} | Initializes the application component.
This method overrides the parent implementation by checking if cache is available. | init | php | yiisoft/yii | framework/web/CCacheHttpSession.php | https://github.com/yiisoft/yii/blob/master/framework/web/CCacheHttpSession.php | BSD-3-Clause |
public function getUseCustomStorage()
{
return true;
} | Returns a value indicating whether to use custom session storage.
This method overrides the parent implementation and always returns true.
@return boolean whether to use custom storage. | getUseCustomStorage | php | yiisoft/yii | framework/web/CCacheHttpSession.php | https://github.com/yiisoft/yii/blob/master/framework/web/CCacheHttpSession.php | BSD-3-Clause |
public function readSession($id)
{
$data=$this->_cache->get($this->calculateKey($id));
return $data===false?'':$data;
} | Session read handler.
Do not call this method directly.
@param string $id session ID
@return string the session data | readSession | php | yiisoft/yii | framework/web/CCacheHttpSession.php | https://github.com/yiisoft/yii/blob/master/framework/web/CCacheHttpSession.php | BSD-3-Clause |
public function writeSession($id,$data)
{
return $this->_cache->set($this->calculateKey($id),$data,$this->getTimeout());
} | Session write handler.
Do not call this method directly.
@param string $id session ID
@param string $data session data
@return boolean whether session write is successful | writeSession | php | yiisoft/yii | framework/web/CCacheHttpSession.php | https://github.com/yiisoft/yii/blob/master/framework/web/CCacheHttpSession.php | BSD-3-Clause |
protected function calculateKey($id)
{
return self::CACHE_KEY_PREFIX.$id;
} | Generates a unique key used for storing session data in cache.
@param string $id session variable name
@return string a safe cache key associated with the session variable name | calculateKey | php | yiisoft/yii | framework/web/CCacheHttpSession.php | https://github.com/yiisoft/yii/blob/master/framework/web/CCacheHttpSession.php | BSD-3-Clause |
public function getUseCustomStorage()
{
return true;
} | Returns a value indicating whether to use custom session storage.
This method overrides the parent implementation and always returns true.
@return boolean whether to use custom storage. | getUseCustomStorage | php | yiisoft/yii | framework/web/CDbHttpSession.php | https://github.com/yiisoft/yii/blob/master/framework/web/CDbHttpSession.php | BSD-3-Clause |
public function regenerateID($deleteOldSession=false)
{
$oldID=session_id();
// if no session is started, there is nothing to regenerate
if(empty($oldID))
return;
parent::regenerateID(false);
$newID=session_id();
$db=$this->getDbConnection();
$row=$db->createCommand()
->select()
->from($this->sessionTableName)
->where('id=:id',array(':id'=>$oldID))
->queryRow();
if($row!==false)
{
if($deleteOldSession)
$db->createCommand()->update($this->sessionTableName,array(
'id'=>$newID
),'id=:oldID',array(':oldID'=>$oldID));
else
{
$row['id']=$newID;
$db->createCommand()->insert($this->sessionTableName, $row);
}
}
else
{
// shouldn't reach here normally
$db->createCommand()->insert($this->sessionTableName, array(
'id'=>$newID,
'expire'=>time()+$this->getTimeout(),
'data'=>'',
));
}
} | Updates the current session id with a newly generated one.
Please refer to {@link https://php.net/session_regenerate_id} for more details.
@param boolean $deleteOldSession Whether to delete the old associated session file or not.
@since 1.1.8 | regenerateID | php | yiisoft/yii | framework/web/CDbHttpSession.php | https://github.com/yiisoft/yii/blob/master/framework/web/CDbHttpSession.php | BSD-3-Clause |
public function openSession($savePath,$sessionName)
{
if($this->autoCreateSessionTable)
{
$db=$this->getDbConnection();
$db->setActive(true);
try
{
$db->createCommand()->delete($this->sessionTableName,'expire<:expire',array(':expire'=>time()));
}
catch(Exception $e)
{
$this->createSessionTable($db,$this->sessionTableName);
}
}
return true;
} | Session open handler.
Do not call this method directly.
@param string $savePath session save path
@param string $sessionName session name
@return boolean whether session is opened successfully | openSession | php | yiisoft/yii | framework/web/CDbHttpSession.php | https://github.com/yiisoft/yii/blob/master/framework/web/CDbHttpSession.php | BSD-3-Clause |
public function writeSession($id,$data)
{
// exception must be caught in session write handler
// https://us.php.net/manual/en/function.session-set-save-handler.php
try
{
$expire=time()+$this->getTimeout();
$db=$this->getDbConnection();
if($db->getDriverName()=='pgsql')
$data=new CDbExpression($db->quoteValueWithType($data, PDO::PARAM_LOB)."::bytea");
if($db->getDriverName()=='sqlsrv' || $db->getDriverName()=='mssql' || $db->getDriverName()=='dblib')
$data=new CDbExpression('CONVERT(VARBINARY(MAX), '.$db->quoteValue($data).')');
if($db->createCommand()->select('id')->from($this->sessionTableName)->where('id=:id',array(':id'=>$id))->queryScalar()===false)
$db->createCommand()->insert($this->sessionTableName,array(
'id'=>$id,
'data'=>$data,
'expire'=>$expire,
));
else
$db->createCommand()->update($this->sessionTableName,array(
'data'=>$data,
'expire'=>$expire
),'id=:id',array(':id'=>$id));
}
catch(Exception $e)
{
if(YII_DEBUG)
echo $e->getMessage();
// it is too late to log an error message here
return false;
}
return true;
} | Session write handler.
Do not call this method directly.
@param string $id session ID
@param string $data session data
@return boolean whether session write is successful | writeSession | php | yiisoft/yii | framework/web/CDbHttpSession.php | https://github.com/yiisoft/yii/blob/master/framework/web/CDbHttpSession.php | BSD-3-Clause |
public function destroySession($id)
{
$this->getDbConnection()->createCommand()
->delete($this->sessionTableName,'id=:id',array(':id'=>$id));
return true;
} | Session destroy handler.
Do not call this method directly.
@param string $id session ID
@return boolean whether session is destroyed successfully | destroySession | php | yiisoft/yii | framework/web/CDbHttpSession.php | https://github.com/yiisoft/yii/blob/master/framework/web/CDbHttpSession.php | BSD-3-Clause |
public function gcSession($maxLifetime)
{
$this->getDbConnection()->createCommand()
->delete($this->sessionTableName,'expire<:expire',array(':expire'=>time()));
return true;
} | Session GC (garbage collection) handler.
Do not call this method directly.
@param integer $maxLifetime the number of seconds after which data will be seen as 'garbage' and cleaned up.
@return boolean whether session is GCed successfully | gcSession | php | yiisoft/yii | framework/web/CDbHttpSession.php | https://github.com/yiisoft/yii/blob/master/framework/web/CDbHttpSession.php | BSD-3-Clause |
public function getRequestedView()
{
if($this->_viewPath===null)
{
if(!empty($_GET[$this->viewParam]) && is_string($_GET[$this->viewParam]))
$this->_viewPath=$_GET[$this->viewParam];
else
$this->_viewPath=$this->defaultView;
}
return $this->_viewPath;
} | Returns the name of the view requested by the user.
If the user doesn't specify any view, the {@link defaultView} will be returned.
@return string the name of the view requested by the user.
This is in the format of 'path.to.view'. | getRequestedView | php | yiisoft/yii | framework/web/actions/CViewAction.php | https://github.com/yiisoft/yii/blob/master/framework/web/actions/CViewAction.php | BSD-3-Clause |
protected function resolveView($viewPath)
{
// start with a word char and have word chars, dots and dashes only
if(preg_match('/^\w[\w\.\-]*$/',$viewPath))
{
$view=strtr($viewPath,'.','/');
if(!empty($this->basePath))
$view=$this->basePath.'/'.$view;
if($this->getController()->getViewFile($view)!==false)
{
$this->view=$view;
return;
}
}
throw new CHttpException(404,Yii::t('yii','The requested view "{name}" was not found.',
array('{name}'=>$viewPath)));
} | Resolves the user-specified view into a valid view name.
@param string $viewPath user-specified view in the format of 'path.to.view'.
@throws CHttpException if the user-specified view is invalid | resolveView | php | yiisoft/yii | framework/web/actions/CViewAction.php | https://github.com/yiisoft/yii/blob/master/framework/web/actions/CViewAction.php | BSD-3-Clause |
public function run()
{
$this->resolveView($this->getRequestedView());
$controller=$this->getController();
if($this->layout!==null)
{
$layout=$controller->layout;
$controller->layout=$this->layout;
}
$this->onBeforeRender($event=new CEvent($this));
if(!$event->handled)
{
if($this->renderAsText)
{
$text=file_get_contents($controller->getViewFile($this->view));
$controller->renderText($text);
}
else
$controller->render($this->view);
$this->onAfterRender(new CEvent($this));
}
if($this->layout!==null)
$controller->layout=$layout;
} | Runs the action.
This method displays the view requested by the user.
@throws CHttpException if the view is invalid | run | php | yiisoft/yii | framework/web/actions/CViewAction.php | https://github.com/yiisoft/yii/blob/master/framework/web/actions/CViewAction.php | BSD-3-Clause |
public function onBeforeRender($event)
{
$this->raiseEvent('onBeforeRender',$event);
} | Raised right before the action invokes the render method.
Event handlers can set the {@link CEvent::handled} property
to be true to stop further view rendering.
@param CEvent $event event parameter | onBeforeRender | php | yiisoft/yii | framework/web/actions/CViewAction.php | https://github.com/yiisoft/yii/blob/master/framework/web/actions/CViewAction.php | BSD-3-Clause |
public function onAfterRender($event)
{
$this->raiseEvent('onAfterRender',$event);
} | Raised right after the action invokes the render method.
@param CEvent $event event parameter | onAfterRender | php | yiisoft/yii | framework/web/actions/CViewAction.php | https://github.com/yiisoft/yii/blob/master/framework/web/actions/CViewAction.php | BSD-3-Clause |
public function runWithParams($params)
{
$method=new ReflectionMethod($this, 'run');
if($method->getNumberOfParameters()>0)
return $this->runWithParamsInternal($this, $method, $params);
$this->run();
return true;
} | Runs the action with the supplied request parameters.
This method is internally called by {@link CController::runAction()}.
@param array $params the request parameters (name=>value)
@return boolean whether the request parameters are valid
@since 1.1.7 | runWithParams | php | yiisoft/yii | framework/web/actions/CAction.php | https://github.com/yiisoft/yii/blob/master/framework/web/actions/CAction.php | BSD-3-Clause |
public function run()
{
$method='action'.$this->getId();
$this->getController()->$method();
} | Runs the action.
The action method defined in the controller is invoked.
This method is required by {@link CAction}. | run | php | yiisoft/yii | framework/web/actions/CInlineAction.php | https://github.com/yiisoft/yii/blob/master/framework/web/actions/CInlineAction.php | BSD-3-Clause |
public function runWithParams($params)
{
$methodName='action'.$this->getId();
$controller=$this->getController();
$method=new ReflectionMethod($controller, $methodName);
if($method->getNumberOfParameters()>0)
return $this->runWithParamsInternal($controller, $method, $params);
$controller->$methodName();
return true;
} | Runs the action with the supplied request parameters.
This method is internally called by {@link CController::runAction()}.
@param array $params the request parameters (name=>value)
@return boolean whether the request parameters are valid
@since 1.1.7 | runWithParams | php | yiisoft/yii | framework/web/actions/CInlineAction.php | https://github.com/yiisoft/yii/blob/master/framework/web/actions/CInlineAction.php | BSD-3-Clause |
public static function encode($text)
{
return htmlspecialchars((string)$text,ENT_QUOTES,Yii::app()->charset);
} | Encodes special characters into HTML entities.
The {@link CApplication::charset application charset} will be used for encoding.
@param string $text data to be encoded
@return string the encoded data
@see https://www.php.net/manual/en/function.htmlspecialchars.php | encode | php | yiisoft/yii | framework/web/helpers/CHtml.php | https://github.com/yiisoft/yii/blob/master/framework/web/helpers/CHtml.php | BSD-3-Clause |
public static function decode($text)
{
return htmlspecialchars_decode($text,ENT_QUOTES);
} | Decodes special HTML entities back to the corresponding characters.
This is the opposite of {@link encode()}.
@param string $text data to be decoded
@return string the decoded data
@see https://www.php.net/manual/en/function.htmlspecialchars-decode.php
@since 1.1.8 | decode | php | yiisoft/yii | framework/web/helpers/CHtml.php | https://github.com/yiisoft/yii/blob/master/framework/web/helpers/CHtml.php | BSD-3-Clause |
public static function closeTag($tag)
{
return '</'.$tag.'>';
} | Generates a close HTML element.
@param string $tag the tag name
@return string the generated HTML element tag | closeTag | php | yiisoft/yii | framework/web/helpers/CHtml.php | https://github.com/yiisoft/yii/blob/master/framework/web/helpers/CHtml.php | BSD-3-Clause |
public static function cdata($text)
{
return '<![CDATA[' . $text . ']]>';
} | Encloses the given string within a CDATA tag.
@param string $text the string to be enclosed
@return string the CDATA tag with the enclosed content. | cdata | php | yiisoft/yii | framework/web/helpers/CHtml.php | https://github.com/yiisoft/yii/blob/master/framework/web/helpers/CHtml.php | BSD-3-Clause |
public static function css($text,$media='')
{
if($media!=='')
$media=' media="'.$media.'"';
if(self::$cdataScriptAndStyleContents)
$text="/*<![CDATA[*/\n{$text}\n/*]]>*/";
return "<style type=\"text/css\"{$media}>\n{$text}\n</style>";
} | Encloses the given CSS content with a CSS tag.
@param string $text the CSS content
@param string $media the media that this CSS should apply to.
@return string the CSS properly enclosed | css | php | yiisoft/yii | framework/web/helpers/CHtml.php | https://github.com/yiisoft/yii/blob/master/framework/web/helpers/CHtml.php | BSD-3-Clause |
public static function refresh($seconds,$url='')
{
$content="$seconds";
if($url!=='')
$content.=';url='.self::normalizeUrl($url);
Yii::app()->clientScript->registerMetaTag($content,null,'refresh');
} | Registers a 'refresh' meta tag.
This method can be invoked anywhere in a view. It will register a 'refresh'
meta tag with {@link CClientScript} so that the page can be refreshed in
the specified seconds.
@param integer $seconds the number of seconds to wait before refreshing the page
@param string $url the URL to which the page should be redirected to. If empty, it means the current page.
@since 1.1.1 | refresh | php | yiisoft/yii | framework/web/helpers/CHtml.php | https://github.com/yiisoft/yii/blob/master/framework/web/helpers/CHtml.php | BSD-3-Clause |
public static function cssFile($url,$media='')
{
return CHtml::linkTag('stylesheet','text/css',$url,$media!=='' ? $media : null);
} | Links to the specified CSS file.
@param string $url the CSS URL
@param string $media the media that this CSS should apply to.
@return string the CSS link. | cssFile | php | yiisoft/yii | framework/web/helpers/CHtml.php | https://github.com/yiisoft/yii/blob/master/framework/web/helpers/CHtml.php | BSD-3-Clause |
public static function pageStateField($value)
{
return '<input type="hidden" name="'.CController::STATE_INPUT_NAME.'" value="'.$value.'" />';
} | Generates a hidden field for storing persistent page states.
This method is internally used by {@link statefulForm}.
@param string $value the persistent page states in serialized format
@return string the generated hidden field | pageStateField | php | yiisoft/yii | framework/web/helpers/CHtml.php | https://github.com/yiisoft/yii/blob/master/framework/web/helpers/CHtml.php | BSD-3-Clause |
public static function asset($path,$hashByName=false)
{
return Yii::app()->getAssetManager()->publish($path,$hashByName);
} | Generates the URL for the published assets.
@param string $path the path of the asset to be published
@param boolean $hashByName whether the published directory should be named as the hashed basename.
If false, the name will be the hashed dirname of the path being published.
Defaults to false. Set true if the path being published is shared among
different extensions.
@return string the asset URL | asset | php | yiisoft/yii | framework/web/helpers/CHtml.php | https://github.com/yiisoft/yii/blob/master/framework/web/helpers/CHtml.php | BSD-3-Clause |
public static function normalizeUrl($url)
{
if(is_array($url))
{
if(isset($url[0]))
{
if(($c=Yii::app()->getController())!==null)
$url=$c->createUrl($url[0],array_splice($url,1));
else
$url=Yii::app()->createUrl($url[0],array_splice($url,1));
}
else
$url='';
}
return $url==='' ? Yii::app()->getRequest()->getUrl() : $url;
} | Normalizes the input parameter to be a valid URL.
If the input parameter is an empty string, the currently requested URL will be returned.
If the input parameter is a non-empty string, it is treated as a valid URL and will
be returned without any change.
If the input parameter is an array, it is treated as a controller route and a list of
GET parameters, and the {@link CController::createUrl} method will be invoked to
create a URL. In this case, the first array element refers to the controller route,
and the rest key-value pairs refer to the additional GET parameters for the URL.
For example, <code>array('post/list', 'page'=>3)</code> may be used to generate the URL
<code>/index.php?r=post/list&page=3</code>.
@param mixed $url the parameter to be used to generate a valid URL
@return string the normalized URL | normalizeUrl | php | yiisoft/yii | framework/web/helpers/CHtml.php | https://github.com/yiisoft/yii/blob/master/framework/web/helpers/CHtml.php | BSD-3-Clause |
protected static function inputField($type,$name,$value,$htmlOptions)
{
$htmlOptions['type']=$type;
$htmlOptions['value']=$value;
$htmlOptions['name']=$name;
if(!isset($htmlOptions['id']))
$htmlOptions['id']=self::getIdByName($name);
elseif($htmlOptions['id']===false)
unset($htmlOptions['id']);
return self::tag('input',$htmlOptions);
} | Generates an input HTML tag.
This method generates an input HTML tag based on the given input name and value.
@param string $type the input type (e.g. 'text', 'radio')
@param string $name the input name
@param string $value the input value
@param array $htmlOptions additional HTML attributes for the HTML tag (see {@link tag}).
@return string the generated input tag | inputField | php | yiisoft/yii | framework/web/helpers/CHtml.php | https://github.com/yiisoft/yii/blob/master/framework/web/helpers/CHtml.php | BSD-3-Clause |
public static function getIdByName($name)
{
return str_replace(array('[]','][','[',']',' '),array('','_','_','','_'),$name);
} | Generates a valid HTML ID based on name.
@param string $name name from which to generate HTML ID
@return string the ID generated based on name. | getIdByName | php | yiisoft/yii | framework/web/helpers/CHtml.php | https://github.com/yiisoft/yii/blob/master/framework/web/helpers/CHtml.php | BSD-3-Clause |
public static function activeId($model,$attribute)
{
return self::getIdByName(self::activeName($model,$attribute));
} | Generates input field ID for a model attribute.
@param CModel|string $model the data model
@param string $attribute the attribute
@return string the generated input field ID | activeId | php | yiisoft/yii | framework/web/helpers/CHtml.php | https://github.com/yiisoft/yii/blob/master/framework/web/helpers/CHtml.php | BSD-3-Clause |
public static function modelName($model)
{
if(is_callable(self::$_modelNameConverter))
return call_user_func(self::$_modelNameConverter,$model);
$className=is_object($model) ? get_class($model) : (string)$model;
return trim(str_replace('\\','_',$className),'_');
} | Generates HTML name for given model.
@see CHtml::setModelNameConverter()
@param CModel|string $model the data model or the model class name
@return string the generated HTML name value
@since 1.1.14 | modelName | php | yiisoft/yii | framework/web/helpers/CHtml.php | https://github.com/yiisoft/yii/blob/master/framework/web/helpers/CHtml.php | BSD-3-Clause |
public static function setModelNameConverter($converter)
{
if(is_callable($converter))
self::$_modelNameConverter=$converter;
elseif($converter===null)
self::$_modelNameConverter=null;
else
throw new CException(Yii::t('yii','The $converter argument must be a valid callback or null.'));
} | Set generator used in the {@link CHtml::modelName()} method. You can use the `null` value to restore default
generator.
@param callable|null $converter the new generator, the model or class name will be passed to this callback
and result must be a valid value for HTML name attribute.
@throws CException if $converter isn't a valid callback
@since 1.1.14 | setModelNameConverter | php | yiisoft/yii | framework/web/helpers/CHtml.php | https://github.com/yiisoft/yii/blob/master/framework/web/helpers/CHtml.php | BSD-3-Clause |
public static function activeName($model,$attribute)
{
$a=$attribute; // because the attribute name may be changed by resolveName
return self::resolveName($model,$a);
} | Generates input field name for a model attribute.
Unlike {@link resolveName}, this method does NOT modify the attribute name.
@param CModel|string $model the data model
@param string $attribute the attribute
@return string the generated input field name | activeName | php | yiisoft/yii | framework/web/helpers/CHtml.php | https://github.com/yiisoft/yii/blob/master/framework/web/helpers/CHtml.php | BSD-3-Clause |
protected static function activeInputField($type,$model,$attribute,$htmlOptions)
{
$htmlOptions['type']=$type;
if($type==='text'||$type==='password'||$type==='color'||$type==='date'||$type==='datetime'||
$type==='datetime-local'||$type==='email'||$type==='month'||$type==='number'||$type==='range'||
$type==='search'||$type==='tel'||$type==='time'||$type==='url'||$type==='week')
{
if(!isset($htmlOptions['maxlength']))
{
foreach($model->getValidators($attribute) as $validator)
{
if($validator instanceof CStringValidator && $validator->max!==null)
{
$htmlOptions['maxlength']=$validator->max;
break;
}
}
}
elseif($htmlOptions['maxlength']===false)
unset($htmlOptions['maxlength']);
}
if($type==='file')
unset($htmlOptions['value']);
elseif(!isset($htmlOptions['value']))
$htmlOptions['value']=self::resolveValue($model,$attribute);
if($model->hasErrors($attribute))
self::addErrorCss($htmlOptions);
return self::tag('input',$htmlOptions);
} | Generates an input HTML tag for a model attribute.
This method generates an input HTML tag based on the given data model and attribute.
If the attribute has input error, the input field's CSS class will
be appended with {@link errorCss}.
This enables highlighting the incorrect input.
@param string $type the input type (e.g. 'text', 'radio')
@param CModel $model the data model
@param string $attribute the attribute
@param array $htmlOptions additional HTML attributes for the HTML tag
@return string the generated input tag | activeInputField | php | yiisoft/yii | framework/web/helpers/CHtml.php | https://github.com/yiisoft/yii/blob/master/framework/web/helpers/CHtml.php | BSD-3-Clause |
protected static function clientChange($event,&$htmlOptions)
{
if(!isset($htmlOptions['submit']) && !isset($htmlOptions['confirm']) && !isset($htmlOptions['ajax']))
return;
if(isset($htmlOptions['live']))
{
$live=$htmlOptions['live'];
unset($htmlOptions['live']);
}
else
$live = self::$liveEvents;
if(isset($htmlOptions['return']) && $htmlOptions['return'])
$return='return true';
else
$return='return false';
if(isset($htmlOptions['on'.$event]))
{
$handler=trim($htmlOptions['on'.$event],';').';';
unset($htmlOptions['on'.$event]);
}
else
$handler='';
if(isset($htmlOptions['id']))
$id=$htmlOptions['id'];
else
$id=$htmlOptions['id']=isset($htmlOptions['name'])?$htmlOptions['name']:self::ID_PREFIX.self::$count++;
$cs=Yii::app()->getClientScript();
$cs->registerCoreScript('jquery');
if(isset($htmlOptions['submit']))
{
$cs->registerCoreScript('yii');
$request=Yii::app()->getRequest();
if($request->enableCsrfValidation && isset($htmlOptions['csrf']) && $htmlOptions['csrf'])
$htmlOptions['params'][$request->csrfTokenName]=$request->getCsrfToken();
if(isset($htmlOptions['params']))
$params=CJavaScript::encode($htmlOptions['params']);
else
$params='{}';
if($htmlOptions['submit']!=='')
$url=CJavaScript::quote(self::normalizeUrl($htmlOptions['submit']));
else
$url='';
$handler.="jQuery.yii.submitForm(this,'$url',$params);{$return};";
}
if(isset($htmlOptions['ajax']))
$handler.=self::ajax($htmlOptions['ajax'])."{$return};";
if(isset($htmlOptions['confirm']))
{
$confirm='confirm(\''.CJavaScript::quote($htmlOptions['confirm']).'\')';
if($handler!=='')
$handler="if($confirm) {".$handler."} else return false;";
else
$handler="return $confirm;";
}
if($live)
$cs->registerScript('Yii.CHtml.#' . $id,"jQuery('body').on('$event','#$id',function(){{$handler}});");
else
$cs->registerScript('Yii.CHtml.#' . $id,"jQuery('#$id').on('$event', function(){{$handler}});");
unset($htmlOptions['params'],$htmlOptions['submit'],$htmlOptions['ajax'],$htmlOptions['confirm'],$htmlOptions['return'],$htmlOptions['csrf']);
} | Generates the JavaScript with the specified client changes.
@param string $event event name (without 'on')
@param array $htmlOptions HTML attributes which may contain the following special attributes
specifying the client change behaviors:
<ul>
<li>submit: string, specifies the URL to submit to. If the current element has a parent form, that form will be
submitted, and if 'submit' is non-empty its value will replace the form's URL. If there is no parent form the
data listed in 'params' will be submitted instead (via POST method), to the URL in 'submit' or the currently
requested URL if 'submit' is empty. Please note that if the 'csrf' setting is true, the CSRF token will be
included in the params too.</li>
<li>params: array, name-value pairs that should be submitted together with the form. This is only used when 'submit' option is specified.</li>
<li>csrf: boolean, whether a CSRF token should be automatically included in 'params' when {@link CHttpRequest::enableCsrfValidation} is true. Defaults to false.
You may want to set this to be true if there is no enclosing form around this element.
This option is meaningful only when 'submit' option is set.</li>
<li>return: boolean, the return value of the javascript. Defaults to false, meaning that the execution of
javascript would not cause the default behavior of the event.</li>
<li>confirm: string, specifies the message that should show in a pop-up confirmation dialog.</li>
<li>ajax: array, specifies the AJAX options (see {@link ajax}).</li>
<li>live: boolean, whether the event handler should be delegated or directly bound.
If not set, {@link liveEvents} will be used. This option has been available since version 1.1.11.</li>
</ul>
This parameter has been available since version 1.1.1. | clientChange | php | yiisoft/yii | framework/web/helpers/CHtml.php | https://github.com/yiisoft/yii/blob/master/framework/web/helpers/CHtml.php | BSD-3-Clause |
public static function resolveNameID($model,&$attribute,&$htmlOptions)
{
if(!isset($htmlOptions['name']))
$htmlOptions['name']=self::resolveName($model,$attribute);
if(!isset($htmlOptions['id']))
$htmlOptions['id']=self::getIdByName($htmlOptions['name']);
elseif($htmlOptions['id']===false)
unset($htmlOptions['id']);
} | Generates input name and ID for a model attribute.
This method will update the HTML options by setting appropriate 'name' and 'id' attributes.
This method may also modify the attribute name if the name
contains square brackets (mainly used in tabular input).
@param CModel|string $model the data model
@param string $attribute the attribute
@param array $htmlOptions the HTML options | resolveNameID | php | yiisoft/yii | framework/web/helpers/CHtml.php | https://github.com/yiisoft/yii/blob/master/framework/web/helpers/CHtml.php | BSD-3-Clause |
public static function resolveValue($model,$attribute)
{
if(($pos=strpos($attribute,'['))!==false)
{
if($pos===0) // [a]name[b][c], should ignore [a]
{
if(preg_match('/\](\w+(\[.+)?)/',$attribute,$matches))
$attribute=$matches[1]; // we get: name[b][c]
if(($pos=strpos($attribute,'['))===false)
return $model->$attribute;
}
$name=substr($attribute,0,$pos);
$value=$model->$name;
foreach(explode('][',rtrim(substr($attribute,$pos+1),']')) as $id)
{
if((is_array($value) || $value instanceof ArrayAccess) && isset($value[$id]))
$value=$value[$id];
else
return null;
}
return $value;
}
else
return $model->$attribute;
} | Evaluates the attribute value of the model.
This method can recognize the attribute name written in array format.
For example, if the attribute name is 'name[a][b]', the value "$model->name['a']['b']" will be returned.
@param CModel $model the data model
@param string $attribute the attribute name
@return mixed the attribute value
@since 1.1.3 | resolveValue | php | yiisoft/yii | framework/web/helpers/CHtml.php | https://github.com/yiisoft/yii/blob/master/framework/web/helpers/CHtml.php | BSD-3-Clause |
public static function quote($js,$forUrl=false)
{
$js = (string)$js;
Yii::import('system.vendors.zend-escaper.Escaper');
$escaper=new Escaper(Yii::app()->charset);
if($forUrl)
return $escaper->escapeUrl($js);
else
return $escaper->escapeJs($js);
} | Quotes a javascript string.
After processing, the string can be safely enclosed within a pair of
quotation marks and serve as a javascript string.
@param string $js string to be quoted
@param boolean $forUrl whether this string is used as a URL
@return string the quoted string | quote | php | yiisoft/yii | framework/web/helpers/CJavaScript.php | https://github.com/yiisoft/yii/blob/master/framework/web/helpers/CJavaScript.php | BSD-3-Clause |
public static function jsonEncode($data)
{
return CJSON::encode($data);
} | Returns the JSON representation of the PHP data.
@param mixed $data the data to be encoded
@return string the JSON representation of the PHP data. | jsonEncode | php | yiisoft/yii | framework/web/helpers/CJavaScript.php | https://github.com/yiisoft/yii/blob/master/framework/web/helpers/CJavaScript.php | BSD-3-Clause |
public static function init($apiKey=null)
{
if($apiKey===null)
return CHtml::scriptFile(self::$bootstrapUrl);
else
return CHtml::scriptFile(self::$bootstrapUrl.'?key='.$apiKey);
} | Renders the jsapi script file.
@param string $apiKey the API key. Null if you do not have a key.
@return string the script tag that loads Google jsapi. | init | php | yiisoft/yii | framework/web/helpers/CGoogleApi.php | https://github.com/yiisoft/yii/blob/master/framework/web/helpers/CGoogleApi.php | BSD-3-Clause |
protected static function nameValue($name, $value)
{
return self::encode(strval($name)) . ':' . self::encode($value);
} | array-walking function for use in generating JSON-formatted name-value pairs
@param string $name name of key to use
@param mixed $value reference to an array element to be encoded
@return string JSON-formatted name-value pair, like '"name":value'
@access private | nameValue | php | yiisoft/yii | framework/web/helpers/CJSON.php | https://github.com/yiisoft/yii/blob/master/framework/web/helpers/CJSON.php | BSD-3-Clause |
protected static function reduceString($str)
{
$str = preg_replace(array(
// eliminate single line comments in '// ...' form
'#^\s*//(.+)$#m',
// eliminate multi-line comments in '/* ... */' form, at start of string
'#^\s*/\*(.+)\*/#Us',
// eliminate multi-line comments in '/* ... */' form, at end of string
'#/\*(.+)\*/\s*$#Us'
), '', $str);
// eliminate extraneous space
return trim($str);
} | reduce a string by removing leading and trailing comments and whitespace
@param string $str string value to strip of comments and whitespace
@return string string value stripped of comments and whitespace
@access private | reduceString | php | yiisoft/yii | framework/web/helpers/CJSON.php | https://github.com/yiisoft/yii/blob/master/framework/web/helpers/CJSON.php | BSD-3-Clause |
protected static function utf8ToUnicode( &$str )
{
$unicode = array();
$values = array();
$lookingFor = 1;
for ($i = 0; $i < strlen( $str ); $i++ )
{
$thisValue = ord( $str[ $i ] );
if ( $thisValue < 128 )
$unicode[] = $thisValue;
else
{
if ( count( $values ) == 0 )
$lookingFor = ( $thisValue < 224 ) ? 2 : 3;
$values[] = $thisValue;
if ( count( $values ) == $lookingFor )
{
$number = ( $lookingFor == 3 ) ?
( ( $values[0] % 16 ) * 4096 ) + ( ( $values[1] % 64 ) * 64 ) + ( $values[2] % 64 ):
( ( $values[0] % 32 ) * 64 ) + ( $values[1] % 64 );
$unicode[] = $number;
$values = array();
$lookingFor = 1;
}
}
}
return $unicode;
} | This function returns any UTF-8 encoded text as a list of
Unicode values:
@param string $str string to convert
@return string
@author Scott Michael Reynen <[email protected]>
@link http://www.randomchaos.com/document.php?source=php_and_unicode
@see unicodeToUTF8() | utf8ToUnicode | php | yiisoft/yii | framework/web/helpers/CJSON.php | https://github.com/yiisoft/yii/blob/master/framework/web/helpers/CJSON.php | BSD-3-Clause |
protected static function unicodeToUTF8( &$str )
{
$utf8 = '';
foreach( $str as $unicode )
{
if ( $unicode < 128 )
{
$utf8.= chr( $unicode );
}
elseif ( $unicode < 2048 )
{
$utf8.= chr( 192 + ( ( $unicode - ( $unicode % 64 ) ) / 64 ) );
$utf8.= chr( 128 + ( $unicode % 64 ) );
}
else
{
$utf8.= chr( 224 + ( ( $unicode - ( $unicode % 4096 ) ) / 4096 ) );
$utf8.= chr( 128 + ( ( ( $unicode % 4096 ) - ( $unicode % 64 ) ) / 64 ) );
$utf8.= chr( 128 + ( $unicode % 64 ) );
}
}
return $utf8;
} | This function converts a Unicode array back to its UTF-8 representation
@param string $str string to convert
@return string
@author Scott Michael Reynen <[email protected]>
@link http://www.randomchaos.com/document.php?source=php_and_unicode
@see utf8ToUnicode() | unicodeToUTF8 | php | yiisoft/yii | framework/web/helpers/CJSON.php | https://github.com/yiisoft/yii/blob/master/framework/web/helpers/CJSON.php | BSD-3-Clause |
protected static function utf8ToUTF16BE(&$str, $bom = false)
{
$out = $bom ? "\xFE\xFF" : '';
if(function_exists('mb_convert_encoding'))
return $out.mb_convert_encoding($str,'UTF-16BE','UTF-8');
$uni = self::utf8ToUnicode($str);
foreach($uni as $cp)
$out .= pack('n',$cp);
return $out;
} | UTF-8 to UTF-16BE conversion.
Maybe really UCS-2 without mb_string due to utf8ToUnicode limits
@param string $str string to convert
@param boolean $bom whether to output BOM header
@return string | utf8ToUTF16BE | php | yiisoft/yii | framework/web/helpers/CJSON.php | https://github.com/yiisoft/yii/blob/master/framework/web/helpers/CJSON.php | BSD-3-Clause |
protected static function utf16beToUTF8(&$str)
{
$uni = unpack('n*',$str);
return self::unicodeToUTF8($uni);
} | UTF-8 to UTF-16BE conversion.
Maybe really UCS-2 without mb_string due to utf8ToUnicode limits
@param string $str string to convert
@return string | utf16beToUTF8 | php | yiisoft/yii | framework/web/helpers/CJSON.php | https://github.com/yiisoft/yii/blob/master/framework/web/helpers/CJSON.php | BSD-3-Clause |
public function getOn()
{
return $this->_on;
} | Returns a value indicating under which scenarios this string is visible.
If the value is empty, it means the string is visible under all scenarios.
Otherwise, only when the model is in the scenario whose name can be found in
this value, will the string be visible. See {@link CModel::scenario} for more
information about model scenarios.
@return string scenario names separated by commas. Defaults to null. | getOn | php | yiisoft/yii | framework/web/form/CFormStringElement.php | https://github.com/yiisoft/yii/blob/master/framework/web/form/CFormStringElement.php | BSD-3-Clause |
public function render()
{
return $this->content;
} | Renders this element.
The default implementation simply returns {@link content}.
@return string the string content | render | php | yiisoft/yii | framework/web/form/CFormStringElement.php | https://github.com/yiisoft/yii/blob/master/framework/web/form/CFormStringElement.php | BSD-3-Clause |
protected function evaluateVisible()
{
return empty($this->_on) || in_array($this->getParent()->getModel()->getScenario(),$this->_on);
} | Evaluates the visibility of this element.
This method will check the {@link on} property to see if
the model is in a scenario that should have this string displayed.
@return boolean whether this element is visible. | evaluateVisible | php | yiisoft/yii | framework/web/form/CFormStringElement.php | https://github.com/yiisoft/yii/blob/master/framework/web/form/CFormStringElement.php | BSD-3-Clause |
public function getRequired()
{
if($this->_required!==null)
return $this->_required;
else
return $this->getParent()->getModel()->isAttributeRequired($this->name);
} | Gets the value indicating whether this input is required.
If this property is not set explicitly, it will be determined by calling
{@link CModel::isAttributeRequired} for the associated model and attribute of this input.
@return boolean whether this input is required. | getRequired | php | yiisoft/yii | framework/web/form/CFormInputElement.php | https://github.com/yiisoft/yii/blob/master/framework/web/form/CFormInputElement.php | BSD-3-Clause |
public function render()
{
if($this->type==='hidden')
return $this->renderInput();
$output=array(
'{label}'=>$this->renderLabel(),
'{input}'=>$this->renderInput(),
'{hint}'=>$this->renderHint(),
'{error}'=>!$this->getParent()->showErrors ? '' : $this->renderError(),
);
return strtr($this->layout,$output);
} | Renders everything for this input.
The default implementation simply returns the result of {@link renderLabel}, {@link renderInput},
{@link renderHint}. When {@link CForm::showErrorSummary} is false, {@link renderError} is also called
to show error messages after individual input fields.
@return string the complete rendering result for this input, including label, input field, hint, and error. | render | php | yiisoft/yii | framework/web/form/CFormInputElement.php | https://github.com/yiisoft/yii/blob/master/framework/web/form/CFormInputElement.php | BSD-3-Clause |
public function renderLabel()
{
$options = array(
'label'=>$this->getLabel(),
'required'=>$this->getRequired()
);
if(!empty($this->attributes['id']))
$options['for']=$this->attributes['id'];
return CHtml::activeLabel($this->getParent()->getModel(), $this->name, $options);
} | Renders the label for this input.
The default implementation returns the result of {@link CHtml activeLabelEx}.
@return string the rendering result | renderLabel | php | yiisoft/yii | framework/web/form/CFormInputElement.php | https://github.com/yiisoft/yii/blob/master/framework/web/form/CFormInputElement.php | BSD-3-Clause |
public function renderInput()
{
if(isset(self::$coreTypes[$this->type]))
{
$method=self::$coreTypes[$this->type];
if(strpos($method,'List')!==false)
return CHtml::$method($this->getParent()->getModel(), $this->name, $this->items, $this->attributes);
else
return CHtml::$method($this->getParent()->getModel(), $this->name, $this->attributes);
}
else
{
$attributes=$this->attributes;
$attributes['model']=$this->getParent()->getModel();
$attributes['attribute']=$this->name;
ob_start();
$this->getParent()->getOwner()->widget($this->type, $attributes);
return ob_get_clean();
}
} | Renders the input field.
The default implementation returns the result of the appropriate CHtml method or the widget.
@return string the rendering result | renderInput | php | yiisoft/yii | framework/web/form/CFormInputElement.php | https://github.com/yiisoft/yii/blob/master/framework/web/form/CFormInputElement.php | BSD-3-Clause |
public function renderHint()
{
return $this->hint===null ? '' : '<div class="hint">'.$this->hint.'</div>';
} | Renders the hint text for this input.
The default implementation returns the {@link hint} property enclosed in a paragraph HTML tag.
@return string the rendering result. | renderHint | php | yiisoft/yii | framework/web/form/CFormInputElement.php | https://github.com/yiisoft/yii/blob/master/framework/web/form/CFormInputElement.php | BSD-3-Clause |
protected function evaluateVisible()
{
return $this->getParent()->getModel()->isAttributeSafe($this->name);
} | Evaluates the visibility of this element.
This method will check if the attribute associated with this input is safe for
the current model scenario.
@return boolean whether this element is visible. | evaluateVisible | php | yiisoft/yii | framework/web/form/CFormInputElement.php | https://github.com/yiisoft/yii/blob/master/framework/web/form/CFormInputElement.php | BSD-3-Clause |
protected function init()
{
} | Initializes this form.
This method is invoked at the end of the constructor.
You may override this method to provide customized initialization (such as
configuring the form object). | init | php | yiisoft/yii | framework/web/form/CForm.php | https://github.com/yiisoft/yii/blob/master/framework/web/form/CForm.php | BSD-3-Clause |
public function submitted($buttonName='submit',$loadData=true)
{
$ret=$this->clicked($this->getUniqueId()) && $this->clicked($buttonName);
if($ret && $loadData)
$this->loadData();
return $ret;
} | Returns a value indicating whether this form is submitted.
@param string $buttonName the name of the submit button
@param boolean $loadData whether to call {@link loadData} if the form is submitted so that
the submitted data can be populated to the associated models.
@return boolean whether this form is submitted.
@see loadData | submitted | php | yiisoft/yii | framework/web/form/CForm.php | https://github.com/yiisoft/yii/blob/master/framework/web/form/CForm.php | BSD-3-Clause |
public function clicked($name)
{
if(strcasecmp($this->getRoot()->method,'get'))
return isset($_POST[$name]);
else
return isset($_GET[$name]);
} | Returns a value indicating whether the specified button is clicked.
@param string $name the button name
@return boolean whether the button is clicked. | clicked | php | yiisoft/yii | framework/web/form/CForm.php | https://github.com/yiisoft/yii/blob/master/framework/web/form/CForm.php | BSD-3-Clause |
public function validate()
{
$ret=true;
foreach($this->getModels() as $model)
$ret=$model->validate() && $ret;
return $ret;
} | Validates the models associated with this form.
All models, including those associated with sub-forms, will perform
the validation. You may use {@link CModel::getErrors()} to retrieve the validation
error messages.
@return boolean whether all models are valid | validate | php | yiisoft/yii | framework/web/form/CForm.php | https://github.com/yiisoft/yii/blob/master/framework/web/form/CForm.php | BSD-3-Clause |
public function getOwner()
{
$owner=$this->getParent();
while($owner instanceof self)
$owner=$owner->getParent();
return $owner;
} | @return CBaseController the owner of this form. This refers to either a controller or a widget
by which the form is created and rendered. | getOwner | php | yiisoft/yii | framework/web/form/CForm.php | https://github.com/yiisoft/yii/blob/master/framework/web/form/CForm.php | BSD-3-Clause |
public function getModel($checkParent=true)
{
if(!$checkParent)
return $this->_model;
$form=$this;
while($form->_model===null && $form->getParent() instanceof self)
$form=$form->getParent();
return $form->_model;
} | Returns the model that this form is associated with.
@param boolean $checkParent whether to return parent's model if this form doesn't have model by itself.
@return CModel the model associated with this form. If this form does not have a model,
it will look for a model in its ancestors. | getModel | php | yiisoft/yii | framework/web/form/CForm.php | https://github.com/yiisoft/yii/blob/master/framework/web/form/CForm.php | BSD-3-Clause |
public function getElements()
{
if($this->_elements===null)
$this->_elements=new CFormElementCollection($this,false);
return $this->_elements;
} | Returns the input elements of this form.
This includes text strings, input elements and sub-forms.
Note that the returned result is a {@link CFormElementCollection} object, which
means you can use it like an array. For more details, see {@link CMap}.
@return CFormElementCollection the form elements. | getElements | php | yiisoft/yii | framework/web/form/CForm.php | https://github.com/yiisoft/yii/blob/master/framework/web/form/CForm.php | BSD-3-Clause |
public function setElements($elements)
{
$collection=$this->getElements();
foreach($elements as $name=>$config)
$collection->add($name,$config);
} | Configures the input elements of this form.
The configuration must be an array of input configuration array indexed by input name.
Each input configuration array consists of name-value pairs that are used to initialize
a {@link CFormStringElement} object (when 'type' is 'string'), a {@link CFormElement} object
(when 'type' is a string ending with 'Form'), or a {@link CFormInputElement} object in
all other cases.
@param array $elements the elements configurations | setElements | php | yiisoft/yii | framework/web/form/CForm.php | https://github.com/yiisoft/yii/blob/master/framework/web/form/CForm.php | BSD-3-Clause |
public function getButtons()
{
if($this->_buttons===null)
$this->_buttons=new CFormElementCollection($this,true);
return $this->_buttons;
} | Returns the button elements of this form.
Note that the returned result is a {@link CFormElementCollection} object, which
means you can use it like an array. For more details, see {@link CMap}.
@return CFormElementCollection the form elements. | getButtons | php | yiisoft/yii | framework/web/form/CForm.php | https://github.com/yiisoft/yii/blob/master/framework/web/form/CForm.php | BSD-3-Clause |
public function setButtons($buttons)
{
$collection=$this->getButtons();
foreach($buttons as $name=>$config)
$collection->add($name,$config);
} | Configures the buttons of this form.
The configuration must be an array of button configuration array indexed by button name.
Each button configuration array consists of name-value pairs that are used to initialize
a {@link CFormButtonElement} object.
@param array $buttons the button configurations | setButtons | php | yiisoft/yii | framework/web/form/CForm.php | https://github.com/yiisoft/yii/blob/master/framework/web/form/CForm.php | BSD-3-Clause |
public function render()
{
return $this->renderBegin() . $this->renderBody() . $this->renderEnd();
} | Renders the form.
The default implementation simply calls {@link renderBegin}, {@link renderBody} and {@link renderEnd}.
@return string the rendering result | render | php | yiisoft/yii | framework/web/form/CForm.php | https://github.com/yiisoft/yii/blob/master/framework/web/form/CForm.php | BSD-3-Clause |
public function renderBegin()
{
if($this->getParent() instanceof self)
return '';
else
{
$options=$this->activeForm;
if(isset($options['class']))
{
$class=$options['class'];
unset($options['class']);
}
else
$class='CActiveForm';
$options['action']=$this->action;
$options['method']=$this->method;
if(isset($options['htmlOptions']))
{
foreach($this->attributes as $name=>$value)
$options['htmlOptions'][$name]=$value;
}
else
$options['htmlOptions']=$this->attributes;
ob_start();
$this->_activeForm=$this->getOwner()->beginWidget($class, $options);
return ob_get_clean() . "<div style=\"display:none\">".CHtml::hiddenField($this->getUniqueID(),1)."</div>\n";
}
} | Renders the open tag of the form.
The default implementation will render the open form tag.
@return string the rendering result | renderBegin | php | yiisoft/yii | framework/web/form/CForm.php | https://github.com/yiisoft/yii/blob/master/framework/web/form/CForm.php | BSD-3-Clause |
public function renderEnd()
{
if($this->getParent() instanceof self)
return '';
else
{
ob_start();
$this->getOwner()->endWidget();
return ob_get_clean();
}
} | Renders the close tag of the form.
@return string the rendering result | renderEnd | php | yiisoft/yii | framework/web/form/CForm.php | https://github.com/yiisoft/yii/blob/master/framework/web/form/CForm.php | BSD-3-Clause |
public function renderElement($element)
{
if(is_string($element))
{
if(($e=$this[$element])===null && ($e=$this->getButtons()->itemAt($element))===null)
return $element;
else
$element=$e;
}
if($element->getVisible())
{
if($element instanceof CFormInputElement)
{
if($element->type==='hidden')
return "<div style=\"display:none\">\n".$element->render()."</div>\n";
else
return "<div class=\"row field_{$element->name}\">\n".$element->render()."</div>\n";
}
elseif($element instanceof CFormButtonElement)
return $element->render()."\n";
else
return $element->render();
}
return '';
} | Renders a single element which could be an input element, a sub-form, a string, or a button.
@param mixed $element the form element to be rendered. This can be either a {@link CFormElement} instance
or a string representing the name of the form element.
@return string the rendering result | renderElement | php | yiisoft/yii | framework/web/form/CForm.php | https://github.com/yiisoft/yii/blob/master/framework/web/form/CForm.php | BSD-3-Clause |
public function addedElement($name,$element,$forButtons)
{
} | This method is called after an element is added to the element collection.
@param string $name the name of the element
@param CFormElement $element the element that is added
@param boolean $forButtons whether the element is added to the {@link buttons} collection.
If false, it means the element is added to the {@link elements} collection. | addedElement | php | yiisoft/yii | framework/web/form/CForm.php | https://github.com/yiisoft/yii/blob/master/framework/web/form/CForm.php | BSD-3-Clause |
public function removedElement($name,$element,$forButtons)
{
} | This method is called after an element is removed from the element collection.
@param string $name the name of the element
@param CFormElement $element the element that is removed
@param boolean $forButtons whether the element is removed from the {@link buttons} collection
If false, it means the element is removed from the {@link elements} collection. | removedElement | php | yiisoft/yii | framework/web/form/CForm.php | https://github.com/yiisoft/yii/blob/master/framework/web/form/CForm.php | BSD-3-Clause |
protected function evaluateVisible()
{
foreach($this->getElements() as $element)
if($element->getVisible())
return true;
return false;
} | Evaluates the visibility of this form.
This method will check the visibility of the {@link elements}.
If any one of them is visible, the form is considered as visible. Otherwise, it is invisible.
@return boolean whether this form is visible. | evaluateVisible | php | yiisoft/yii | framework/web/form/CForm.php | https://github.com/yiisoft/yii/blob/master/framework/web/form/CForm.php | BSD-3-Clause |
protected function getUniqueId()
{
if(isset($this->attributes['id']))
return 'yform_'.$this->attributes['id'];
else
return 'yform_'.sprintf('%x',crc32(serialize(array_keys($this->getElements()->toArray()))));
} | Returns a unique ID that identifies this form in the current page.
@return string the unique ID identifying this form | getUniqueId | php | yiisoft/yii | framework/web/form/CForm.php | https://github.com/yiisoft/yii/blob/master/framework/web/form/CForm.php | BSD-3-Clause |
public function offsetExists($offset)
{
return $this->getElements()->contains($offset);
} | Returns whether there is an element at the specified offset.
This method is required by the interface ArrayAccess.
@param mixed $offset the offset to check on
@return boolean | offsetExists | php | yiisoft/yii | framework/web/form/CForm.php | https://github.com/yiisoft/yii/blob/master/framework/web/form/CForm.php | BSD-3-Clause |
public function offsetGet($offset)
{
return $this->getElements()->itemAt($offset);
} | Returns the element at the specified offset.
This method is required by the interface ArrayAccess.
@param mixed $offset the offset to retrieve element.
@return mixed the element at the offset, null if no element is found at the offset | offsetGet | php | yiisoft/yii | framework/web/form/CForm.php | https://github.com/yiisoft/yii/blob/master/framework/web/form/CForm.php | BSD-3-Clause |
public function offsetSet($offset,$item)
{
$this->getElements()->add($offset,$item);
} | Sets the element at the specified offset.
This method is required by the interface ArrayAccess.
@param mixed $offset the offset to set element
@param mixed $item the element value | offsetSet | php | yiisoft/yii | framework/web/form/CForm.php | https://github.com/yiisoft/yii/blob/master/framework/web/form/CForm.php | BSD-3-Clause |
public function offsetUnset($offset)
{
$this->getElements()->remove($offset);
} | Unsets the element at the specified offset.
This method is required by the interface ArrayAccess.
@param mixed $offset the offset to unset element | offsetUnset | php | yiisoft/yii | framework/web/form/CForm.php | https://github.com/yiisoft/yii/blob/master/framework/web/form/CForm.php | BSD-3-Clause |
public function remove($key)
{
if(($item=parent::remove($key))!==null)
$this->_form->removedElement($key,$item,$this->_forButtons);
} | Removes the specified element by key.
@param string $key the name of the element to be removed from the collection
@throws CException | remove | php | yiisoft/yii | framework/web/form/CFormElementCollection.php | https://github.com/yiisoft/yii/blob/master/framework/web/form/CFormElementCollection.php | BSD-3-Clause |
public function __toString()
{
return $this->render();
} | Converts the object to a string.
This is a PHP magic method.
The default implementation simply calls {@link render} and return
the rendering result.
@return string the string representation of this object. | __toString | php | yiisoft/yii | framework/web/form/CFormElement.php | https://github.com/yiisoft/yii/blob/master/framework/web/form/CFormElement.php | BSD-3-Clause |
public function configure($config)
{
if(is_string($config))
$config=require(Yii::getPathOfAlias($config).'.php');
if(is_array($config))
{
foreach($config as $name=>$value)
$this->$name=$value;
}
} | Configures this object with property initial values.
@param mixed $config the configuration for this object. This can be an array
representing the property names and their initial values.
It can also be a string representing the file name of the PHP script
that returns a configuration array. | configure | php | yiisoft/yii | framework/web/form/CFormElement.php | https://github.com/yiisoft/yii/blob/master/framework/web/form/CFormElement.php | BSD-3-Clause |
public function getVisible()
{
if($this->_visible===null)
$this->_visible=$this->evaluateVisible();
return $this->_visible;
} | Returns a value indicating whether this element is visible and should be rendered.
This method will call {@link evaluateVisible} to determine the visibility of this element.
@return boolean whether this element is visible and should be rendered. | getVisible | php | yiisoft/yii | framework/web/form/CFormElement.php | https://github.com/yiisoft/yii/blob/master/framework/web/form/CFormElement.php | BSD-3-Clause |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.