Displaying 51-60 of 268 results.
Wiki: CActiveRelation HAS_MANY BELONGS_TO based on secondary keywiki
posted by admin on November 16, 2016
In the Model class, I overrode the getTableSchema and manually defined the foreign keys like so:

public function getTableSchema()
{
$table = parent::getTableSchema();

$table->columns['sid']->isForeignKey = true;
$table->foreignKeys['sid'] = array('Click', 'm_sid');

return $table;
}

And in the corresponding table:

public function getTableSchema()
{
$table = parent::getTableSchema();

$table->columns['m_sid']->isForeignKey = true;
$table->foreignKeys['m_sid'] = array('Message', 'sid');

return $table;
}

Now the standard relation definitions work directly!

'clicks'=>array( self::HAS_MANY, 'Click', 'm_sid' ),

as well as

'message'=>array( self::BELONGS_TO, 'Message', 'sid'),
Read more
Resolved: Hosting iPage.com MySQL connection error: SQLSTATE[HY000] [2002] Connection refused
posted by admin on November 11, 2016
I am trying to run my Yii 1 website and connect to DB, which is not in my hosting iPage.com and have this error:

CDbConnection failed to open the DB connection: SQLSTATE[HY000] [2002] Connection refused

For example, my MySQL config in iPage.com working fine
protected/config/database.php

<?php
return array(
'connectionString' => 'mysql:host=*******.ipagemysql.com;dbname=somename',
'emulatePrepare' => true,
'username' => 'someuser',
'password' => 'somepassword',
'charset' => 'utf8',
);

Another server connection and error
protected/config/database.php

<?php
return array(
'connectionString' => 'mysql:host=anotherhostname;dbname=somename',
'emulatePrepare' => true,
'username' => 'someuser',
'password' => 'somepassword',
'charset' => 'utf8',
);

Error:

CDbConnection failed to open the DB connection: SQLSTATE[HY000] [2002] Connection refused
Read more
Resolved: Yii 1.1 Redirect to referrer url
posted by admin on November 10, 2016
I want to redirect from referrer page
Now:

$this->redirect(array('admin'));

I want something like

$this->redirect({referrer});
Read more
Wiki: Yii 1.1 right way to pass parametr to model search from relation controller and view (usage in CGridView)wiki
posted by admin on November 9, 2016
Models:

* @property integer $id
* @property integer $type_id
* @property string $name
class Store extends CActiveRecord
{
//...
public function rules()
{
return array(
//your rules
array('id, type_id, name', 'safe', 'on'=>'search, searchbytype'),
);
}

public function relations()
{
return array(
'type' => array(self::BELONGS_TO, 'Type', 'type_id'),
);
}

public function search()
{
$criteria=new CDbCriteria;
$criteria->compare('t.id',$this->id);
$criteria->compare('t.name',$this->name,true);
$criteria->compare('t.type_id',$this->type_id);

return new CActiveDataProvider($this, array(
'criteria' => $criteria,
'sort' => array(
'defaultOrder' => 't.id DESC',
'attributes' => array(
'*',
),
),
'pagination' => array (
'PageSize' => 50 //edit your number items per page here
),
));
}

//Our custom search with recieve passed parametrs
public function searchbytype($id)
{
$criteria=new CDbCriteria;
//add condition here
$criteria->condition = "t.type_id = ".$id;

$criteria->compare('t.id',$this->id);
$criteria->compare('t.name',$this->name,true);
$criteria->compare('t.type_id',$this->type_id);

//do not add condition here, filter search not working correct
//$criteria->condition = "t.type_id = ".$id;

return new CActiveDataProvider($this, array(
'criteria' => $criteria,
'sort' => array(
'defaultOrder' => 't.id DESC',
'attributes' => array(
'*',
),
),
'pagination' => array (
'PageSize' => 50 //edit your number items per page here
),
));
}

//...
}

class Type extends CActiveRecord
{
//...
public function relations()
{
return array(
'store' => array(self::HAS_MANY, 'Store', 'type_id'),
);
}
//...
}


Controller:

class TypeController extends Controller
{
//...
public function actionView($id)
{
$model = $this->loadModel($id);
$stores=new Store('searchbytype');
$stores->unsetAttributes(); // clear any default values
if(isset($_GET['Store']))
$stores->attributes=$_GET['Store'];
$this->render('view',array(
'model'=>$model,
'stores'=>$stores
));
}
//...
}

View:

<h1><?php echo $model->id; ?></h1>
<?php
$id = Yii::app()->request->getQuery('id');

$this->widget('zii.widgets.grid.CGridView', array(
'id'=>'application-grid',
'dataProvider'=>$stores->searchbytype($id),
'filter'=>$stores,
'pagerCssClass' => 'pagination pull-right',

'columns'=>array(
'id',
'name',
array(
'class'=>'CButtonColumn',
),
),
));
Read more
Resolved: Yii 1.1 CHtml activeDropDownList htmlOptions
posted by admin on November 8, 2016
I have , and want to add htmlOPtions array, for example style, or class etc...

CHtml::activeDropDownList($model, 'status_id', array_combine(array_values(array("", "3", "1")), array("Все", "Заявки", "В ожидании")));
Read more
Resolved: Yii 1.1 Cgridview filter listdata without findAll from db, with php array
posted by admin on November 7, 2016
I have CGridView with select filter, and I want to insert select box info manually with php array.
Now I have result with findAll():

<?php $this->widget('zii.widgets.grid.CGridView', array(
'id'=>'application-grid',
'dataProvider'=>$model->search(),
'filter'=>$model,
'columns'=>array(
...
array(
'name'=>'status_id',
'value'=>'$data->status->name',
'type'=>'html',
'filter' => CHtml::listData(Status::model()->findAll(), 'id', 'name'),
),
...
),
)
);
Read more
Wiki: Css3 spin icon with originwiki
posted by admin on November 7, 2016
HTML:

<h1 class="text-center">
<span class="glyphicon glyphicon-refresh spin"></span>
<span class="glyphicon glyphicon-record spin"></span>
<span class="glyphicon glyphicon-send spin"></span>
<span class="glyphicon glyphicon-star spin"></span>
</h1>

<h3 class="text-center">
<span class="glyphicon glyphicon-refresh spin"></span>
<span class="glyphicon glyphicon-record spin"></span>
<span class="glyphicon glyphicon-send spin"></span>
<span class="glyphicon glyphicon-star spin"></span>
</h3>

<h6 class="text-center">
<span class="glyphicon glyphicon-refresh spin"></span>
<span class="glyphicon glyphicon-record spin"></span>
<span class="glyphicon glyphicon-send spin"></span>
<span class="glyphicon glyphicon-star spin"></span>
</h6>

CSS3:

.spin {
-webkit-animation: spin .2s infinite linear;
-moz-animation: spin .2s infinite linear;
-o-animation: spin .2s infinite linear;
animation: spin .2s infinite linear;
-webkit-transform-origin: 50% 58%;
transform-origin:50% 58%;
-ms-transform-origin:50% 58%; /* IE 9 */
}

@-moz-keyframes spin {
from {
-moz-transform: rotate(0deg);
}
to {
-moz-transform: rotate(360deg);
}
}

@-webkit-keyframes spin {
from {
-webkit-transform: rotate(0deg);
}
to {
-webkit-transform: rotate(360deg);
}
}

@keyframes spin {
from {
transform: rotate(0deg);
}
to {
transform: rotate(360deg);
}
}
Read more
Resolved: Css pre last child
posted by admin on November 7, 2016
I want to get pre-last child of children elements
Example:

<table>
<tr><td>1<td><td>2<td><td>3<td><td>...<td><td>n-1<td><td>n<td></tr><!-- 1 -->
<tr><td>1<td><td>2<td><td>3<td><td>...<td><td>n-1<td><td>n<td></tr><!-- 2 -->
<tr><td>1<td><td>2<td><td>3<td><td>...<td><td>n-1<td><td>n<td></tr><!-- 3 -->
...//<!-- ... -->
<tr><td>1<td><td>2<td><td>3<td><td>...<td><td>n-1<td><td>n<td></tr><!-- m -->
<tr><td>1<td><td>2<td><td>3<td><td>...<td><td>n-1<td><td>n<td></tr><!-- m - 1 -->
</table>

I want to get all pre td elements selector in css styles, like

table tr td:last-child(-1){
/* to do */
}
Read more
Wiki: PHP intval - value to int conversationwiki
posted by admin on November 7, 2016
intval — Возвращает целое значение переменной
Описание

int intval ( mixed $var [, int $base = 10 ] )

Возвращает целое значение переменной var, используя указанное основание системы исчисления base для преобразования (по умолчанию основание равно 10). intval() нельзя использовать с объектами, попытка это сделать вызовет ошибку уровня E_NOTICE и вернет значение 1.
Список параметров
  • var - Скалярное значение для конвертации в целое
  • base - Основание системы исчисления для преобразования

Замечание:
Если base равно 0, основание системы исчисления определяется форматом параметра var:
  • если строка включает префикс "0x" (или "0X"), основание выбирается равным 16 (шестнадцатеричным);
  • иначе, если строка начинается с "0", основание равно 8 (восьмеричное);
  • иначе, основание выбирается равным 10 (десятеричным).

Возвращаемые значения
Целое значение переменной var в случае успеха, или 0 в случае неудачи. Для пустых массивов возвращается 0, для непустых возвращается 1.

Максимальное значение зависит от операционной системы. В 32-х битных системах максимальное знаковое целое лежит в диапазоне от -2147483648 до 2147483647. Так, например, в такой системе, intval('1000000000000') вернет 2147483647. Максимальное знаковое целое значение для 64-х битных систем - 9223372036854775807.

Для строк функция скорее всего вернет 0, хотя это зависит от первого символа в строке. Применяются общие правила преобразований в целые.
Примеры

<?php
echo intval(42); // 42
echo intval(4.2); // 4
echo intval('42'); // 42
echo intval('+42'); // 42
echo intval('-42'); // -42
echo intval(042); // 34
echo intval('042'); // 42
echo intval(1e10); // 1410065408
echo intval('1e10'); // 1
echo intval(0x1A); // 26
echo intval(42000000); // 42000000
echo intval(420000000000000000000); // 0
echo intval('420000000000000000000'); // 2147483647
echo intval(42, 8); // 42
echo intval('42', 8); // 34
echo intval(array()); // 0
echo intval(array('foo', 'bar')); // 1
?>
Read more
Wiki: Yii 1.1 app db createCommand execution of SQL statement wayswiki
posted by admin on November 7, 2016
Once a database connection is established, SQL statements can be executed using CDbCommand. One creates a CDbCommand instance by calling CDbConnection::createCommand() with the specified SQL statement:

$connection=Yii::app()->db; // assuming you have configured a "db" connection
// If not, you may explicitly create a connection:
// $connection=new CDbConnection($dsn,$username,$password);
$command=$connection->createCommand($sql);
// if needed, the SQL statement may be updated as follows:
// $command->text=$newSQL;

A SQL statement is executed via CDbCommand in one of the following two ways:
  • execute(): performs a non-query SQL statement, such as INSERT, UPDATE and DELETE. If successful, it returns the number of rows that are affected by the execution.
  • query(): performs an SQL statement that returns rows of data, such as SELECT. If successful, it returns a CDbDataReader instance from which one can traverse the resulting rows of data. For convenience, a set of queryXXX() methods are also implemented which directly return the query results.

An exception will be raised if an error occurs during the execution of SQL statements.

$rowCount=$command->execute(); // execute the non-query SQL
$dataReader=$command->query(); // execute a query SQL
$rows=$command->queryAll(); // query and return all rows of result
$row=$command->queryRow(); // query and return the first row of result
$column=$command->queryColumn(); // query and return the first column of result
$value=$command->queryScalar(); // query and return the first field in the first row
//in Russian
$rowCount=$command->execute(); // выполнение запроса типа `INSERT`, `UPDATE` или `DELETE`
$dataReader=$command->query(); // выполнение запроса типа `SELECT`
$rows=$command->queryAll(); // возвращает все строки результата запроса
$row=$command->queryRow(); // возвращает первую строку результата запроса
$column=$command->queryColumn(); // возвращает первый столбец результата запроса
$value=$command->queryScalar(); // возвращает значение первого поля первой строки результата запроса
Read more