In your first example, you are importing namespaces into the controller. In your second example, you are assigning the controller to a namespace.
Importing a namespaces allows you to reference classes without having to user their fully qualified class name.
new \Entities\User() // without import
new User() // with import
Assigning a namespace to your controller actually changes the fully-qualified name for your class.
new \IndexController() // without namespace
new \Entities\IndexController() // with namespace
(Classes inside a namespace can always reference other classes in that same namespace without having to 'use' it. I suspect that was the primary reason you were trying to use option 2).
Zend Framework 1.10 is still namespace ignorant. When parsing a URL and trying to load a controller, it will look only look in the default global namespace for \IndexController
, and have no idea that it's been assigned to a user defined namespace (\Entities\IndexController
).
My recommendation is that when working with controllers in ZF, don't assign namespaces to them. Importing works fine. We'll have to wait until ZF 2.0 for full namespace support.