Yii Fundamentals Flashcards

(115 cards)

1
Q

How can you run Yii in debug mode?

A

Define the YII_DEBUG constant as true, before including the yii.php file.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

The application object is also called the…

A

…front controller.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Name three things that the application object does.

A
  1. Collects information about the request.
  2. Dispatches request information to the appropriate controller for further processing.
  3. Stores application-level configuration settings.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

The application object is instantiated as a _ by the _ _.

A

Singleton, entry script.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How can you access the application singleton?

A

Yii:app().

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Where is the main application configuration stored?

A

In protected/config/main.php.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

By default, the application object is an instance of…

A

…CWebApplication.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

How do you apply application configuration?

A

By passing the configuration filename as a parameter to the application’s constructor, like this: $app=Yii::createWebApplication($configFile)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

How do you protect the contents of the /protected directory from view?

A

With a .htaccess file containing “deny from all”.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

How do you customize the class and property values of any application component used?

A

By configuring the ‘components’ property of the application instance.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

How can you access an application component?

A

Use Yii:app()->ComponentID, where ComponentID refers to the ID of the component.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

How do you disable an application component?

A

Set ‘enabled’ to ‘false’ in its configuration.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

By default, are application components created on demand?

A

Yes.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

How can you create an application component regardless of whether it is accessed or not?

A

List its ID in the ‘preload’ application property.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

List all 15 core components that are pre-declared by CWebApplication.

A
AssetManager
AuthManager
Cache
ClientScript
DbConnection
ErrorHandler
Formatter
HttpRequest
HttpSession
PhpMessageSource
SecurityManager
StatePersister
ThemeManager
UrlManager
WebUser
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

List the 8 steps in an application life cycle.

A
  1. Pre-initialize the application with CApplication:preinit().
  2. Setup the class autoloader and error handling.
  3. Register core application components.
  4. Load application configuration.
  5. Initialize the application with CApplication:init().
  6. Raise an onBeginRequest event.
  7. Process the user request: collect request information, create a controller, run a controller.
  8. Raise an onEndRequest event.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

A controller is an instance of…

A

…CController, or a class that extends CController.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

What is an action?

A

A controller class method whose name begins with “action”.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

How is a route formed?

A

By concatenating a controller ID and an action ID, separated by a slash.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

By default, are routes case-sensitive?

A

Yes.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

What is the route for a controller action inside a module?

A

moduleID/controllerID/actionID.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

When is a controller instance created?

A

When CWebApplication handles an incoming request.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

For a controller ID of admin/user, what class file is it mapped to?

A

protected/controllers/admin/UserController.php.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

What’s action parameter binding?

A

It’s when a controller action method can define named parameters whose value will be automatically populated from $_GET.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
When the run() method of an action class is defined with some parameters, they will be populated with...
...the corresponding named request parameter values.
26
What is a filter?
A piece of code that is configured to be executed before and/or after a controller action executes.
27
In what order are filters executed?
In the order that they appear in the filter list.
28
How do you define a filter?
As a controller class method, whose name must begin with "filter".
29
To apply filters to actions, you need to override the...
...CController::filters() method.
30
A filters() method should return...
...an array of filter configurations.
31
Filters can be both method-based, and...
...object based.
32
If neither plus nor minus appears in the filter configuration, the filter will be applied to...
...all actions.
33
A model is an instance of...
...CModel or a class that extends CModel.
34
What are the two types of models that Yii implements?
Form models and active records.
35
A form model is an instance of...
...CFormModel.
36
Each AR object is an instance of...
...CActiveRecord or a class that extends CActiveRecord.
37
Each AR object represents...
...a single row in a database table.
38
In an AR object, fields in a row are represented as...
...properties of the AR object.
39
How do you render a view?
Call CController::render() with the name of the view.
40
What is a layout?
A layout is a special view that is used as a container for views.
41
What is the default layout file?
protected/views/layouts/main.php.
42
How do you render a view without applying any layout?
Call renderPartial() instead of render().
43
How do you customize which layout is used?
Change either CWebApplication::layout or CController::layout.
44
A widget is an instance of...
...CWidget or a child class of CWidget.
45
How do you configure a widget to customize its behavior?
Set its initial property values when calling CBaseController::beginWidget or CBaseController::widget.
46
How do you define a new widget?
Extend CWidget and override its init() and run() methods.
47
Where are a widget's view files located?
Under the 'views' subdirectory of the directory containing the widget class file.
48
How do you render a widget view?
By calling CWidget::render().
49
Name two differences between rendering a widget view and a regular view.
1. No layout is applied to a widget view. | 2. $this in a widget view refers to the widget instance, instead of the controller instance.
50
What is a system view?
A system view refers to the views used by Yii to display error and logging information.
51
Where are Yii's default system view files located?
framework/views.
52
How do you customize Yii's default system views?
By creating the same-named view files under protected/views/system.
53
A component is an instance of...
...CComponent or its derived class.
54
How do you get a component's textWidth value, and set a component's enableCaching value to 'true'?
$width=$component->textWidth; //get | $component->enableCaching=true; //set
55
What is the benefit of using getter and setter methods to define properties in a component?
Additional logic (validation, raising events) can be executed when reading and writing the property.
56
Attaching (assigning) a method to a component event will cause...
...the method to be invoked automatically at the places where the event is raised.
57
How do you define a component event?
By defining a method whose name starts with 'on'.
58
Are event names case-insensitive?
No.
59
If an event callback is a class method, rather than a global function, how must it be given?
As an array: array($object, 'methodName');
60
Can an event be attached with multiple handlers?
Yes.
61
What is a behavior?
An object whose methods can be 'inherited' like a trait.
62
Can a component be attached with several behaviors?
Yes.
63
Which interface must behavior classes implement?
IBehavior.
64
Most behaviors can extend from the _ base class. If a behavior needs to be attached to a model, it may also extend from _ or _, which implements additional features specific for models.
CBehavior, CModelBehavior, CActiveRecordBehavior.
65
Can an attached behavior be accessed like a normal property of the component?
Yes.
66
If a behavior named 'tree' is attached to a component, how do you obtain the reference to this behavior object?
$behavior=$component->tree
67
If two behaviors attached to the same component have methods of the same name, which behavior takes precedence?
The method of the first attached behavior.
68
How can a behavior observe or change the normal execution flow of a component?
By attaching some of its methods to some events of the component.
69
If a behavior has a property named 'xyz' and the behavior is attached to a component name '$a', how can you access the behavior's property?
$a->xyz
70
What is a module?
A self-contained software unit that consists of models, views, controllers and other supporting components.
71
What's the difference between a module and an application?
A module cannot be deployed alone, and it must reside inside of an application.
72
When are modules useful?
When an application is divided into several modules, each being developed and maintained separately. Commonly-used features such as user management or content management may be developed in terms of reusable modules.
73
A module must have a module class that extends from...
...CWebModule.
74
What are the two steps required to use a module?
1. Place the module directory under 'modules' of the application base directory. 2. Declare the module ID in the 'modules' property of the application.
75
What route do you use to access a controller action in a module?
moduleID/controllerID/actionID
76
If a module named 'forum' has a controller named 'PostController', what url would refer to the controller's 'create' action?
http://www.example.com/index.php?r=forum/post/create
77
Modules can be nested in _ levels.
Unlimited.
78
What route would you use to access a controller action in a child module?
parentModuleID/childModuleID/controllerID/actionID
79
What are the 10 steps in the Yii development workflow?
1. Create the skeleton directory structure with yiic. 2. Configure the application by modifying the application configuration file. 3. Create a model class for each type of data to be managed. 4. Create a controller class for each type of user request. 5. Implement actions and their corresponding views. 6. Configure necessary action filters in controller classes. 7. Create themes if the theming feature is required. 8. Create translated messages if internationalization is required. 9. Spot data and views that can be cached, and apply appropriate caching techniques. 10. Final tune up and deployment.
80
Yii favors c_ over c_.
Conventions, configurations.
81
What happens if the actionID is omitted in the route?
The default action is taken.
82
What happens if the controllerID is omitted in the route?
The default controller is used.
83
Yii recommends naming variables, functions, and class types in what case?
CamelCase.
84
Private class member variable names should be prefixed with...
...an underscore.
85
Controller class names must be appended with the word _.
Controller.
86
A class named PageController has an ID of _.
page.
87
Any _-able properties of an object can be configured.
write-able.
88
Database tables and columns should be in what case?
Lower case.
89
Database table and column name words should be separated by...
...an underscore.
90
Should models use $_GET, $_POST, or other similar variables that are directly tied to the end-user request?
No.
91
Should models embed HTML or other presentational code?
No.
92
Should views contain DB query code?
No.
93
Should controllers directly access $_GET or $_POST?
Yes.
94
Can views access properties and methods of controllers and models directly?
Yes, but only for presentational purposes.
95
Can controllers create model instances and manage their life cycles?
Yes.
96
Should controllers contain SQL statements?
No.
97
What is a path alias?
A directory or file path, in dot syntax.
98
What can you use to translate an alias to its corresponding path?
YiiBase::getPathOfAlias()
99
What can you use to define new root path aliases?
YiiBase::setPathOfAlias()
100
What does the 'system' alias refer to?
The Yii framework directory.
101
What does the 'zii' alias refer to?
The Zii library directory.
102
What does the 'application' alias refer to?
The application's base directory, /protected.
103
What does the 'webroot' alias refer to?
The directory containing the entry script file.
104
What does the 'ext' alias refer to?
The directory containing all third-party extensions.
105
How do you include the CController class using aliases?
Yii::import('system.web.CController');
106
How does Yii's import() method differ from require() or include()?
With import(), the class definition being imported is not included until it is referenced for the first time.
107
What is 'Class Map' used for?
Pre-importing classes that can be used anywhere in a Yii application without being explicitly imported or included.
108
Demonstrate how to import the entire /framework/web directory.
Yii::import('system.web.*');
109
What is a namespace?
A logical grouping of some class names so that they can be differentiated from other class names, even if their names are the same.
110
What is the convention for naming variable and function names?
First word in all lowercase.
111
What does a token enclosed in double-braces mean in an SQL statement, like {{post}}?
Yii will translate it into a name with the table prefix specified in the application configuration.
112
The name of a class file must be the same as...
...the corresponding class name, suffixed with the '.php' extension.
113
What is the alias for a UserIdentity class, in the standard location?
application.components.UserIdentity
114
How would you configure the application so that any classes in /protected/models and /protected/components are automatically included?
'import'=>array('application.models.*', 'application.components.*')
115
What is the default alias for the primary table in a relational query?
t