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 __construct(
protected Pulse $pulse,
) {
//
} | Create a new recorder instance. | __construct | php | laravel/pulse | src/Recorders/UserJobs.php | https://github.com/laravel/pulse/blob/master/src/Recorders/UserJobs.php | MIT |
public function __construct(
protected Pulse $pulse,
) {
//
} | Create a new recorder instance. | __construct | php | laravel/pulse | src/Recorders/SlowJobs.php | https://github.com/laravel/pulse/blob/master/src/Recorders/SlowJobs.php | MIT |
public function __construct(
protected Pulse $pulse,
protected Repository $config,
) {
//
} | Create a new recorder instance. | __construct | php | laravel/pulse | src/Recorders/Exceptions.php | https://github.com/laravel/pulse/blob/master/src/Recorders/Exceptions.php | MIT |
public function __construct(
protected Pulse $pulse,
) {
//
} | Create a new recorder instance. | __construct | php | laravel/pulse | src/Recorders/SlowRequests.php | https://github.com/laravel/pulse/blob/master/src/Recorders/SlowRequests.php | MIT |
public function __construct(
protected Pulse $pulse,
) {
//
} | Create a new recorder instance. | __construct | php | laravel/pulse | src/Recorders/SlowOutgoingRequests.php | https://github.com/laravel/pulse/blob/master/src/Recorders/SlowOutgoingRequests.php | MIT |
public function actionError()
{
if($error=Yii::app()->errorHandler->error)
{
if(Yii::app()->request->isAjaxRequest)
echo $error['message'];
else
$this->render('error', $error);
}
} | This is the action to handle external exceptions. | actionError | php | yiisoft/yii | demos/blog/protected/controllers/SiteController.php | https://github.com/yiisoft/yii/blob/master/demos/blog/protected/controllers/SiteController.php | BSD-3-Clause |
public function actionLogout()
{
Yii::app()->user->logout();
$this->redirect(Yii::app()->homeUrl);
} | Logs out the current user and redirect to homepage. | actionLogout | php | yiisoft/yii | demos/blog/protected/controllers/SiteController.php | https://github.com/yiisoft/yii/blob/master/demos/blog/protected/controllers/SiteController.php | BSD-3-Clause |
public function accessRules()
{
return array(
array('allow', // allow all users to access 'index' and 'view' actions.
'actions'=>array('index','view'),
'users'=>array('*'),
),
array('allow', // allow authenticated users to access all actions
'users'=>array('@'),
),
array('deny', // deny all users
'users'=>array('*'),
),
);
} | Specifies the access control rules.
This method is used by the 'accessControl' filter.
@return array access control rules | accessRules | php | yiisoft/yii | demos/blog/protected/controllers/PostController.php | https://github.com/yiisoft/yii/blob/master/demos/blog/protected/controllers/PostController.php | BSD-3-Clause |
public function actionCreate()
{
$model=new Post;
if(isset($_POST['Post']))
{
$model->attributes=$_POST['Post'];
if($model->save())
$this->redirect(array('view','id'=>$model->id));
}
$this->render('create',array(
'model'=>$model,
));
} | Creates a new model.
If creation is successful, the browser will be redirected to the 'view' page. | actionCreate | php | yiisoft/yii | demos/blog/protected/controllers/PostController.php | https://github.com/yiisoft/yii/blob/master/demos/blog/protected/controllers/PostController.php | BSD-3-Clause |
public function actionUpdate()
{
$model=$this->loadModel();
if(isset($_POST['Post']))
{
$model->attributes=$_POST['Post'];
if($model->save())
$this->redirect(array('view','id'=>$model->id));
}
$this->render('update',array(
'model'=>$model,
));
} | Updates a particular model.
If update is successful, the browser will be redirected to the 'view' page. | actionUpdate | php | yiisoft/yii | demos/blog/protected/controllers/PostController.php | https://github.com/yiisoft/yii/blob/master/demos/blog/protected/controllers/PostController.php | BSD-3-Clause |
public function actionDelete()
{
if(Yii::app()->request->isPostRequest)
{
// we only allow deletion via POST request
$this->loadModel()->delete();
// if AJAX request (triggered by deletion via admin grid view), we should not redirect the browser
if(!isset($_GET['ajax']))
$this->redirect(array('index'));
}
else
throw new CHttpException(400,'Invalid request. Please do not repeat this request again.');
} | Deletes a particular model.
If deletion is successful, the browser will be redirected to the 'index' page. | actionDelete | php | yiisoft/yii | demos/blog/protected/controllers/PostController.php | https://github.com/yiisoft/yii/blob/master/demos/blog/protected/controllers/PostController.php | BSD-3-Clause |
public function actionSuggestTags()
{
if(isset($_GET['q']) && ($keyword=trim($_GET['q']))!=='')
{
$tags=Tag::model()->suggestTags($keyword);
if($tags!==array())
echo implode("\n",$tags);
}
} | Suggests tags based on the current user input.
This is called via AJAX when the user is entering the tags input. | actionSuggestTags | php | yiisoft/yii | demos/blog/protected/controllers/PostController.php | https://github.com/yiisoft/yii/blob/master/demos/blog/protected/controllers/PostController.php | BSD-3-Clause |
public function loadModel()
{
if($this->_model===null)
{
if(isset($_GET['id']))
{
if(Yii::app()->user->isGuest)
$condition='status='.Post::STATUS_PUBLISHED.' OR status='.Post::STATUS_ARCHIVED;
else
$condition='';
$this->_model=Post::model()->findByPk($_GET['id'], $condition);
}
if($this->_model===null)
throw new CHttpException(404,'The requested page does not exist.');
}
return $this->_model;
} | Returns the data model based on the primary key given in the GET variable.
If the data model is not found, an HTTP exception will be raised. | loadModel | php | yiisoft/yii | demos/blog/protected/controllers/PostController.php | https://github.com/yiisoft/yii/blob/master/demos/blog/protected/controllers/PostController.php | BSD-3-Clause |
protected function newComment($post)
{
$comment=new Comment;
if(isset($_POST['ajax']) && $_POST['ajax']==='comment-form')
{
echo CActiveForm::validate($comment);
Yii::app()->end();
}
if(isset($_POST['Comment']))
{
$comment->attributes=$_POST['Comment'];
if($post->addComment($comment))
{
if($comment->status==Comment::STATUS_PENDING)
Yii::app()->user->setFlash('commentSubmitted','Thank you for your comment. Your comment will be posted once it is approved.');
$this->refresh();
}
}
return $comment;
} | Creates a new comment.
This method attempts to create a new comment based on the user input.
If the comment is successfully created, the browser will be redirected
to show the created comment.
@param Post the post that the new comment belongs to
@return Comment the comment instance | newComment | php | yiisoft/yii | demos/blog/protected/controllers/PostController.php | https://github.com/yiisoft/yii/blob/master/demos/blog/protected/controllers/PostController.php | BSD-3-Clause |
public function accessRules()
{
return array(
array('allow', // allow authenticated users to access all actions
'users'=>array('@'),
),
array('deny', // deny all users
'users'=>array('*'),
),
);
} | Specifies the access control rules.
This method is used by the 'accessControl' filter.
@return array access control rules | accessRules | php | yiisoft/yii | demos/blog/protected/controllers/CommentController.php | https://github.com/yiisoft/yii/blob/master/demos/blog/protected/controllers/CommentController.php | BSD-3-Clause |
public function actionUpdate()
{
$model=$this->loadModel();
if(isset($_POST['ajax']) && $_POST['ajax']==='comment-form')
{
echo CActiveForm::validate($model);
Yii::app()->end();
}
if(isset($_POST['Comment']))
{
$model->attributes=$_POST['Comment'];
if($model->save())
$this->redirect(array('index'));
}
$this->render('update',array(
'model'=>$model,
));
} | Updates a particular model.
If update is successful, the browser will be redirected to the 'view' page. | actionUpdate | php | yiisoft/yii | demos/blog/protected/controllers/CommentController.php | https://github.com/yiisoft/yii/blob/master/demos/blog/protected/controllers/CommentController.php | BSD-3-Clause |
public function actionDelete()
{
if(Yii::app()->request->isPostRequest)
{
// we only allow deletion via POST request
$this->loadModel()->delete();
// if AJAX request (triggered by deletion via admin grid view), we should not redirect the browser
if(!isset($_POST['ajax']))
$this->redirect(array('index'));
}
else
throw new CHttpException(400,'Invalid request. Please do not repeat this request again.');
} | Deletes a particular model.
If deletion is successful, the browser will be redirected to the 'index' page. | actionDelete | php | yiisoft/yii | demos/blog/protected/controllers/CommentController.php | https://github.com/yiisoft/yii/blob/master/demos/blog/protected/controllers/CommentController.php | BSD-3-Clause |
public function actionApprove()
{
if(Yii::app()->request->isPostRequest)
{
$comment=$this->loadModel();
$comment->approve();
$this->redirect(array('index'));
}
else
throw new CHttpException(400,'Invalid request. Please do not repeat this request again.');
} | Approves a particular comment.
If approval is successful, the browser will be redirected to the comment index page. | actionApprove | php | yiisoft/yii | demos/blog/protected/controllers/CommentController.php | https://github.com/yiisoft/yii/blob/master/demos/blog/protected/controllers/CommentController.php | BSD-3-Clause |
public function loadModel()
{
if($this->_model===null)
{
if(isset($_GET['id']))
$this->_model=Comment::model()->findbyPk($_GET['id']);
if($this->_model===null)
throw new CHttpException(404,'The requested page does not exist.');
}
return $this->_model;
} | Returns the data model based on the primary key given in the GET variable.
If the data model is not found, an HTTP exception will be raised. | loadModel | php | yiisoft/yii | demos/blog/protected/controllers/CommentController.php | https://github.com/yiisoft/yii/blob/master/demos/blog/protected/controllers/CommentController.php | BSD-3-Clause |
public function rules()
{
return array(
// name, email, subject and body are required
array('name, email, subject, body', 'required'),
// email has to be a valid email address
array('email', 'email'),
// verifyCode needs to be entered correctly
array('verifyCode', 'captcha', 'allowEmpty'=>!CCaptcha::checkRequirements()),
);
} | Declares the validation rules. | rules | php | yiisoft/yii | demos/blog/protected/models/ContactForm.php | https://github.com/yiisoft/yii/blob/master/demos/blog/protected/models/ContactForm.php | BSD-3-Clause |
public function attributeLabels()
{
return array(
'verifyCode'=>'Verification Code',
);
} | Declares customized attribute labels.
If not declared here, an attribute would have a label that is
the same as its name with the first letter in upper case. | attributeLabels | php | yiisoft/yii | demos/blog/protected/models/ContactForm.php | https://github.com/yiisoft/yii/blob/master/demos/blog/protected/models/ContactForm.php | BSD-3-Clause |
public static function model($className=__CLASS__)
{
return parent::model($className);
} | Returns the static model of the specified AR class.
@return static the static model class | model | php | yiisoft/yii | demos/blog/protected/models/Tag.php | https://github.com/yiisoft/yii/blob/master/demos/blog/protected/models/Tag.php | BSD-3-Clause |
public function findTagWeights($limit=20)
{
$models=$this->findAll(array(
'order'=>'frequency DESC',
'limit'=>$limit,
));
$total=0;
foreach($models as $model)
$total+=$model->frequency;
$tags=array();
if($total>0)
{
foreach($models as $model)
$tags[$model->name]=8+(int)(16*$model->frequency/($total+10));
ksort($tags);
}
return $tags;
} | Returns tag names and their corresponding weights.
Only the tags with the top weights will be returned.
@param integer the maximum number of tags that should be returned
@return array weights indexed by tag names. | findTagWeights | php | yiisoft/yii | demos/blog/protected/models/Tag.php | https://github.com/yiisoft/yii/blob/master/demos/blog/protected/models/Tag.php | BSD-3-Clause |
public static function model($className=__CLASS__)
{
return parent::model($className);
} | Returns the static model of the specified AR class.
@return static the static model class | model | php | yiisoft/yii | demos/blog/protected/models/Comment.php | https://github.com/yiisoft/yii/blob/master/demos/blog/protected/models/Comment.php | BSD-3-Clause |
protected function beforeSave()
{
if(parent::beforeSave())
{
if($this->isNewRecord)
$this->create_time=time();
return true;
}
else
return false;
} | This is invoked before the record is saved.
@return boolean whether the record should be saved. | beforeSave | php | yiisoft/yii | demos/blog/protected/models/Comment.php | https://github.com/yiisoft/yii/blob/master/demos/blog/protected/models/Comment.php | BSD-3-Clause |
public static function model($className=__CLASS__)
{
return parent::model($className);
} | Returns the static model of the specified AR class.
@return static the static model class | model | php | yiisoft/yii | demos/blog/protected/models/Lookup.php | https://github.com/yiisoft/yii/blob/master/demos/blog/protected/models/Lookup.php | BSD-3-Clause |
public static function items($type)
{
if(!isset(self::$_items[$type]))
self::loadItems($type);
return self::$_items[$type];
} | Returns the items for the specified type.
@param string item type (e.g. 'PostStatus').
@return array item names indexed by item code. The items are order by their position values.
An empty array is returned if the item type does not exist. | items | php | yiisoft/yii | demos/blog/protected/models/Lookup.php | https://github.com/yiisoft/yii/blob/master/demos/blog/protected/models/Lookup.php | BSD-3-Clause |
public static function item($type,$code)
{
if(!isset(self::$_items[$type]))
self::loadItems($type);
return isset(self::$_items[$type][$code]) ? self::$_items[$type][$code] : false;
} | Returns the item name for the specified type and code.
@param string the item type (e.g. 'PostStatus').
@param integer the item code (corresponding to the 'code' column value)
@return string the item name for the specified the code. False is returned if the item type or code does not exist. | item | php | yiisoft/yii | demos/blog/protected/models/Lookup.php | https://github.com/yiisoft/yii/blob/master/demos/blog/protected/models/Lookup.php | BSD-3-Clause |
private static function loadItems($type)
{
self::$_items[$type]=array();
$models=self::model()->findAll(array(
'condition'=>'type=:type',
'params'=>array(':type'=>$type),
'order'=>'position',
));
foreach($models as $model)
self::$_items[$type][$model->code]=$model->name;
} | Loads the lookup items for the specified type from the database.
@param string the item type | loadItems | php | yiisoft/yii | demos/blog/protected/models/Lookup.php | https://github.com/yiisoft/yii/blob/master/demos/blog/protected/models/Lookup.php | BSD-3-Clause |
public function rules()
{
return array(
// username and password are required
array('username, password', 'required'),
// rememberMe needs to be a boolean
array('rememberMe', 'boolean'),
// password needs to be authenticated
array('password', 'authenticate'),
);
} | Declares the validation rules.
The rules state that username and password are required,
and password needs to be authenticated. | rules | php | yiisoft/yii | demos/blog/protected/models/LoginForm.php | https://github.com/yiisoft/yii/blob/master/demos/blog/protected/models/LoginForm.php | BSD-3-Clause |
public function authenticate($attribute,$params)
{
$this->_identity=new UserIdentity($this->username,$this->password);
if(!$this->_identity->authenticate())
$this->addError('password','Incorrect username or password.');
} | Authenticates the password.
This is the 'authenticate' validator as declared in rules().
@param string $attribute the name of the attribute to be validated.
@param array $params additional parameters passed with rule when being executed. | authenticate | php | yiisoft/yii | demos/blog/protected/models/LoginForm.php | https://github.com/yiisoft/yii/blob/master/demos/blog/protected/models/LoginForm.php | BSD-3-Clause |
public function login()
{
if($this->_identity===null)
{
$this->_identity=new UserIdentity($this->username,$this->password);
$this->_identity->authenticate();
}
if($this->_identity->errorCode===UserIdentity::ERROR_NONE)
{
$duration=$this->rememberMe ? 3600*24*30 : 0; // 30 days
Yii::app()->user->login($this->_identity,$duration);
return true;
}
else
return false;
} | Logs in the user using the given username and password in the model.
@return boolean whether login is successful | login | php | yiisoft/yii | demos/blog/protected/models/LoginForm.php | https://github.com/yiisoft/yii/blob/master/demos/blog/protected/models/LoginForm.php | BSD-3-Clause |
public static function model($className=__CLASS__)
{
return parent::model($className);
} | Returns the static model of the specified AR class.
@return static the static model class | model | php | yiisoft/yii | demos/blog/protected/models/Post.php | https://github.com/yiisoft/yii/blob/master/demos/blog/protected/models/Post.php | BSD-3-Clause |
public function normalizeTags($attribute,$params)
{
$this->tags=Tag::array2string(array_unique(Tag::string2array($this->tags)));
} | Normalizes the user-entered tags. | normalizeTags | php | yiisoft/yii | demos/blog/protected/models/Post.php | https://github.com/yiisoft/yii/blob/master/demos/blog/protected/models/Post.php | BSD-3-Clause |
public function addComment($comment)
{
if(Yii::app()->params['commentNeedApproval'])
$comment->status=Comment::STATUS_PENDING;
else
$comment->status=Comment::STATUS_APPROVED;
$comment->post_id=$this->id;
return $comment->save();
} | Adds a new comment to this post.
This method will set status and post_id of the comment accordingly.
@param Comment the comment to be added
@return boolean whether the comment is saved successfully | addComment | php | yiisoft/yii | demos/blog/protected/models/Post.php | https://github.com/yiisoft/yii/blob/master/demos/blog/protected/models/Post.php | BSD-3-Clause |
protected function afterFind()
{
parent::afterFind();
$this->_oldTags=$this->tags;
} | This is invoked when a record is populated with data from a find() call. | afterFind | php | yiisoft/yii | demos/blog/protected/models/Post.php | https://github.com/yiisoft/yii/blob/master/demos/blog/protected/models/Post.php | BSD-3-Clause |
protected function beforeSave()
{
if(parent::beforeSave())
{
if($this->isNewRecord)
{
$this->create_time=$this->update_time=time();
$this->author_id=Yii::app()->user->id;
}
else
$this->update_time=time();
return true;
}
else
return false;
} | This is invoked before the record is saved.
@return boolean whether the record should be saved. | beforeSave | php | yiisoft/yii | demos/blog/protected/models/Post.php | https://github.com/yiisoft/yii/blob/master/demos/blog/protected/models/Post.php | BSD-3-Clause |
protected function afterSave()
{
parent::afterSave();
Tag::model()->updateFrequency($this->_oldTags, $this->tags);
} | This is invoked after the record is saved. | afterSave | php | yiisoft/yii | demos/blog/protected/models/Post.php | https://github.com/yiisoft/yii/blob/master/demos/blog/protected/models/Post.php | BSD-3-Clause |
protected function afterDelete()
{
parent::afterDelete();
Comment::model()->deleteAll('post_id='.$this->id);
Tag::model()->updateFrequency($this->tags, '');
} | This is invoked after the record is deleted. | afterDelete | php | yiisoft/yii | demos/blog/protected/models/Post.php | https://github.com/yiisoft/yii/blob/master/demos/blog/protected/models/Post.php | BSD-3-Clause |
public function search()
{
$criteria=new CDbCriteria;
$criteria->compare('title',$this->title,true);
$criteria->compare('status',$this->status);
return new CActiveDataProvider('Post', array(
'criteria'=>$criteria,
'sort'=>array(
'defaultOrder'=>'status, update_time DESC',
),
));
} | Retrieves the list of posts based on the current search/filter conditions.
@return CActiveDataProvider the data provider that can return the needed posts. | search | php | yiisoft/yii | demos/blog/protected/models/Post.php | https://github.com/yiisoft/yii/blob/master/demos/blog/protected/models/Post.php | BSD-3-Clause |
public static function model($className=__CLASS__)
{
return parent::model($className);
} | Returns the static model of the specified AR class.
@return static the static model class | model | php | yiisoft/yii | demos/blog/protected/models/User.php | https://github.com/yiisoft/yii/blob/master/demos/blog/protected/models/User.php | BSD-3-Clause |
public function validatePassword($password)
{
return CPasswordHelper::verifyPassword($password,$this->password);
} | Checks if the given password is correct.
@param string the password to be validated
@return boolean whether the password is valid | validatePassword | php | yiisoft/yii | demos/blog/protected/models/User.php | https://github.com/yiisoft/yii/blob/master/demos/blog/protected/models/User.php | BSD-3-Clause |
public function actionIndex()
{
echo 'Hello World';
} | Index action is the default action in a controller. | actionIndex | php | yiisoft/yii | demos/helloworld/protected/controllers/SiteController.php | https://github.com/yiisoft/yii/blob/master/demos/helloworld/protected/controllers/SiteController.php | BSD-3-Clause |
public function actions()
{
return array(
'phonebook'=>array(
'class'=>'CWebServiceAction',
'classMap'=>array(
'Contact',
),
),
);
} | Declares the 'phonebook' Web service action. | actions | php | yiisoft/yii | demos/phonebook/protected/controllers/SiteController.php | https://github.com/yiisoft/yii/blob/master/demos/phonebook/protected/controllers/SiteController.php | BSD-3-Clause |
public function actionIndex()
{
$this->render('index');
} | This is the default action that displays the phonebook Flex client. | actionIndex | php | yiisoft/yii | demos/phonebook/protected/controllers/SiteController.php | https://github.com/yiisoft/yii/blob/master/demos/phonebook/protected/controllers/SiteController.php | BSD-3-Clause |
public function actionTest()
{
$wsdlUrl=Yii::app()->request->hostInfo.$this->createUrl('phonebook');
$client=new SoapClient($wsdlUrl);
echo "<pre>";
echo "login...\n";
$client->login('demo','demo');
echo "fetching all contacts\n";
print_r($client->getContacts());
echo "\ninserting a new contact...";
$contact=new Contact;
$contact->name='Tester Name';
$contact->phone='123-123-1234';
$client->saveContact($contact);
echo "done\n\n";
echo "fetching all contacts\n";
print_r($client->getContacts());
echo "</pre>";
} | This action serves as a SOAP client to test the phonebook Web service. | actionTest | php | yiisoft/yii | demos/phonebook/protected/controllers/SiteController.php | https://github.com/yiisoft/yii/blob/master/demos/phonebook/protected/controllers/SiteController.php | BSD-3-Clause |
public function beforeWebMethod($service)
{
$safeMethods=array(
'login',
'getContacts',
);
$pattern='/^('.implode('|',$safeMethods).')$/i';
if(!Yii::app()->user->isGuest || preg_match($pattern,$service->methodName))
return true;
else
throw new CException('Login required.');
} | This method is required by IWebServiceProvider.
It makes sure the user is logged in before making changes to data.
@param CWebService the currently requested Web service.
@return boolean whether the remote method should be executed. | beforeWebMethod | php | yiisoft/yii | demos/phonebook/protected/controllers/SiteController.php | https://github.com/yiisoft/yii/blob/master/demos/phonebook/protected/controllers/SiteController.php | BSD-3-Clause |
public function afterWebMethod($service)
{
} | This method is required by IWebServiceProvider.
@param CWebService the currently requested Web service. | afterWebMethod | php | yiisoft/yii | demos/phonebook/protected/controllers/SiteController.php | https://github.com/yiisoft/yii/blob/master/demos/phonebook/protected/controllers/SiteController.php | BSD-3-Clause |
public function deleteContact($id)
{
return Contact::model()->deleteByPk($id);
} | Deletes the specified contact record.
@param integer ID of the contact to be deleted
@return integer number of records deleted
@soap | deleteContact | php | yiisoft/yii | demos/phonebook/protected/controllers/SiteController.php | https://github.com/yiisoft/yii/blob/master/demos/phonebook/protected/controllers/SiteController.php | BSD-3-Clause |
public function authenticate()
{
if($this->username==='demo' && $this->password==='demo')
$this->errorCode=self::ERROR_NONE;
else
$this->errorCode=self::ERROR_PASSWORD_INVALID;
return !$this->errorCode;
} | Validates the username and password.
This method should check the validity of the provided username
and password in some way. In case of any authentication failure,
set errorCode and errorMessage with appropriate values and return false.
@param string username
@param string password
@return boolean whether the username and password are valid | authenticate | php | yiisoft/yii | demos/phonebook/protected/components/UserIdentity.php | https://github.com/yiisoft/yii/blob/master/demos/phonebook/protected/components/UserIdentity.php | BSD-3-Clause |
public function actionPlay()
{
static $levels=array(
'10'=>'Easy game; you are allowed 10 misses.',
'5'=>'Medium game; you are allowed 5 misses.',
'3'=>'Hard game; you are allowed 3 misses.',
);
// if a difficulty level is correctly chosen
if(isset($_POST['level']) && isset($levels[$_POST['level']]))
{
$this->word=$this->generateWord();
$this->guessWord=str_repeat('_',strlen($this->word));
$this->level=$_POST['level'];
$this->misses=0;
$this->setPageState('guessed',null);
// show the guess page
$this->render('guess');
}
else
{
$params=array(
'levels'=>$levels,
// if this is a POST request, it means the level is not chosen
'error'=>Yii::app()->request->isPostRequest,
);
// show the difficulty level page
$this->render('play',$params);
}
} | The 'play' action.
In this action, users are asked to choose a difficulty level
of the game. | actionPlay | php | yiisoft/yii | demos/hangman/protected/controllers/GameController.php | https://github.com/yiisoft/yii/blob/master/demos/hangman/protected/controllers/GameController.php | BSD-3-Clause |
public function actionGuess()
{
// check to see if the letter is guessed correctly
if(isset($_GET['g'][0]) && ($result=$this->guess($_GET['g'][0]))!==null)
$this->render($result ? 'win' : 'lose');
else // the letter is guessed correctly, but not win yet
{
$guessed=$this->getPageState('guessed',array());
$guessed[$_GET['g'][0]]=true;
$this->setPageState('guessed',$guessed,array());
$this->render('guess');
}
} | The 'guess' action.
This action is invoked each time when the user makes a guess. | actionGuess | php | yiisoft/yii | demos/hangman/protected/controllers/GameController.php | https://github.com/yiisoft/yii/blob/master/demos/hangman/protected/controllers/GameController.php | BSD-3-Clause |
public function actionGiveup()
{
$this->render('lose');
} | The 'guess' action.
This action is invoked when the user gives up the game. | actionGiveup | php | yiisoft/yii | demos/hangman/protected/controllers/GameController.php | https://github.com/yiisoft/yii/blob/master/demos/hangman/protected/controllers/GameController.php | BSD-3-Clause |
public function isGuessed($letter)
{
$guessed=$this->getPageState('guessed',array());
return isset($guessed[$letter]);
} | Checks to see if a letter is already guessed.
@param string the letter
@return boolean whether the letter is already guessed. | isGuessed | php | yiisoft/yii | demos/hangman/protected/controllers/GameController.php | https://github.com/yiisoft/yii/blob/master/demos/hangman/protected/controllers/GameController.php | BSD-3-Clause |
protected function generateWord()
{
$wordFile=dirname(__FILE__).'/words.txt';
$words=preg_split("/[\s,]+/",file_get_contents($wordFile));
do
{
$i=rand(0,count($words)-1);
$word=$words[$i];
} while(strlen($word)<5 || !ctype_alpha($word));
return strtoupper($word);
} | Generates a word to be guessed.
@return string the word to be guessed | generateWord | php | yiisoft/yii | demos/hangman/protected/controllers/GameController.php | https://github.com/yiisoft/yii/blob/master/demos/hangman/protected/controllers/GameController.php | BSD-3-Clause |
protected function guess($letter)
{
$word=$this->word;
$guessWord=$this->guessWord;
$pos=0;
$success=false;
while(($pos=strpos($word,$letter,$pos))!==false)
{
$guessWord[$pos]=$letter;
$success=true;
$pos++;
}
if($success)
{
$this->guessWord=$guessWord;
if($guessWord===$word)
return true;
}
else
{
$this->misses++;
if($this->misses>=$this->level)
return false;
}
} | Checks to see if a letter is guessed correctly.
@param string the letter
@return mixed true if the word is guessed correctly, false
if the user has used up all guesses and the word is guessed
incorrectly, and null if the letter is guessed correctly but
the whole word is guessed correctly yet. | guess | php | yiisoft/yii | demos/hangman/protected/controllers/GameController.php | https://github.com/yiisoft/yii/blob/master/demos/hangman/protected/controllers/GameController.php | BSD-3-Clause |
public function getLevel()
{
return $this->getPageState('level');
} | @return integer the difficulty level. This value is persistent
during the whole game session. | getLevel | php | yiisoft/yii | demos/hangman/protected/controllers/GameController.php | https://github.com/yiisoft/yii/blob/master/demos/hangman/protected/controllers/GameController.php | BSD-3-Clause |
public function setLevel($value)
{
$this->setPageState('level',$value);
} | @param integer the difficulty level. This value is persistent
during the whole game session. | setLevel | php | yiisoft/yii | demos/hangman/protected/controllers/GameController.php | https://github.com/yiisoft/yii/blob/master/demos/hangman/protected/controllers/GameController.php | BSD-3-Clause |
public function getWord()
{
return $this->getPageState('word');
} | @return string the word to be guessed. This value is persistent
during the whole game session. | getWord | php | yiisoft/yii | demos/hangman/protected/controllers/GameController.php | https://github.com/yiisoft/yii/blob/master/demos/hangman/protected/controllers/GameController.php | BSD-3-Clause |
public function setWord($value)
{
$this->setPageState('word',$value);
} | @param string the word to be guessed. This value is persistent
during the whole game session. | setWord | php | yiisoft/yii | demos/hangman/protected/controllers/GameController.php | https://github.com/yiisoft/yii/blob/master/demos/hangman/protected/controllers/GameController.php | BSD-3-Clause |
public function getGuessWord()
{
return $this->getPageState('guessWord');
} | @return string the word being guessed. This value is persistent
during the whole game session. | getGuessWord | php | yiisoft/yii | demos/hangman/protected/controllers/GameController.php | https://github.com/yiisoft/yii/blob/master/demos/hangman/protected/controllers/GameController.php | BSD-3-Clause |
public function setGuessWord($value)
{
$this->setPageState('guessWord',$value);
} | @param string the word being guessed. This value is persistent
during the whole game session. | setGuessWord | php | yiisoft/yii | demos/hangman/protected/controllers/GameController.php | https://github.com/yiisoft/yii/blob/master/demos/hangman/protected/controllers/GameController.php | BSD-3-Clause |
public function getMisses()
{
return $this->getPageState('misses');
} | @return integer the number of misses. This value is persistent
during the whole game session. | getMisses | php | yiisoft/yii | demos/hangman/protected/controllers/GameController.php | https://github.com/yiisoft/yii/blob/master/demos/hangman/protected/controllers/GameController.php | BSD-3-Clause |
public function setMisses($value)
{
$this->setPageState('misses',$value);
} | @param integer the number of misses. This value is persistent
during the whole game session. | setMisses | php | yiisoft/yii | demos/hangman/protected/controllers/GameController.php | https://github.com/yiisoft/yii/blob/master/demos/hangman/protected/controllers/GameController.php | BSD-3-Clause |
public function actionReport($sourcePath, $translationPath, $title = 'Translation report')
{
$sourcePath=trim($sourcePath, '/\\');
$translationPath=trim($translationPath, '/\\');
$results = array();
$dir = new DirectoryIterator($sourcePath);
foreach ($dir as $fileinfo) {
if (!$fileinfo->isDot() && !$fileinfo->isDir()) {
$translatedFilePath = $translationPath.'/'.$fileinfo->getFilename();
$sourceFilePath = $sourcePath.'/'.$fileinfo->getFilename();
$errors = $this->checkFiles($translatedFilePath);
$diff = empty($errors) ? $this->getDiff($translatedFilePath, $sourceFilePath) : '';
if(!empty($diff)) {
$errors[] = 'Translation outdated.';
}
$result = array(
'errors' => $errors,
'diff' => $diff,
);
$results[$fileinfo->getFilename()] = $result;
}
}
// checking if there are obsolete translation files
$dir = new DirectoryIterator($translationPath);
foreach ($dir as $fileinfo) {
if (!$fileinfo->isDot() && !$fileinfo->isDir()) {
$translatedFilePath = $translationPath.'/'.$fileinfo->getFilename();
$errors = $this->checkFiles(null, $translatedFilePath);
if(!empty($errors)) {
$results[$fileinfo->getFilename()]['errors'] = $errors;
}
}
}
$this->renderFile(dirname(__FILE__).'/translations/report_html.php', array(
'results' => $results,
'sourcePath' => $sourcePath,
'translationPath' => $translationPath,
'title' => $title,
));
} | Generates summary report for given translation and original directories
@param string $sourcePath the directory where the original documentation files are
@param string $translationPath the directory where the translated documentation files are
@param string $title custom title to use for report | actionReport | php | yiisoft/yii | build/commands/TranslationsCommand.php | https://github.com/yiisoft/yii/blob/master/build/commands/TranslationsCommand.php | BSD-3-Clause |
protected function highlightDiff($diff)
{
$lines = explode("\n", $diff);
foreach ($lines as $key => $val) {
if (mb_substr($val,0,1,'utf-8') === '@') {
$lines[$key] = '<span class="info">'.CHtml::encode($val).'</span>';
}
else if (mb_substr($val,0,1,'utf-8') === '+') {
$lines[$key] = '<ins>'.CHtml::encode($val).'</ins>';
}
else if (mb_substr($val,0,1,'utf-8') === '-') {
$lines[$key] = '<del>'.CHtml::encode($val).'</del>';
}
else {
$lines[$key] = CHtml::encode($val);
}
}
return implode("\n", $lines);
} | Adds all necessary HTML tags and classes to diff output
@param string $diff DIFF
@return string highlighted DIFF | highlightDiff | php | yiisoft/yii | build/commands/TranslationsCommand.php | https://github.com/yiisoft/yii/blob/master/build/commands/TranslationsCommand.php | BSD-3-Clause |
public function is_utf8($str) {
$c=0; $b=0;
$bits=0;
$len=strlen($str);
for($i=0; $i<$len; $i++){
$c=ord($str[$i]);
if($c > 128){
if(($c >= 254)) return false;
elseif($c >= 252) $bits=6;
elseif($c >= 248) $bits=5;
elseif($c >= 240) $bits=4;
elseif($c >= 224) $bits=3;
elseif($c >= 192) $bits=2;
else return false;
if(($i+$bits) > $len) return false;
while($bits > 1){
$i++;
$b=ord($str[$i]);
if($b < 128 || $b > 191) return false;
$bits--;
}
}
}
return true;
} | php.net/manual/de/function.mb-detect-encoding.php#85294 */ | is_utf8 | php | yiisoft/yii | build/commands/Utf8Command.php | https://github.com/yiisoft/yii/blob/master/build/commands/Utf8Command.php | BSD-3-Clause |
public function actionIndex()
{
// renders the view file 'protected/views/site/index.php'
// using the default layout 'protected/views/layouts/main.php'
$this->render('index');
} | This is the default 'index' action that is invoked
when an action is not explicitly requested by users. | actionIndex | php | yiisoft/yii | build/commands/lite/protected/controllers/SiteController.php | https://github.com/yiisoft/yii/blob/master/build/commands/lite/protected/controllers/SiteController.php | BSD-3-Clause |
public function actionLogin()
{
$user=new LoginForm;
if(Yii::app()->request->isPostRequest)
{
// collect user input data
if(isset($_POST['LoginForm']))
$user->setAttributes($_POST['LoginForm']);
// validate user input and redirect to previous page if valid
if($user->validate())
$this->redirect(Yii::app()->user->returnUrl);
}
// display the login form
$this->render('login',array('user'=>$user));
} | Displays a login form to login a user. | actionLogin | php | yiisoft/yii | build/commands/lite/protected/controllers/SiteController.php | https://github.com/yiisoft/yii/blob/master/build/commands/lite/protected/controllers/SiteController.php | BSD-3-Clause |
public function actionLogout()
{
Yii::app()->user->logout();
$this->redirect(Yii::app()->homeUrl);
} | Logout the current user and redirect to homepage. | actionLogout | php | yiisoft/yii | build/commands/lite/protected/controllers/SiteController.php | https://github.com/yiisoft/yii/blob/master/build/commands/lite/protected/controllers/SiteController.php | BSD-3-Clause |
public function filters()
{
return array(
'accessControl', // perform access control for CRUD operations
);
} | Specifies the action filters.
This method overrides the parent implementation.
@return array action filters | filters | php | yiisoft/yii | build/commands/lite/protected/controllers/PostController.php | https://github.com/yiisoft/yii/blob/master/build/commands/lite/protected/controllers/PostController.php | BSD-3-Clause |
public function accessRules()
{
return array(
array('deny', // deny access to CUD for guest users
'actions'=>array('delete'),
'users'=>array('?'),
),
);
} | Specifies the access control rules.
This method overrides the parent implementation.
It is only effective when 'accessControl' filter is enabled.
@return array access control rules | accessRules | php | yiisoft/yii | build/commands/lite/protected/controllers/PostController.php | https://github.com/yiisoft/yii/blob/master/build/commands/lite/protected/controllers/PostController.php | BSD-3-Clause |
public function actionCreate()
{
$post=new Post;
if(Yii::app()->request->isPostRequest)
{
if(isset($_POST['Post']))
$post->setAttributes($_POST['Post']);
if($post->save())
$this->redirect(array('show','id'=>$post->id));
}
$this->render('create',array('post'=>$post));
} | Creates a new post.
If creation is successful, the browser will be redirected to the 'show' page. | actionCreate | php | yiisoft/yii | build/commands/lite/protected/controllers/PostController.php | https://github.com/yiisoft/yii/blob/master/build/commands/lite/protected/controllers/PostController.php | BSD-3-Clause |
public function actionUpdate()
{
$post=$this->loadPost();
if(Yii::app()->request->isPostRequest)
{
if(isset($_POST['Post']))
$post->setAttributes($_POST['Post']);
if($post->save())
$this->redirect(array('show','id'=>$post->id));
}
$this->render('update',array('post'=>$post));
} | Updates a particular post.
If update is successful, the browser will be redirected to the 'show' page. | actionUpdate | php | yiisoft/yii | build/commands/lite/protected/controllers/PostController.php | https://github.com/yiisoft/yii/blob/master/build/commands/lite/protected/controllers/PostController.php | BSD-3-Clause |
public function actionDelete()
{
if(Yii::app()->request->isPostRequest)
{
// we only allow deletion via POST request
$this->loadPost()->delete();
$this->redirect(array('list'));
}
else
throw new CHttpException(500,'Invalid request. Please do not repeat this request again.');
} | Deletes a particular post.
If deletion is successful, the browser will be redirected to the 'list' page. | actionDelete | php | yiisoft/yii | build/commands/lite/protected/controllers/PostController.php | https://github.com/yiisoft/yii/blob/master/build/commands/lite/protected/controllers/PostController.php | BSD-3-Clause |
protected function loadPost()
{
if(isset($_GET['id']))
$post=Post::model()->findbyPk($_GET['id']);
if(isset($post))
return $post;
else
throw new CHttpException(500,'The requested post does not exist.');
} | Loads the data model based on the primary key given in the GET variable.
If the data model is not found, an HTTP exception will be raised. | loadPost | php | yiisoft/yii | build/commands/lite/protected/controllers/PostController.php | https://github.com/yiisoft/yii/blob/master/build/commands/lite/protected/controllers/PostController.php | BSD-3-Clause |
protected function getListCriteria($pages)
{
$criteria=new CDbCriteria;
$columns=Post::model()->tableSchema->columns;
if(isset($_GET['sort']) && isset($columns[$_GET['sort']]))
{
$criteria->order=$columns[$_GET['sort']]->rawName;
if(isset($_GET['desc']))
$criteria->order.=' DESC';
}
$criteria->limit=$pages->pageSize;
$criteria->offset=$pages->currentPage*$pages->pageSize;
return $criteria;
} | @param CPagination the pagination information
@return CDbCriteria the query criteria for Post list.
It includes the ORDER BY and LIMIT/OFFSET information. | getListCriteria | php | yiisoft/yii | build/commands/lite/protected/controllers/PostController.php | https://github.com/yiisoft/yii/blob/master/build/commands/lite/protected/controllers/PostController.php | BSD-3-Clause |
protected function generateColumnHeader($column)
{
$params=$_GET;
if(isset($params['sort']) && $params['sort']===$column)
{
if(isset($params['desc']))
unset($params['desc']);
else
$params['desc']=1;
}
else
{
$params['sort']=$column;
unset($params['desc']);
}
$url=$this->createUrl('list',$params);
return CHtml::link(Post::model()->getAttributeLabel($column),$url);
} | Generates the header cell for the specified column.
This method will generate a hyperlink for the column.
Clicking on the link will cause the data to be sorted according to the column.
@param string the column name
@return string the generated header cell content | generateColumnHeader | php | yiisoft/yii | build/commands/lite/protected/controllers/PostController.php | https://github.com/yiisoft/yii/blob/master/build/commands/lite/protected/controllers/PostController.php | BSD-3-Clause |
public function rules()
{
return array(
array('username, password', 'required'),
array('verifyCode', 'captcha', 'allowEmpty'=>!extension_loaded('gd')),
array('password', 'authenticate'),
);
} | Declares the validation rules.
The rules state that username and password are required,
and password needs to be authenticated. | rules | php | yiisoft/yii | build/commands/lite/protected/models/LoginForm.php | https://github.com/yiisoft/yii/blob/master/build/commands/lite/protected/models/LoginForm.php | BSD-3-Clause |
public function attributeLabels()
{
return array(
'verifyCode'=>'Verification Code',
);
} | Declares attribute labels.
If not declared here, an attribute would have a label
the same as its name with the first letter in upper case. | attributeLabels | php | yiisoft/yii | build/commands/lite/protected/models/LoginForm.php | https://github.com/yiisoft/yii/blob/master/build/commands/lite/protected/models/LoginForm.php | BSD-3-Clause |
public function authenticate($attribute,$params)
{
if(!$this->hasErrors()) // we only want to authenticate when no input errors
{
$identity=new UserIdentity($this->username,$this->password);
if($identity->authenticate())
{
$duration=$this->rememberMe ? 3600*24*30 : 0; // 30 days
Yii::app()->user->login($identity,$duration);
}
else
$this->addError('password','Incorrect password.');
}
} | Authenticates the password.
This is the 'authenticate' validator as declared in rules(). | authenticate | php | yiisoft/yii | build/commands/lite/protected/models/LoginForm.php | https://github.com/yiisoft/yii/blob/master/build/commands/lite/protected/models/LoginForm.php | BSD-3-Clause |
public static function model($className=__CLASS__)
{
return parent::model($className);
} | Returns the static model of the specified AR class.
This method is required by all child classes of CActiveRecord.
@return CActiveRecord the static model class | model | php | yiisoft/yii | build/commands/lite/protected/models/Post.php | https://github.com/yiisoft/yii/blob/master/build/commands/lite/protected/models/Post.php | BSD-3-Clause |
public function authenticate()
{
if($this->username==='demo' && $this->password==='demo')
$this->errorCode=self::ERROR_NONE;
else
$this->errorCode=self::ERROR_PASSWORD_INVALID;
return !$this->errorCode;
} | Validates the username and password.
This method should check the validity of the provided username
and password in some way. In case of any authentication failure,
set errorCode and errorMessage with appropriate values and return false.
@param string username
@param string password
@return boolean whether the username and password are valid | authenticate | php | yiisoft/yii | build/commands/lite/protected/components/UserIdentity.php | https://github.com/yiisoft/yii/blob/master/build/commands/lite/protected/components/UserIdentity.php | BSD-3-Clause |
public function main()
{
$this->addProperty('yii.version',$this->getYiiVersion());
$this->addProperty('yii.revision',$this->getYiiRevision());
$this->addProperty('yii.winbuild', substr(PHP_OS, 0, 3) == 'WIN' ? 'true' : 'false');
$this->addProperty('yii.release',$this->getYiiRelease());
$this->addProperty('yii.date',date('M j, Y'));
} | Execute lint check against PhingFile or a FileSet | main | php | yiisoft/yii | build/tasks/YiiInitTask.php | https://github.com/yiisoft/yii/blob/master/build/tasks/YiiInitTask.php | BSD-3-Clause |
public static function createApplication($class,$config=null)
{
return new $class($config);
} | Creates an application of the specified class.
@param string $class the application class name
@param mixed $config application configuration. This parameter will be passed as the parameter
to the constructor of the application class.
@return mixed the application instance | createApplication | php | yiisoft/yii | framework/YiiBase.php | https://github.com/yiisoft/yii/blob/master/framework/YiiBase.php | BSD-3-Clause |
public static function app()
{
return self::$_app;
} | Returns the application singleton or null if the singleton has not been created yet.
@return CApplication the application singleton, null if the singleton has not been created yet. | app | php | yiisoft/yii | framework/YiiBase.php | https://github.com/yiisoft/yii/blob/master/framework/YiiBase.php | BSD-3-Clause |
public static function setApplication($app)
{
if(self::$_app===null || $app===null)
self::$_app=$app;
else
throw new CException(Yii::t('yii','Yii application can only be created once.'));
} | Stores the application instance in the class static member.
This method helps implement a singleton pattern for CApplication.
Repeated invocation of this method or the CApplication constructor
will cause the throw of an exception.
To retrieve the application instance, use {@link app()}.
@param CApplication $app the application instance. If this is null, the existing
application singleton will be removed.
@throws CException if multiple application instances are registered. | setApplication | php | yiisoft/yii | framework/YiiBase.php | https://github.com/yiisoft/yii/blob/master/framework/YiiBase.php | BSD-3-Clause |
public static function import($alias,$forceInclude=false)
{
if(isset(self::$_imports[$alias])) // previously imported
return self::$_imports[$alias];
if(class_exists($alias,false) || interface_exists($alias,false))
return self::$_imports[$alias]=$alias;
if(($pos=strrpos($alias,'\\'))!==false) // a class name in PHP 5.3 namespace format
{
$namespace=str_replace('\\','.',ltrim(substr($alias,0,$pos),'\\'));
if(($path=self::getPathOfAlias($namespace))!==false)
{
$classFile=$path.DIRECTORY_SEPARATOR.substr($alias,$pos+1).'.php';
if($forceInclude)
{
if(is_file($classFile))
require($classFile);
else
throw new CException(Yii::t('yii','Alias "{alias}" is invalid. Make sure it points to an existing PHP file and the file is readable.',array('{alias}'=>$alias)));
self::$_imports[$alias]=$alias;
}
else
self::$classMap[$alias]=$classFile;
return $alias;
}
else
{
// try to autoload the class with an autoloader
if (class_exists($alias,true))
return self::$_imports[$alias]=$alias;
else
throw new CException(Yii::t('yii','Alias "{alias}" is invalid. Make sure it points to an existing directory or file.',
array('{alias}'=>$namespace)));
}
}
if(($pos=strrpos($alias,'.'))===false) // a simple class name
{
// try to autoload the class with an autoloader if $forceInclude is true
if($forceInclude && (Yii::autoload($alias,true) || class_exists($alias,true)))
self::$_imports[$alias]=$alias;
return $alias;
}
$className=(string)substr($alias,$pos+1);
$isClass=$className!=='*';
if($isClass && (class_exists($className,false) || interface_exists($className,false)))
return self::$_imports[$alias]=$className;
if(($path=self::getPathOfAlias($alias))!==false)
{
if($isClass)
{
if($forceInclude)
{
if(is_file($path.'.php'))
require($path.'.php');
else
throw new CException(Yii::t('yii','Alias "{alias}" is invalid. Make sure it points to an existing PHP file and the file is readable.',array('{alias}'=>$alias)));
self::$_imports[$alias]=$className;
}
else
self::$classMap[$className]=$path.'.php';
return $className;
}
else // a directory
{
if(self::$_includePaths===null)
{
self::$_includePaths=array_unique(explode(PATH_SEPARATOR,get_include_path()));
if(($pos=array_search('.',self::$_includePaths,true))!==false)
unset(self::$_includePaths[$pos]);
}
array_unshift(self::$_includePaths,$path);
if(self::$enableIncludePath && set_include_path('.'.PATH_SEPARATOR.implode(PATH_SEPARATOR,self::$_includePaths))===false)
self::$enableIncludePath=false;
return self::$_imports[$alias]=$path;
}
}
else
throw new CException(Yii::t('yii','Alias "{alias}" is invalid. Make sure it points to an existing directory or file.',
array('{alias}'=>$alias)));
} | Imports a class or a directory.
Importing a class is like including the corresponding class file.
The main difference is that importing a class is much lighter because it only
includes the class file when the class is referenced the first time.
Importing a directory is equivalent to adding a directory into the PHP include path.
If multiple directories are imported, the directories imported later will take
precedence in class file searching (i.e., they are added to the front of the PHP include path).
Path aliases are used to import a class or directory. For example,
<ul>
<li><code>application.components.GoogleMap</code>: import the <code>GoogleMap</code> class.</li>
<li><code>application.components.*</code>: import the <code>components</code> directory.</li>
</ul>
The same path alias can be imported multiple times, but only the first time is effective.
Importing a directory does not import any of its subdirectories.
Starting from version 1.1.5, this method can also be used to import a class in namespace format
(available for PHP 5.3 or above only). It is similar to importing a class in path alias format,
except that the dot separator is replaced by the backslash separator. For example, importing
<code>application\components\GoogleMap</code> is similar to importing <code>application.components.GoogleMap</code>.
The difference is that the former class is using qualified name, while the latter unqualified.
Note, importing a class in namespace format requires that the namespace corresponds to
a valid path alias once backslash characters are replaced with dot characters.
For example, the namespace <code>application\components</code> must correspond to a valid
path alias <code>application.components</code>.
@param string $alias path alias to be imported
@param boolean $forceInclude whether to include the class file immediately. If false, the class file
will be included only when the class is being used. This parameter is used only when
the path alias refers to a class.
@return string the class name or the directory that this alias refers to
@throws CException if the alias is invalid | import | php | yiisoft/yii | framework/YiiBase.php | https://github.com/yiisoft/yii/blob/master/framework/YiiBase.php | BSD-3-Clause |
public static function setPathOfAlias($alias,$path)
{
if(empty($path))
unset(self::$_aliases[$alias]);
else
self::$_aliases[$alias]=rtrim($path,'\\/');
} | Create a path alias.
Note, this method neither checks the existence of the path nor normalizes the path.
@param string $alias alias to the path
@param string $path the path corresponding to the alias. If this is null, the corresponding
path alias will be removed. | setPathOfAlias | php | yiisoft/yii | framework/YiiBase.php | https://github.com/yiisoft/yii/blob/master/framework/YiiBase.php | BSD-3-Clause |
public static function trace($msg,$category='application')
{
if(YII_DEBUG)
self::log($msg,CLogger::LEVEL_TRACE,$category);
} | Writes a trace message.
This method will only log a message when the application is in debug mode.
@param string $msg message to be logged
@param string $category category of the message
@see log | trace | php | yiisoft/yii | framework/YiiBase.php | https://github.com/yiisoft/yii/blob/master/framework/YiiBase.php | BSD-3-Clause |
public static function endProfile($token,$category='application')
{
self::log('end:'.$token,CLogger::LEVEL_PROFILE,$category);
} | Marks the end of a code block for profiling.
This has to be matched with a previous call to {@link beginProfile()} with the same token.
@param string $token token for the code block
@param string $category the category of this log message
@see beginProfile | endProfile | php | yiisoft/yii | framework/YiiBase.php | https://github.com/yiisoft/yii/blob/master/framework/YiiBase.php | BSD-3-Clause |
public static function powered()
{
return Yii::t('yii','Powered by {yii}.', array('{yii}'=>'<a href="https://www.yiiframework.com/" rel="external">Yii Framework</a>'));
} | Returns a string that can be displayed on your Web page showing Powered-by-Yii information
@return string a string that can be displayed on your Web page showing Powered-by-Yii information | powered | php | yiisoft/yii | framework/YiiBase.php | https://github.com/yiisoft/yii/blob/master/framework/YiiBase.php | BSD-3-Clause |
public function getViewFile($controller,$viewName)
{
$moduleViewPath=$this->getViewPath();
if(($module=$controller->getModule())!==null)
$moduleViewPath.='/'.$module->getId();
return $controller->resolveViewFile($viewName,$this->getViewPath().'/'.$controller->getUniqueId(),$this->getViewPath(),$moduleViewPath);
} | Finds the view file for the specified controller's view.
@param CController $controller the controller
@param string $viewName the view name
@return string the view file path. False if the file does not exist. | getViewFile | php | yiisoft/yii | framework/web/CTheme.php | https://github.com/yiisoft/yii/blob/master/framework/web/CTheme.php | BSD-3-Clause |
public function getLayoutFile($controller,$layoutName)
{
$moduleViewPath=$basePath=$this->getViewPath();
$module=$controller->getModule();
if(empty($layoutName))
{
while($module!==null)
{
if($module->layout===false)
return false;
if(!empty($module->layout))
break;
$module=$module->getParentModule();
}
if($module===null)
$layoutName=Yii::app()->layout;
else
{
$layoutName=$module->layout;
$moduleViewPath.='/'.$module->getId();
}
}
elseif($module!==null)
$moduleViewPath.='/'.$module->getId();
return $controller->resolveViewFile($layoutName,$moduleViewPath.'/layouts',$basePath,$moduleViewPath);
} | Finds the layout file for the specified controller's layout.
@param CController $controller the controller
@param string $layoutName the layout name
@return string the layout file path. False if the file does not exist. | getLayoutFile | php | yiisoft/yii | framework/web/CTheme.php | https://github.com/yiisoft/yii/blob/master/framework/web/CTheme.php | BSD-3-Clause |
public function setCriteria($value)
{
$this->_criteria=$value instanceof CDbCriteria ? $value : new CDbCriteria($value);
} | Sets the query criteria.
@param CDbCriteria|array $value the query criteria. This can be either a CDbCriteria object or an array
representing the query criteria. | setCriteria | php | yiisoft/yii | framework/web/CActiveDataProvider.php | https://github.com/yiisoft/yii/blob/master/framework/web/CActiveDataProvider.php | BSD-3-Clause |
public function getCountCriteria()
{
if($this->_countCriteria===null)
return $this->getCriteria();
return $this->_countCriteria;
} | Returns the count query criteria.
@return CDbCriteria the count query criteria.
@since 1.1.14 | getCountCriteria | php | yiisoft/yii | framework/web/CActiveDataProvider.php | https://github.com/yiisoft/yii/blob/master/framework/web/CActiveDataProvider.php | BSD-3-Clause |
public function setCountCriteria($value)
{
$this->_countCriteria=$value instanceof CDbCriteria ? $value : new CDbCriteria($value);
} | Sets the count query criteria.
@param CDbCriteria|array $value the count query criteria. This can be either a CDbCriteria object
or an array representing the query criteria.
@since 1.1.14 | setCountCriteria | php | yiisoft/yii | framework/web/CActiveDataProvider.php | https://github.com/yiisoft/yii/blob/master/framework/web/CActiveDataProvider.php | BSD-3-Clause |
protected function getModel($className)
{
return CActiveRecord::model($className);
} | Given active record class name returns new model instance.
@param string $className active record class name.
@return CActiveRecord active record model instance.
@since 1.1.14 | getModel | php | yiisoft/yii | framework/web/CActiveDataProvider.php | https://github.com/yiisoft/yii/blob/master/framework/web/CActiveDataProvider.php | BSD-3-Clause |
protected function fetchData()
{
$criteria=clone $this->getCriteria();
if(($pagination=$this->getPagination())!==false)
{
$pagination->setItemCount($this->getTotalItemCount());
$pagination->applyLimit($criteria);
}
$baseCriteria=$this->model->getDbCriteria(false);
if(($sort=$this->getSort())!==false)
{
// set model criteria so that CSort can use its table alias setting
if($baseCriteria!==null)
{
$c=clone $baseCriteria;
$c->mergeWith($criteria);
$this->model->setDbCriteria($c);
}
else
$this->model->setDbCriteria($criteria);
$sort->applyOrder($criteria);
}
$this->model->setDbCriteria($baseCriteria!==null ? clone $baseCriteria : null);
$data=$this->model->findAll($criteria);
$this->model->setDbCriteria($baseCriteria); // restore original criteria
return $data;
} | Fetches the data from the persistent data storage.
@return array list of data items | fetchData | php | yiisoft/yii | framework/web/CActiveDataProvider.php | https://github.com/yiisoft/yii/blob/master/framework/web/CActiveDataProvider.php | BSD-3-Clause |
protected function calculateTotalItemCount()
{
$baseCriteria=$this->model->getDbCriteria(false);
if($baseCriteria!==null)
$baseCriteria=clone $baseCriteria;
$count=$this->model->count($this->getCountCriteria());
$this->model->setDbCriteria($baseCriteria);
return $count;
} | Calculates the total number of data items.
@return integer the total number of data items. | calculateTotalItemCount | php | yiisoft/yii | framework/web/CActiveDataProvider.php | https://github.com/yiisoft/yii/blob/master/framework/web/CActiveDataProvider.php | BSD-3-Clause |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.