Doctrine - Fatal error: Class not found - php

My terminal says that a certain class doesn't exist when updating schema through the command "php doctrine orm:schema-tool:update".
This is the response:
Fatal error: Class 'Emily\Controller\PageController' not found in /src/Emily/Controller/Page/Login.php on line 8
This is the source:
<?php
namespace Emily\Controller\Page;
use Emily\Controller\PageController;
class Login extends PageController
{
}
This is the parent/PageController:
<?php
namespace Emily\Controller;
use Emily\Controller\Controller;
class PageController extends Controller
{
}
I've checked names, paths, but all is in place. Why does doctrine keep telling me the class doesn't exist?
Many thanks!

Related

Fatal Error Class 'App\Http\Controllers\Controller' not found Laravel 5.4

I tried to route with using name .
I already tried to solve with using Composer update , Clear Cache , Generate App key.
But it's showing fatal error .
Error View Message :
(1/1) FatalErrorException
Class 'App\Http\Controllers\Controller' not found
in ClassesController.php line 13
My Route Code Below :
<?php
Route::prefix('Classes')->group(function(){
Route::get('/add','ClassesController#index')->name('AddNewClass');
});
My Controller Code Below :
<?php
namespace App\Http\Controllers;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
class ClassesController extends Controller{
public function index()
{
return "Method Access";
}
In this event, I would first ensure that the file containing the class Controller exists in the same directory with the same namespace as the ClassesController, as implied in your code.
If the Controller does not exist, you can either create the class or simply remove the extends Controller and the line use App\Http\Controllers\Controller; from your code.
its worked for me.
usercontroller
<?php
namespace App\Http\Controllers;
use App\Http\Controllers\Controller;
class UserController extends Controller
{
/**
* Show the profile for the given user.
*/
/* http://localhost:8080/laravelapps/blog/public/staff */
public function showProfile()
{
return 'new';
}
}
web.php
Route::get('/staff', 'UserController#showProfile');
http://localhost:8080/laravelapps/blog/public/staff
Check whether Controller.php file exists or not in your Controllers folder if not exists download or put from laravel project.
After that run following command php artisan app:name newproject
Make sure in the above line i have updated text 'newproject' that should be first line of your Controller.php file. For example: namespace newproject\Http\Controllers;

PHP Fatal error: Interface 'App\\PluginContract' not found

In the same direcory I have:
html/app
Plugin.php
PluginContract.php
GetUid.php
On GetUid.php i have this code:
<?php
namespace App;
include_once "Plugin.php";
include_once "PluginContract.php";
use Carbon\Carbon;
use TeamSpeak3\Ts3Exception;
class GetUid extends Plugin implements PluginContract
{
public function isTriggered()
{
...
}
}
And this is PluginContract.php:
<?php
namespace App;
interface PluginContract
{
public function isTriggered();
}
It seems all ok, but I got this error:
PHP Fatal error: Interface 'App\PluginContract' not found in /var/www/html/app/GetUid.php on line 11
The weird thing is that it can load Plugin.php without problem but it gets this error for PluginContract.php which is in the same folder.
What I'm doing wrong?
What I was tring to do is add a web interface to a PHP application, I though that I don't need the autoload because it automatically start with the server, but I discovered that adding again the autoload to my index.php I resolved the problem.

Can't find PHP class after implementing namespaces

I am dealing with an old PHP class called Config in a Config.class.php file.
Recently, I have implemented namespaces:
<?php
namespace Tfr\Partners\Smartfocus;
use Tfr\BaseApp;
class Config
{
...
} else {
$isProd = BaseApp::isProd();
}
...
When I am running the code, I now get the following error message:
Fatal error: Class 'Tfr\BaseApp' not found in
<some_path>/Partners/Smartfocus/Config.class.php on line 45
but the BaseClass is there in a file called <some_path>/BaseApp.class.php. However, it does not have a namespace itself.
Unfortunately, it is used in many places in a large code base, and adding a namespace to BaseClass seems very risky.
How can I 'import' BaseClass in Config safely and get rid of my error?

Using class constants in PHPUnit annotations

The manual of PHPUnit shows, that I can use class-constants in annotations for #expectedExceptionCode, see PHPUnit #expectedExceptionCode
I try to use it within my name spaced model which extends from Eloquent.
When I run my tests I got an: "PHP Fatal error: Class 'Eloquent' not found"
Running the App is all fine, so it depends on the Unit-Tests, isn't it?
Any ideas?
namespace Foo\Models;
use \Eloquent;
class Bar extends Eloquent {
const ERRORCODE = 150;
...
}
class BarTest extends TestCase {
/**
* #expectedExceptionCode Foo\Models\Bar::ERRORCODE
*/
public function testFoobar()
{
$name = 'foobar';
Bar::findBarOrFail($name);
}
}
For clarification:
PHP Fatal error: Class 'Eloquent' not found in PathToProject/app/models/Bar.php
Update
After #j-boschieros comment I got the above code working! Thanks mate!
However, when I provoke the exception in a controller test, the fatal error still occurs.
Even if I use the namespaces or not.
use \Eleoquent;
use Foo\Models\Bar;
class TestController extends TestCase {
/**
* #expectedExceptionCode Foo\Models\Bar::ERRORCODE
*/
public function testStoreActionWithInvalidDatatyp ()
{
$this->call('POST', '/routeToException');
}
Update 2
Got my Unit-Tests working when I extend \Illuminate\Database\Eloquent\Model instead of Eloquent.
namespace Foo\Models;
use \Illuminate\Database\Eloquent\Model;
class Bar extends Model {
const ERRORCODE = 150;
...
}
This differs from Laravel Doc. Is it still okay?
The "class" \Eloquent is actually an alias which is registered at run-time by the Laravel framework. You're making PHP parse the model class file before these aliases have been set up, causing it to fail. The correct approach to this is just to avoid the global namespace aliases and use the real class names instead (Illuminate\Database\Eloquent\Model instead of Eloquent in your case). You can find a list of class aliases in app/config/app.php.

Laravel 4 : Unable to access Auth instance inside package class

I have this class in a workbench package:
class SomeClass{
//Constructor
function __construct(){
$isAuth = Auth::check();
}
But it gives me following error:
Class 'vendor\pachage\Auth' not found
Is this a namespace issue? I am using the following namespace:
namespace vendor\pachage;
You need Fully qualified name, add a backslash:
\Auth::check();
It all described as Namepace resolution.

Categories