2

What I want to do is to use different namespaces in a controller. I have a tree scheme like this:

app/
app/controllers/
app/modules/
app/modules/modulename/
app/modules/modulename/controllers/
app/modules/modulename/controllers/modulecontroller.php
app/modules/modulename/models/
app/modules/modulename/models/modulemodel.php

What I want to do is to call a model from a controller in app/controllers/ folder. Therefore I am supposed to add namespace as follows:

    use App\Modules\Facebook\Controllers\Facebook;

The problem is that when I add a namespace and use App::() function at the sametime, I get the following error:

    Class 'App\Modules\Modulename\Controllers\App' not found

I think it is looking the App::() function in module folder. How can I solve this problem?

1
  • Can you add a few of your controller namespaces. I think you are doing something wrong there. Commented May 7, 2014 at 8:28

3 Answers 3

3

if you use App inside your App\Modules\Facebook\Controllers namespace, it will be interpreted as App\Modules\Facebook\Controllers\Facebook\App class.

since you don't want to have the previous namespace, you use a \ before App like:

\App::()

or put a use statement of top the class like use App;

Sign up to request clarification or add additional context in comments.

Comments

1

You probably are creating an unusual namspace scheme. It appears you are namespacing every class from your module differently. You should namespace your code within your module only, like so:

// Adding Onur to the namespace prevents any future namespace collisions.
<?php namespace Onur\Facebook;

After creating your namespace you should add all classes that are outside of your namespace that you want to use as followed.

use Eloquent, Input, Validate, Etc;

This prevents you from adding a \ in front of every class instance, making your code hard maintain and prone to errors. It also gives you a good overview on all the classes you are using in the current class.

Comments

1

if you say

use App\Modules\Facebook\Controllers\Facebook;

then you are supposed to use Facebook instead of App... Or don´t I understand your problem correctly?

if you say

use App\Modules\Facebook\Controllers\Facebook as FacebookController;

the you can use FacebookController in your file

if you need Access to the root App, you need to to root it using a leading \

\App::make()

1 Comment

Ok I can use it. But the main problem is that I want to use laravel's App::() function at the same time in the same controller. That time App::make() function gives me error like this: Class 'App\Modules\Facebook\Controllers\App' not found

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.