Category: Yii

  • Generating Module

    Let us see how to generate a Module. Step 1 − To generate a module, open the module generation interface and fill in the form. Step 2 − Then, click the “Preview” button and “Generate”. Step 3 − We need to activate the module. Modify the modules application component in the config/web.php file. Step 4 − To check whether our newly generated module…

  • Generating Controller

    Let us see how to generate a Controller. Step 1 − To generate a controller with several actions, open the controller generator interface fill in the form. Step 2 − Then, click the “Preview” button and “Generate”. The CustomController.php file with index, hello, and world actions will be generated in the controllers folder. Form Generation Step 1 − To generate…

  • Creating a Model

    To create a Model in Gii − Generating CRUD Let us generate CRUD for the MyUser model. Step 1 − Open the CRUD generator interface, fill in the form. Step 2 − Then, click the “Preview” button and “Generate”. Go to the URL http://localhost:8080/index.php?r=my-user, you will see the list of all users. Step 3 − Open the URL http://localhost:8080/index.php?r=my-user/create. You…

  • Gii

    Gii is the extension, that provides a web-based code generator for generating models, forms, modules, CRUD, and so forth. By default, the following generators are available − To open the gii generation tool, type http://localhost:8080/index.php?r=gii: in the address bar of the web browser. Preparing the DB Step 1 − Create a new database. Database can be prepared in…

  • Localization

    I18N (Internationalization) is the process of designing an application that can be adapted to various languages. Yii offers a full spectrum of I18N features. Locale is a set of parameters that specify a user’s language and country. For example, the en-US stands for the English locale and the United States. Yii provides two types of languages:…

  • Authorization

    The process of verifying that a user has enough permission to do something is called authorization. Yii provides an ACF (Access Control Filter), an authorization method implemented as yii\filters\AccessControl. Modify the behaviors() function of the SiteController − In the above code, ACF is attached as a behavior. The only property specifies that the ACF should be applied…

  • Authentication

    The process of verifying the identity of a user is called authentication. It usually uses a username and a password to judge whether the user is one who he claims as. To use the Yii authentication framework, you need to − The basic application template comes with a built-in authentication system. It uses the user application…

  • Error Handling

    Yii includes a built-in error handler. The Yii error handler does the following − To disable the error handler, you should define the YII_ENABLE_ERROR_HANDLER constant to be false in the entry script. The error handler is registered as an application component. Step 1 − You can configure it in the following way. The above configuration sets…

  • Logging

    Yii provides a highly customizable and extensible framework. With the help of this framework, you can easily log various types of messages. To log a message, you should call one of the following methods − The above methods record log messages at various categories. They share the following function signature − where − A simple…

  • Aliases

    Aliases help you not to hard-code absolute paths or URLs in your project. An alias starts with the @ character. To define an alias you should call the Yii::setAlias() method − You can also derive a new alias from an existing one − You can call the Yii::setAlias() method in the entry script or in a writable…