Posts Tagged with action

Displaying 1-10 of 10 results.
Resolved: WordPress How to remove cells(columns) from admin posts and pages table
posted by admin on April 21, 2017
altIn my wordpress website I have a few plugins, for example Yuzo Views, All in One Seo, etc, and they insert their columns to wordpress posts and pages editing tables, and I cant see general information in admin, like title, categories, tags etc. All fields very narrow, and I can't read information normally.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 cactiverecord not saving model
posted by admin on September 6, 2016
My model:

<?php

/**
* This is the model class for table "tbl_test".
*
* The followings are the available columns in table 'tbl_test':
* @property integer $id
* @property string $name
* @property integer $status_id
*
* The followings are the available model relations:
* @property TblQuestion[] $tblQuestions
* @property TblStatus $status
*/
class Test extends CActiveRecord
{
public $status_list;
public $status_listdata;
/**
* @return string the associated database table name
*/
public function tableName()
{
return 'tbl_test';
}

/**
* @return array validation rules for model attributes.
*/
public function rules()
{
// NOTE: you should only define rules for those attributes that
// will receive user inputs.
return array(
array('name, status_id', 'required'),
//array('status_id', 'numerical', 'integerOnly'=>true),
array('name', 'length', 'max'=>255),
// The following rule is used by search().
// @todo Please remove those attributes that should not be searched.
array('id, name, status_id', 'safe', 'on'=>'search'),
);
}

/**
* @return array relational rules.
*/
public function relations()
{
// NOTE: you may need to adjust the relation name and the related
// class name for the relations automatically generated below.
return array(
'question' => array(self::HAS_MANY, 'Question', 'test_id'),
'status' => array(self::BELONGS_TO, 'Status', 'status_id'),
);
}

/**
* @return array customized attribute labels (name=>label)
*/
public function attributeLabels()
{
return array(
'id' => 'ID',
'name' => 'Name',
'status_id' => 'Status',
);
}

/**
* Retrieves a list of models based on the current search/filter conditions.
*
* Typical usecase:
* - Initialize the model fields with values from filter form.
* - Execute this method to get CActiveDataProvider instance which will filter
* models according to data in model fields.
* - Pass data provider to CGridView, CListView or any similar widget.
*
* @return CActiveDataProvider the data provider that can return the models
* based on the search/filter conditions.
*/
public function search()
{
// @todo Please modify the following code to remove attributes that should not be searched.

$criteria=new CDbCriteria;

$criteria->compare('id',$this->id);
$criteria->compare('name',$this->name,true);
$criteria->compare('status_id',$this->status_id);

return new CActiveDataProvider($this, array(
'criteria'=>$criteria,
));
}

/**
* Returns the static model of the specified AR class.
* Please note that you should have this exact method in all your CActiveRecord descendants!
* @param string $className active record class name.
* @return Test the static model class
*/
public static function model($className=__CLASS__)
{
return parent::model($className);
}

public function __construct() {
$this->status_list = Status::model()->findAll();
$this->status_listdata = CHtml::listData($this->status_list,'id','name');
}
}


My Controller actionCreate:

public function actionCreate()
{
$model=new Test;

if($model->save()){
$this->redirect(array('view','id'=>$model->id));
}else{
die("asd");
}// Uncomment the following line if AJAX validation is needed
$this->performAjaxValidation($model);

if(isset($_POST['Test']))
{
$model->attributes=$_POST['Test'];

}

$this->render('create',array(
'model'=>$model,
));
}
Read more
Resolved: Submit form on change of dropdown list
posted by admin on April 26, 2016
I have SELECT dropdown list

<form method="GET" >
<select id="id_period" name="period">
<option value="day">day</option>
<option value="week">week</option>
<option value="month">month</option>
<option value="all" selected="selected">all time</option>
</select>
</form>

I want to submit form on changeRead more
Resolved: Yii get current controller and action
posted by admin on April 25, 2016
Is their a way to get the name of the current controller and action that the app is executing? I was wondering if Yii:app stores this or not, but I can't find any reference to it. I need this information to use in the main layout view for a widget.Read more
Resolved: Yii CActiveDataProvider CListView pagination error
posted by admin on April 15, 2016
In Controller:

$dataProviderComments = new CActiveDataProvider('Comments',
array(
'criteria' => array(
'order' => 'id DESC',
),
'pagination' => array(
'pageSize' => 10,
'pageVar'=> 'page'
),
)
);

$this->render('/media/view', array('comments'=>$dataProviderComments));

In View:

<?php $this->widget('zii.widgets.CListView', array(
'dataProvider'=>$comments,
'itemView'=>'../comments/_comment',
'ajaxUpdate'=>false,
'template'=>'{sorter}{pager}{summary}{items}{pager}',
)); ?>


When my comments less than 10, all is right, but when will be pagination, start from 11, I see this error

Fatal error: Call to a member function getId() on null in C:\xampp\htdocs\avaim.ru\framework\web\CController.php on line 962
Read more
Resolved: Yii universal action in controller to missing actions methods
posted by admin on April 11, 2016
I have a controller in Yii:

class PageController extends Controller {
public function actionSOMETHING_MAGIC($pagename) {
// Commando will to rendering,etc from here
}
}


I need some magic method under Yii CController for controlling all subrequest under /page || Page controller.Read more
Wiki: Yii 1.1 Model Save problem in MySQL queryor in update actionwiki
posted by admin on April 5, 2016
In my update Action

if($model->save()) :
...
endif;


And I have problem with MySQL save, it is Yii errorRead more
Resolved: Yii check action create and update in view _form
posted by admin on February 2, 2016
I want to check is action create or update and write specific view form row

<?php if (action check syntax here like isUpdate) : ?>
<?php echo $form->labelEx($model,'newpassword'); ?>
<?php echo $form->passwordField($model,'newpassword',array('size'=>55,'maxlength'=>255)); ?>
<?php echo $form->error($model,'newpassword'); ?>
<?php endif; ?>
Read more
Resolved: CWidget should have a createUrl implementation?
posted by admin on December 26, 2015
After some research in the source and reading the api I'd like to discuss if the CWidget class shouldn't have a createUrl() implementation like CController but appending to the action automatically the $prefixUrl. I think it could be very useful

What do you think?Read more