davzie / laravel-bootstrap

[DEPRECATED] A Laravel 4, Bootstrap 3 CMS Built With SOLID Principles In Mind
Other
558 stars 165 forks source link

Regarding namespace and use #21

Closed andrewvmail closed 10 years ago

andrewvmail commented 10 years ago

In the vendor/Davzie/Controllers each of the file has a namespace and then following those some has a line with "use view, config" etc.

Why do you need to specify the View,Config etc aliases. Normally dont they Autoload without namespace.. I can't wrap my head around this. I comment those out and i get error. So I'm guessing when we use namespace we are overriding some settings?

davzie commented 10 years ago

Normally in controllers you would be able to access these Laravel Facades but the controllers in Laravel Bootstrap have a namespace themselves which takes them outside of the global namespace that Laravel’s facades are defined in, imagine a container like this:

[   App,   DB,   View,   Config,   Davzie[     LaravelBootstrap[         Controllers     ]

  ]

]

So my controllers are nested in that big namespace which is great to keep things separate but we do need to tell it to use those facades outside of that namespace :)

Hope that helps,

Dave

On 15 February 2014 at 12:36:38, Andrew (notifications@github.com) wrote:

In the vendor/Davzie/Controllers each of the file has a namespace and then following those some has a line with "use view, config" etc.

Why do you need to specify the View,Config etc aliases. Normally dont they Autoload without namespace.. I can't wrap my head around this. I comment those out and i get error. So I'm guessing when we use namespace we are overriding some settings?

— Reply to this email directly or view it on GitHub.

andrewvmail commented 10 years ago

Thanks for the explanation! That helps! I think I got it. I'm guessing I have to do the same if I want to use some of your vendor codes in the front end for instance your composers/page. I like the way you preload all the variable for the view there.

How did you get away with just using single word not the full path? OH ! is it because of the alias defined in App.php?

Cheers!

davzie commented 10 years ago

The full path is simply the alias because it is in the global namespace (top level). You may see instances where within say: Davzie\Posts\Post I may be referring to Davzie\Accounts\Users - I have to use the full path in that instance because the ‘use’ statement is relative to the root namespace (or global as I have called it). 

On 16 February 2014 at 04:56:14, Andrew (notifications@github.com) wrote:

Thanks for the explanation! That helps! I think I got it. I'm guessing I have to do the same if I want to use some of your vendor codes in the front end for instance your composers/page. I like the way you preload all the variable for the view there.

How did you get away with just using single word not the full path? OH ! is it because of the alias defined in App.php?

Cheers!

— Reply to this email directly or view it on GitHub.

andrewvmail commented 10 years ago

Got it! Thanks for the explanation.

Andrew