How to split full name from model into firstname and lastname in yii2 view and concat to save in yii2 model


First create a model of the table using GII tool in yii2,then by using CRUD option in GII create MVC file ,which has create,update function in controller and add rules in model like

[[‘first_name’,’last_name’], ‘trim’],
[[‘first_name’,’last_name’], ‘required’],
[[‘first_name’,’last_name’], ‘string’, ‘max’ => 50],

And variable above rules like

public $first_name;
public $last_name;

As the controller render update.php in view folder,the update file render _form.php

In  _form.php

I added the php code to split username into first name and last name

$parts = explode(” “, $model->name);
$lastname = array_pop($parts);
$firstname = implode(” “, $parts);

$model->first_name = $firstname;
$model->last_name = $lastname;

And the form fields like

<?= $form->field($model, ‘first_name’)->textInput([‘maxlength’ => true]) ?>
<?= $form->field($model, ‘last_name’)->textInput([‘maxlength’ => true]) ?>

In model concat the firstname and lastname into $model->name to save.

$model->name = $this->first_name.’ ‘.$this->last_name;
return $model->save();

 

 

Tagged with: , , , , , , , , , ,
Posted in yii2

My new experience with jquery


Disable the all  input fields with unique (ID) like numbers  in table :

$(“#table_id  input[type=’text’][id=” + id + “]”).prop({
disabled: true
});

Disable the all  Select fields with unique (ID)  like numbers in table :

$(“select[id=” + id + “]”).prop({
disabled: true
});

Change the placeholder text in input field of table by unique (ID) like numbers :

$(“#table_user_lists input[type=’text’][name=’user_name’][id=” + id + “]”).attr(‘placeholder’, user_name);

jquery change function by name attribute of array:

$(‘input[name =”name[]”]’).change(function () { });

Enable the select of unique (ID) on each:

$(“#table_id *[id]”).each(function () {
if ($(this).attr(‘id’) == id) {
$(this).prop(‘disabled’, false);
}
});

Tagged with: , , , , , , , ,
Posted in javascript and jquery

Find mysql_query issue


Paste the code below mysql_query or mysqli_query to find correct issue,recently i used it in project and found that table itself not exited in database.

if (!$res) {
printf(“Error: %s\n”, mysqli_error($this->conn));
exit();
}

Tagged with: , , , , , ,
Posted in php

Points to Remember in Yii


1)Yii application is build using Model-View-Controller(MVC) architecture.

2) Yii implements two kinds of model form model (CFormModel class) and active records(CActiveRecord class),which are extended by same base class cmodel.

3)form model represent the logic for form fields validation and bussiness logic.

4)Active records is design pattern of database structure to abstract the data access in object oriented way.

5)Controller is responsible for taking form inputs,interacting with model and passing the updated info to the view.

6)The router is action taken place as user sent request to the application.

yii work flow

yii work flow

 

Please share any of the important points in yii in comments.thank you

 

Tagged with: , , , , , ,
Posted in php, yii framework

forEach vs for loop in javascript


I tried the  run the javascript array in forech and for loop and i faced the issue like undefined in forech loop .

Example foreach Loop:

foreach

Example For Loop:

for-loop

any solution for foreach  and Please share your experience in it.

 

 

Tagged with: , , , , ,
Posted in javascript
Follow php tutorial on WordPress.com
categories
Calendar
August 2017
M T W T F S S
« Sep    
 123456
78910111213
14151617181920
21222324252627
28293031  
Follow me on Twitter
Blog Stats
  • 74,953 hits
%d bloggers like this: