Home » Install Methods » how we can use dynamic model yii2

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.

How to create dropdown in yii2 gridview

Back to top