Yii Interview Questions and Answers – Part 3

21. What is the differences between render , renderPartial and renderfile in yii framework ?
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 and finally outputs the result. i.e) render with theme.
renderPartial() is commonly used to render a “piece” of a page. The main difference from render() is that this method does not place the results of the render in a layout. By default it also does not perform output processing, but you can override this behavior using the $processOutputparameter. i.e) render without theme.
renderFile() is a low-level method that does the grunt work of rendering: it extracts the data variables in the current scope and then runs the view code. The other two methods internally call this one, but you should practically never need to call it yourself. If you do, keep in mind that you need to pass in a file path (not a view path).

22. How to use widget on Yii framework ?
To use a widget, do as follows in a view script:

beginWidget('path.to.WidgetClass'); ?>
...body content that may be captured by the widget...
endWidget(); ?>


widget('path.to.WidgetClass'); ?>

23. How to defining a component property in Yii ?
There are two different ways of defining a component property. First way is to simply declare a public member variable in the component class like the following:

class Document extends CComponent
public $textWidth;

Another way is to use getters and setters. It is more flexible since additionally to normal properties you can declare a read only or write only property.

class Document extends CComponent
private $_textWidth;
protected $_completed=false;

public function getTextWidth()
return $this->_textWidth;

public function setTextWidth($value)

public function getTextHeight()
// calculates and returns text height

public function setCompleted($value)

The component above can be used like the following:

$document=new Document();

// we can write and read textWidth
echo $document->textWidth;

// we can only read textHeight
echo $document->textHeight;

// we can only write completed

24. Why do Yii run so FAST?
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.

25. What about the naming convention in Yii?
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.

26. what is the component, uses, how can we do and what is the better way?
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.

27. What is the first function that gets loaded from a controller?
Index function. i.e) actionIndex()

28. What is meant habtm?
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.

29. How to use ajax in Yii?
We use by calling ajax helper, then using it in controller for rendering.

30. What are the possible ways to validate a registrations module for a user in Yii?
This can be done in two ways by
i) submission in controller, or
ii) ii) using javascript/ajax while user is still filling the data. But, comparatively Second option will be better

Sign-up for our email newsletter and get free job alerts, current affairs and GK updates regularly.
Subscribe Here (or)

Leave a Reply

Your email address will not be published. Required fields are marked *

3 × = twenty one

Popup Dialog Box Powered By : XYZScripts.com
  • RSS
  • Facebook
  • Google+
  • Twitter