phplaravel-4namespacesphpcodesnifferlaravel-4.2

phpcs - class must be in a namespace of at least one level - how to fix?


I am using laravel 4.2.

Lets say there is such class:

class BShopsController extends ShopsController

To fix this, I try to use name space lets say this:

namespace app\controllers;

and then it does not find ShopsController

so I add

use \ShopsController;

Then I get error:

Class BShopsController does not exist

What namespace should I use first of all so it would not break anything?

Edit:

BShopsController and ShopsController are in folder Shops


Solution

  • So with the help of Shhetri and this Using namespaces in Laravel 4

    I did this way:

    namespace App\Controllers\Shops;
    
    class BShopsController extends ShopsController{}
    

    Also in routes.php then need to change to this:

    Route::controller('shops', 'App\Controllers\Shops\ShopsController');
    

    And where calling action() method - also need to use namespace.

    Also needed to run

    composer dump-autoload -o 
    

    otherwise were errors.

    Also in ShopsContrller needed to to this:

    use \App\Controllers\BaseController;
    

    Because Shops controller was in another namespace than BaseController and cannot find it. But is extending from BaseController, so need it.