Install http://www.yiiframework.com/extension/yii-debug-toolbar/
enabling SQL:
put
‘enableProfiling’=>true, // in database setting in config/main.php
Install http://www.yiiframework.com/extension/yii-debug-toolbar/
enabling SQL:
put
‘enableProfiling’=>true, // in database setting in config/main.php
Hey! do you need that double insert every time user create
public function actionCreate()
{
$model = new Records();
if($model->load(Yii::$app->request->post()))
{
$model->name = $model->name.’.trustpositifkominfo’;
$model->save();
// second insert here
$clone = new Records;
$clone->attributes = $model->attributes;
$clone->name = ‘*.’.$clone->name;
$clone->save();
return $this->redirect([‘view’, ‘id’ => $model->id]);
}
else {
return $this->render(‘create’, [
‘model’ => $model,
]);
}
}
hello! After a long hiatus. I got a project for my office. It is a dashboard application for powerdns. All the records have only 1 master domain. So, I have to do a trick to put trustpositifkominfo as a domain for every record inserted. here is the magic:
public function beforeSave($insert) {
if ($insert) {
$this->domain_id = 1;
$this->name = $this->name.’.trustpositifkominfo’;
}
return parent::beforeSave($insert);
}
Link presentasi
Pada sabtu 23 Januari 2016 saya mendapatkan kesempatan menarik untuk menjadi salah satu pembicara di seminar kerjasama STMIK Nusa Mandiri, BSI beserta PHP Indonesia.
To rename ToggleButton YiiBootstrap label,
just add ‘enabledLabel’ and ‘disabledLabel’ to an array. Example:
//in view/_form
<?php echo $form->toggleButtonRow($model,’Status’, array(‘enabledLabel’ => ‘Active’,’disabledLabel’ => ‘Inactive’, ‘width’ => 150,)); ?>
public function afterSave(){
Model2::model()->updateByPk($this->goods_id,array(‘stock’=>$this->balance_history)); // from model 1
return parent::afterSave();
}
Add in the first Model,
public function beforeSave() {
$model2 = new StudentRegistration;
$model3 = new RegistrationDetail;
// data Model 2
$model2->save();
$this->idfrommodel1=$model->idmodel2; //copy id
}
Today I challenge myself to make a documentation of my code. And the topic of today’s post is how to create search (filter) for related model in your GridView (using yiiframework).
First, we’re working in model:
public $CourseIDFK; // put your target field’s name as a public variable
then, make a function, let’s name it search2().
public function search2() {
$criteria = new CDbCriteria;
$criteria->together = true;
$criteria->with[] = ‘courseIDFK’;
if ($this->CourseIDFK) {
$criteria->compare(‘courseIDFK.Name’, $this->CourseIDFK, true);
}
return new CActiveDataProvider($this, array(
‘criteria’ => $criteria,
));
}
then in controller put ‘search2’ as a parameter of the model’s object :
$model=new Classregistration(‘search2’);
in view admin, set dataprovider as below:
‘dataProvider’=>$model->search2(),
and don’t forget to put your target’s field value
‘value’ => ‘($data->courseIDFK->Name)’, // this is your target field’s value
voila! now you can search any value of your related model in your GridView 😉
Still can’t figure out? ask me in comment section. Sure I will help u ^^
Hai! I’m a twenty-something coder girl who has a giant dream. I want to remember all of the logics that I wrote in my yii based application. Don’t hesitate to ask anything that related to my blog post 🙂
Ciao bella!