Saturday 20 April 2013

Yii Interview Question

1Q. What is meant by Yii Framework?

A. Yii is an open source and highly performed component-based PHP framework used for Web application development. This application was started on January and completed in December 2008.

2Q. Why do Yii run so FAST?

A. Yii is so much faster because it uses sluggish loading technique widely. Like it doesn’t include a class file until the class is used initially and it doesn’t create object until it is accessed for the first time. Some of the frameworks get problems because of the performance hit because they would enable functionality no matter it is used or not during its request.

3Q. tell about the file that gets loaded when you run an application using Yii?

A. index.php

4Q. Explain about model, view, controller?

A. Model represents the underlying data structure of a Web application. Models often share different sub-applications of a Web application. B. View is responsible in presenting models in the format where the end users desire. In general view contains presentational code. C. Controllers are the adhesive that binds models, views and other components composed into a runnable application. Controllers are responsible in dealing with the end user requests. Controllers access $_GET, $_POST and other PHP variables according to the user requests.

5Q. What about the naming convention in Yii?

- We define table prefix while using Gii. In your case you need to set it to tbl_. Then it should generate UserController instead of TblUserController. - The Yii Framework employees a class naming convention whereby the names of the classes directly plot to the directories in where they are stored. The root level directory of the Yii Framework is the “framework/” directory, where all classes are stored hierarchically. Class names contain alphanumeric characters.

6Q. what is the component, uses, how can we do and what is the better way?

A. A component is a piece of code written for specific task is used by calling controllers, helper is used for helping Yii in rendering the data to be shown to user with views, these adds to modularity in code or else same coding will be implemented in controllers.

7Q. How do you continue when you have to use Yii for any application?

A. If you have changed according to your needs… Proceed with basic software engg. concepts as requirement gathering etc. This is the basic Understanding Concept in Yii. - Yii based apps are driven by data logic. - Yii can generate the shebang of PHP codes automatically. - Yii will generate an essential app for you automatically. - Yii uses MySQL and SQLite. - Yii is an open-source.

8Q. What is the first function that gets loaded from a controller?

A. Index

9Q. What is meant habtm?

A. Habtm means HasAndBelongsToMany. The” has and belongs to many” is a kind of associations that defined in models for retrieving related data across different entities.

10Q. How to use ajax in Yii?

A. We use by calling ajax helper, then using it in controller for rendering.

11Q. What are the possible ways to validate a registrations module for a user?

A. This can be done in two ways by i) submission in controller, or ii) using javascript/ajax while user is still filling the data. But, comparatively Second option will be better.

12Q. List out some database related functions in Yii?

A. Query find, findAll , findByPk , find By

13Q. How to include a javascript menu through a site?

A. We can include by adding the javascript files in webroot and then call them in default views if they are needed everywhere or in the related views.

14Q.Who was the developer of the Yii and when was it build?

A. The developer of the Yii is Yii Software LLC. It was started in the year 2008 in December 3, with the version of 1.0 and continued to 1.1.13. in PHP language.

15Q. What are the requirements of the Yii?

A. To run a Yii Web application, we need a Web server which supports PHP 5.1.0. Version. The developers who want to use Yii, should understand the object-oriented programming (OOP) which is very helpful, because it is a pure OOP framework.

16Q. How does Yii Compare with Other Frameworks?

A. Comparatively to most of PHP frameworks, Yii is a MVC framework. Yii bests PHP frameworks for its efficient, feature-rich and clearly-documented. Yii is designed to be fit for serious Web application development. It is neither a consequence of some project nor a corporation of third-party work.

17Q. How do we extend Yii?

A. Extending Yii is a common action during web development. Like when we write a new controller, we extend Yii by inheriting its CController class; when we write a new widget, we will extend CWidget or an existing class. If the code is designed to be reused by third-party then we call it an extension.

18Q. How to connect to the database?

A. Most of the web applications are assisted by databases. test-drive application is not an exception. For database, we need to see the application where and how to connect it. This is done through the application configuration file WebRoot/testdrive/protected/config/main.php, the following code represent the connectivity to the database

return array(
    ‘components’=>array(
        ‘db’=>array(
            ‘connectionString’=>’sqlite:protected/data/testdrive.db’,
        ),
    ),
);

19Q. What is a Yiibase?

A. YiiBase is a helper class that serves functionalities of common framework. We should not use YiiBase directly. Instead, have to use its child class where we can customise the methods of YiiBase.

20Q. How to generate CRUD code?

A. After creating a model class file, we shall generate the code that implements the CRUD operations for user data. We choose the Crud Generator in Gii. In the model class field, we enter ‘User’. In the Controller ID field, we enter ‘user’ in lower case. Then press the preview button followed by the Generate button. Now we are done with the CRUD code generation.

Yii Interview Question