views:

36

answers:

2

i am wondering what does adding ...

resources.view[] = 

... init application.ini actually do?

i know it allows me to access the view from bootstrap by

$this->bootstrap('view');
$view = $this->getResource('view');

but i wonder how does zf know resources.view = zend view? i guess doing that and accessing $view by getResource('view') will create a view initialized using the zend view plugin?

if i dont add the line resources.view[] = my app still has a zend view right? so why is that line required, just to get the view resource?

+3  A: 

That line triggers bootstrapping of the View resource, see:

http://framework.zend.com/manual/en/zend.application.available-resources.html#zend.application.available-resources.view

it allows you to set a load of options (doctype, encoding etc.) via. the application.ini.

Without that line you will still have a view yes, as the viewRenderer will create a View object on demand when it is first required.

Tim Fountain
i am actually wondering if ZF is "hardcoded" to recognize that as telling it to trigger the bootstrapping the view resource, cos if i do something like `resources.myresource[] = ` it will not do anything right?
jiewmeng
It'll map what's in the ini file to the appropriate resource class, so view[] will map to Zend_Application_Resource_View. I would imagine using a non-existent thing like myresource will error unless you create an equivalent class yourself.
Tim Fountain
A: 

The :

resources.view[] =

in ini file is equal to php's empty array:

array(
    'resources' => array(
         'view' => array()  // pass empty array of the view options
    )
)

The Bootstrap checks whether the resources array is null, so if you pass an empty array, you pass no options, but the comparison result is not null, which results in running the view resource, but without any options.

To have the same effect, you could do:

resources.view.enabled = 1

But this sends option enabled to the view resource.

takeshin