What is Yii framework?
Yii is a high-performance component-based PHP framework best for Web Application 2.0 development.
Why Yii is so fast?
Yii is so much faster because it is using the lazy loading technique extensively. For example, it does not include a class file until the class is used for the first time; and it does not create an object until the object is accessed for the first time. Other frameworks suffer from the performance hit because they would enable functionality (e.g. DB connection, user session) no matter it is used or not during a request.
what is the first file that gets loaded when you run a application using Yii?
What is Model,View,Controller?
Models represent the underlying data structure of a Web application. Models are often shared among different sub-applications of a Web application. For example, a LoginForm model may be used by both the front end and the back end of an application; a News model may be used by the console commands, Web APIs, and the front/back end of an application. Therefore, models
- should contain properties to represent specific data;
- should contain business logic (e.g. validation rules) to ensure the represented data fulfills the design requirement;
- may contain code for manipulating data. For example, a SearchForm model, besides representing the search input data, may contain a search method to implement the actual search.
Views are responsible for presenting models in the format that end users desire. In general, views
- should mainly contain presentational code, such as HTML, and simple PHP code to traverse, format and render data;
- Should avoid containing code that performs explicit DB queries. Such code is better placed in models.
- Should avoid direct access to $_GET, $_POST, or other similar variables that represent the end user request. This is the controller’s job. The view should be focused on the display and layout of the data provided to it by the controller and/or model, but not attempting to access request variables or the database directly.
- may access properties and methods of controllers and models directly. However, this should be done only for the purpose of presentation.
Controllers are the glue that binds models, views and other components together into a runnable application. Controllers are responsible for dealing directly with end user requests. Therefore, controllers
- may access $_GET, $_POST and other PHP variables that represent user requests;
- May create model instances and manage their life cycles. For example, in a typical model update action, the controller may first create the model instance; then populate the model with the user input from$_POST; after saving the model successfully, the controller may redirect the user browser to the model detail page. Note that the actual implementation of saving a model should be located in the model instead of the controller.
- Should avoid containing embedded SQL statements, which are better kept in models.
- Should avoid containing any HTML or any other presentational markup. This is better kept in views.
What is the naming convention in Yii?
You can define table prefix when using Gii. In your case you need to set it to tbl_. Then it should generate UserController instead of TblUserController.
The Yii Framework employs a class naming convention whereby the names of the classes directly map to the directories in which they are stored. The root level directory of the Yii Framework is the “framework/” directory, under which all classes are stored hierarchically.
Class names may only contain alphanumeric characters. Numbers are permitted in class names but are discouraged. Dot (.) is only permitted in place of the path separator.
What is the component, helper and why are they used, is there other way we can do same thing, what is better?
A component is an independent piece of code written for specific task that can be used by calling in controllers (example : email component), helper is used for helping yii in rendering the data to be shown to user with views, these only adds to modularity in code otherwise same coding can be implemented in controllers.
What is the first function that gets loaded from a controller?
What is Habtm?
HasAndBelongsToMany
Has and belongs to many is a kind of associations that can be defined in models for retrieving associated data across different entities
How can we use ajax in Yii?
By calling ajax helper and then using it in controller for rendering.
If you have to validate a registrations module for a user, what all can be possible ways, which one is the best?
Can be done on submission in controller, or using javascript/ajax while user is still filling the data. Second option is better.
Can you list some database related functions in Yii?
find, findAll, findByPk, findByquery
how can you include a JavaScript menu thought the site? give steps?
By adding the javascript files in webroot and call them in default views if needed everywhere or just in the related views.
How to install or setup Yii-framework in your local system?
To install Yii you need to
- Download the Yii code from its official website or github.
- Extract the code into your server root directory.
- Open command line terminal and type the following command.
- php path-to-yii-folder/framework/yiic webapp [webapp-name]
- After execution of above command, it will ask you for the confirmation of creating your application, on selecting yes, this will create a defaut application.
How to configure Yii aplication with database?
In default application of yii, open the main.php file exists in protected/config/main.php and search for a parameter named as db, there you can add host-name, database name, username and password of your database server.
What are the features of Yii Framework?
- Built in MVC pattern
- It has high performance.
- It provides features for both relational and NoSQL databases.
- It’s never over-designs things for the sole purpose of following some design pattern.
- It is extremely extensible.
- It provides multi-tier caching support and RESTful API development support
How you can create and work with different module in Yii?
To create a module access gii url and there you can create a module. After creating a module from gii you need to add it the mai configuration file of your yii application.
localhost/your-app/index.php?r=gii // utl to access gii
….
‘modules’ => array(
‘module-name’,
‘other-module’,
‘user’ => array(
‘activeAfterRegister’ => false,
),
…..
What is ‘Gii’ and why it is used?
Gii is a module that provides Web-based code generation capabilities. To work with gii, you need to change the main configuration file of your application like following.
return array(
……
‘modules’=>array(
‘gii’=>array(
‘class’=>’system.gii.GiiModule’,
‘password’=>[*choose a password*]
),
),
)
To access gii in your local system, hit the url on your browser localhost/your-app/index.php?r=gii. You need to type the password that you have set in the main configuration of your app. to proceed further.
What is the difference between render and renderpartial?
render() is commonly used to render a view that corresponds to what a user sees as a “page” in your application. It first renders the view you have specified and then renders the layout for the current controller action (if applicable), placing the result of the first render into the layout. It then performs output processing (which at this time means automatically inserting any necessary <script> tags and updating dynamic content) and finally outputs the result.
renderPartial() is commonly used to render a “piece” of a page/HTML. The main difference from render() is that this method does not place the results of the render in a layout.
How to Files uploads in Yii?
A file uploading function :yii\web\UploadedFile, models and yii\widgets\ActiveForm.