Home » Tips

This tutorial will show you how we can use dynamic model yii2.In some case, we do not want the model because we do not want to insert any data in the MySQL tables. But we need client-side and server-side validations to secure our functionality. To overcome this problem we have an option in yii2 to use dynamic models.

For DynamicModel we don’t need to create any file Or Class. Everything is already implemented by Yii we just need to define rules for our fields. For Example in the controller you can add like below:

In render view form is like

In above example i used only one filed amount you can add multiple. You can add all kinds of rule in Dynamic model.

Some example where we can use this Dynamic model is:
1. If we have some feedback page on our website.
2. we can also use the Dynamic model to get some information from users like phone number, email, etc.

Hope this will help you.

Today we are going to learn how to create dropdown in yii2 gridview. In this post, I will show you how we can add dropdown list in grid view filter and in the column value.

Let’s start.

In the above example, I create a dropdown for the status column. The resultant images are below:

dropdown image

(dropdown in yii2 gridview)

 

image for filter

gridiew filter dropdown

(dropdown in gridiew filter)

you can update status with the help of changeStatus() function.

Hope this will help you 🙂


Summary: 
In this post, We are going to learn the meaning of tilde (~), caret (^),  wildcard ( * ) in composer.json file. When we install the composer you can see a file name composer.json is created. When we just open it we can see some sign near to version like tilde (~), caret (^) and wildcard ( *). For example, I show you
yii2 json file below:

Composer.json file different for different dependency.

Let’s start,
While we install any dependency through the composer we need to define which version of any dependency we are going to use that why we need the separate type symbol to define the versions. With the help of these symbols, you can define that which version of any dependency you want to use. You can also use logic operators (, often means AND and | means OR) to define the range of version. Even you can use some complex condition for the version by using comparators, for example, >=0.8.0,<0.10.0
Means of this is your version greater than 0.8.* and less than 0.9.*  (wildcard ( * )  means value lies between 0 to 9)

Let’s take a look of the tilde (~) and caret (^) symbol.

  • ~3.1.2 means >= 3.1.2,<3.2.0,
  • ~3.1    means >= 3.1.0,<4.0.0,
  • ~0.3   means >= 0.3.0,<1.0.0,
  • ~3       means >= 3.0.0,<4.0.0.

The caret symbol is a bit different:

  • ^3.1.2 means >= 3.1.2,<4.0.0,
  • ^3.1    means >= 3.1.0,<4.0.0 (just like ~3.1),
  • ^0.3   means >= 0.2.0,<0.4.0,
  • ^3       means >= 3.0.0,<4.0.0 (As it is like ~3).

That’s all 😃👍
Hope you understand still have any question you can comment below.

Summary: In this post, I am going to show the Top 7 commands of git you must learn. These are some basic commands that you must have to learn before continuing with Git. Git is a fast-growing platform to manage code and repository. Git has a lot of features related to managing code and taking backup of files and folders. The best part of git it is very easy to learn. There are many web-based hosting services that using git like Github, Gitlab, and Bitbucket. If you do not know how to download Git you can read (link).

Let’s start,

git clone:- This is a very first command when you are going to clone your repository. You need to add your repository link after this command. For example, as I show below:

git clone https://github.com/gs63875/yii2.git

https://github.com/gs63875/yii2.git is our public repository on git Github you can create yours on any platform like Github, Gitlab, and Bitbucket.
If you do not know how to create a new repository on git you need to read (this article).
After running above command on Terminal, cmd or Gitbash any of these It will ask for your repository username and password. You need to fill this out.

git status:- When you have done with the changes you need to run git status command to check in which file you have done changes. It will show you all those files that updated by you recently.

git add:- This command stage you change for git. It means files get ready to commit run below command:

git add filename  

When you made the changes  in multiple files then you need to run below command:

git add .

git add . add your all files in which you have made changes.

git commit:- After adding the file for commit we need to commit changes for this we need to run for example:

git commit -m "your message"

In this command, we need to a message for our commit. This message is very useful to remember our changs.

git commit -am:- This command is the combination of both git add and git commit command you can run this command like below:

git commit -am "your message"

This command is only working to update or edit. For new add file, you need to run git add and git commit separately.

git pull:- git pull command pull the code from git. If you already working on any repository it pulls only that files that different from your local repository.

That’s all for git 😊. Comment below if you have any question.

 

basic linux commands for files and folders

Introduction: Linux is a free and open-source operating system just like Windows and Mac OS. We can use Linux on computers and servers.

Summary: Basic Linux commands for files and folders I choose this topic Because so many users don’t know about the simple command of Linux. In this post, I am going to show you some basic command related to folder and file so that you can easily manage them. We need Shell or Terminal to execute these commands. We can do complex things very easily using these simple commands.
So Let’s Start,

pwd: When you open the terminal, you’re in the home directory of your user. To know the present directory, you can use “pwd“. This full form of this is the present working directory.

cd: stands for change directory. If you want to go from one folder to another you need to write cd folder name. For example, if you in Test1 directory and want to go directory Test2 simply write:

If you want to jump back form any folder just use below command:

ls: ls command is used to list out files and folder in any directory or folder. You simply need to write ls.

touch: Sometimes we need to create a file in the folder. The touch create a new file it can be any file like .txt or .php
any type of file you can create by touch command. For example, if we need a text file in Test1 folder just go in this
with the help of cd then use below command:

After running above command that checks with ls you a text file created in your folder.

mkdir: Stands for make directoryIt works similarly like touch but Its job is kinda different it will create new directory into your present folder. For example, in below command:

rm: Stands for removeThe rm command used t remove files and folders. To remove directory need to use rm -r  because of rm command to able to remove the directory.

chmod: Sometimes you need to perform above action with files and folders but you can’t do that action because of permission issue. You can give permission to any file and folder according to your requirement. For example, you can give permission chmod 777 -R for reading, write and execute.

In the above example, I am giving permission to my new.txt.
That’s all! ?
Please comment below if you have any query or you want to know about more command.  ?

Back to top