Displaying 191-200 of 275 results.
Resolved: Yii - Modifing html generated by CListView by default
posted by admin on March 30, 2016
I want to change generated HTML by CListView to ul li construction.
This is my CListView

<?php $this->widget('zii.widgets.CListView', array(
'dataProvider'=>$dataProvider,
'itemView'=>'_view',
)); ?>
Read more
Resolved: Yii get value from url GET name
posted by admin on March 30, 2016
I'd like to know if there is an Yii function to get a value from url. The url that I have is:

http://www.domain.com/index.php/module/controller/update/id/111

I need to get the value '111' before it gets to the update action, is there an Yii method to do it?Read more
Resolved: Yii CListView itemView from another directory
posted by admin on March 30, 2016
In controller

$dataProvider = new CActiveDataProvider('Media');
$this->render('index',array(
'dataProvider'=>$dataProvider,
));


In View index.php

<?php $this->widget('zii.widgets.CListView', array(
'dataProvider'=>$dataProvider,
'itemView'=>'_view',
)); ?>


I want to pass $dataProvider to another file in another directory.
For example I want to call the file post/_view.phpRead more
Resolved: Yii Readonly Field in CActiveForm form textField
posted by admin on March 30, 2016
My row in _form.php

<div class="form">

<?php $form=$this->beginWidget('CActiveForm', array(
'id'=>'user-form',
// Please note: When you enable ajax validation, make sure the corresponding
// controller action is handling ajax validation correctly.
// There is a call to performAjaxValidation() commented in generated controller code.
// See class documentation of CActiveForm for details on this.
'enableAjaxValidation'=>true,
)); ?>

<p class="note">Fields with <span class="required">*</span> are required.</p>

<?php echo $form->errorSummary($model); ?>
. . .
<div class="row">
<?php echo $form->labelEx($model,'username'); ?>
<?php echo $form->textField($model,'username',array('size'=>50,'maxlength'=>50)); ?>
<?php echo $form->error($model,'username'); ?>
</div>
. . .
<div class="row buttons">
<?php echo CHtml::submitButton($model->isNewRecord ? 'Create' : 'Save'); ?>
</div>

<?php $this->endWidget(); ?>

</div><!-- form -->


I want to make my username readonlyRead more
Resolved: PHP trim my strings in array
posted by admin on March 27, 2016
I have array, and I want to trim my array elements
My array

$arr = array(" one", " two", " three ", ..., etc);
Read more
Resolved: PHP remove empty strings from array
posted by admin on March 27, 2016
I have array

$arr = array("one", "two", "", "four");


I want to remove empty string from array with indexRead more
Resolved: PHP Compose array from string, by comma and space
posted by admin on March 27, 2016
I have hashtags, and I want to compose array from my hashtags string. My hashtags format is

one, two, three, four, five, six, 0909090, ... etc
Read more
Resolved: PHP Regex Remove special chars, symbols from string, allow only comma and space
posted by admin on March 27, 2016
I have tags on my blog.
Tags format, which user write is like

one, two, three, four, five, six, seven, 11887, ... etc


I want to protect my tags, and exclude situations like

#asdad, asdsad#adsd, ***m,
Read more
Wiki: Using font-face cross browser. Синтаксис Fontspringwiki
posted by admin on March 25, 2016

@font-face {
font-family: 'MyFontFamily';
src: url('myfont-webfont.eot?') format('eot'), /* IE9 Compat Modes */
url('myfont-webfont.woff') format('woff'), /* Pretty Modern Browsers */
url('myfont-webfont.ttf') format('truetype'), /* Safari, Android, iOS */Присылайте
url('myfont-webfont.svg#svgFontName') format('svg'); /* Legacy iOS */
}
Read more
Wiki: Yii 1.1 Аутентификация и авторизация. Authentication and authorization. UserIdentitywiki
posted by admin on March 24, 2016
1. Определение класса Identity. Defining Class Identity
Edit your components/UserIdentity.php

class UserIdentity extends CUserIdentity
{
private $_id;
public function authenticate()
{
$record=User::model()->findByAttributes(array('username'=>$this->username));
if($record===null)
$this->errorCode=self::ERROR_USERNAME_INVALID;
else if(!CPasswordHelper::verifyPassword($this->password,$record->password))
$this->errorCode=self::ERROR_PASSWORD_INVALID;
else
{
$this->_id=$record->id;
$this->setState('title', $record->title);
$this->errorCode=self::ERROR_NONE;
}
return !$this->errorCode;
}

public function getId()
{
return $this->_id;
}
}


2. controllers/SiteController.php, add

class SiteController extends Controller
{
...
public function filters()
{
return array(
'accessControl',
);
}
...
}


3.Check models/LoginForm.php

<?php

/**
* LoginForm class.
* LoginForm is the data structure for keeping
* user login form data. It is used by the 'login' action of 'SiteController'.
*/
class LoginForm extends CFormModel
{
public $username;
public $password;
public $rememberMe;

private $_identity;

/**
* Declares the validation rules.
* The rules state that username and password are required,
* and password needs to be authenticated.
*/
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 attribute labels.
*/
public function attributeLabels()
{
return array(
'rememberMe'=>'Remember me next time',
);
}

/**
* Authenticates the password.
* This is the 'authenticate' validator as declared in rules().
*/
public function authenticate($attribute,$params)
{
if(!$this->hasErrors())
{
$this->_identity=new UserIdentity($this->username,$this->password);
if(!$this->_identity->authenticate())
$this->addError('password','Incorrect username or password.');
}
}

/**
* Logs in the user using the given username and password in the model.
* @return boolean whether login is successful
*/
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;
}
}


4. Create models/User.php
4.1. Activate GII module
Go to config/main.php and uncomment the following rows

'gii'=>array(
'class'=>'system.gii.GiiModule',
'password'=>'o55is88oois',
// If removed, Gii defaults to localhost only. Edit carefully to taste.
'ipFilters'=>array('127.0.0.1','::1'),
),


4.2. Go to GII module

http://avaim.ru/index.php?r=gii


4.3. Generate your User.php model, from your users table

4.4. Add to User.php

public function validatePassword($password)
{
return CPasswordHelper::verifyPassword($password,$this->password);
}

public function hashPassword($password)
{
return CPasswordHelper::hashPassword($password);
}


5. Insert user to your users table and enjoy
For example, insert into your users table row
Username: admin
Password HASH: $2y$13$imm.m0q9qN/IrWF4AtmH4ejHyS3d.ElmkayY3vQ69DTApgEY4ne36

6. Login to your website
Go to your_website/index.php?r=site/login and login
Username: admin
Password HASH: 123

Enjoy ;)Read more