Class not found php user

PHP class not found but it’s included

I still can’t figure out what’s the problem. I’m 99% sure it’s correct. The «$ENGINE» is correct, and the class is correct too (Netbeans suggests me class methods and variables). signup.php:

createUser($_POST["username"], $_POST["email"], $_POST["password"]); ?> 
set( "user.".$username, array( 'ID' => uniqid(), 'Username' => $username, 'Email' => $email, 'Password' => $password ) ); > > ?> 

18 Answers 18

Check to make sure your environment isn’t being picky about your opening tags. My configuration requires:

Then I get the same error as you.

Short tags can be enabled through the INI setting short_open_tag.

if ( ! class_exists('User')) die('There is no hope!'); 

I had this problem and the solution was namespaces. The included file was included in its own namespace. Obvious thing, easy to overlook.

It may also be, that you by mistake commented out such a line like require_once __DIR__.’/../vendor/autoload.php’; — your namespaces are not loaded.

Or you forget to add a classmap to the composer, thus classes are not autoloaded and are not available. For example,

"autoload": < "psr-4": < "": "src/" >, "classmap": [ "dir/YourClass.php", ] >, "require": < "php": ">=5.3.9", "symfony/symfony": "2.8.*", 

First of all check if $ENGINE.»/classUser.php» is a valid name of existing file. Try this:

var_dump(file_exists($ENGINE."/classUser.php")); 

My fail might be useful to someone, so I thought I would post as I finally figured out what the issue was. I was autoloading classes like this:

define("PROJECT_PATH", __DIR__); // Autoload class definitions function my_autoload($class) < if(preg_match('/\A\w+\Z/', $class)) < include(PROJECT_PATH . '/classes/' . $class . '.class.php'); >> spl_autoload_register('my_autoload'); 

In my /classes folder I had 4 classes:

dbobject.class.php meeting.class.php session.class.php user.class.php 

When I later created a new class called:

I started getting the can’t load DbObject class . I simply could not figure out what was wrong. As soon as I deleted cscmeeting.class.php from the directory, it worked again.

I finally realized that it was looping through the directory alphabetically and prior to cscmeeting.class.php the first class that got loaded was cscmeeting.class.php since it started with D . But when I add the new class, which starts with C it would load that first and it extended the DbObject class. So it chocked every time.

I ended up naming my DbObject class to _dbobject.class.php and it always loads that first.

I realize my naming conventions are probably not great and that’s why I was having issues. But I’m new to OOP so doing my best.

Источник

PSR-4 autoloader Fatal error: Class not found

However if I try and create a new User() , I get the error Fatal error: Class ‘User’ not found in /var/www/public/api/v1/index.php on line 8 Looking at the composer autoload_psr4.php file it looks ok: // autoload_psr4.php @generated by Composer

$vendorDir = dirname(dirname(__FILE__)); $baseDir = dirname(dirname($vendorDir)); return array( 'XdgBaseDir\\' => array($vendorDir . '/dnoegel/php-xdg-base-dir/src'), 'Monolog\\' => array($vendorDir . '/monolog/monolog/src/Monolog'), 'KeenIO\\' => array($vendorDir . '/keen-io/keen-io/src'), 'Bix\\' => array($baseDir . '/src'), ); 

1 Answer 1

First of all, Linux (I’m not sure which PC you use) is case-sensitive. In your autoloading, you defined src/bix , while it is src/Bix .

But more importantly, with PSR-4, the specified namespace prefix is not included in the directory structure (to avoid directories containing just one directory). In your case, if you configure «Bix\\»: «src/» , a class Bix\Model\User should be located in src/Model/User.php .

EDIT: You’re misunderstanding PHP namespaces. In PHP, you’re not saying «import everything from Bix\Model into the global namespace for this file» with use Bix\Model; . Instead, it means: «Alias Model in this file to Bix\Model «.

require_once "vendor/autoload.php"; use Bix\Model; $user = new Model\User(); 
require_once "vendor/autoload.php"; use Bix\Model\User; $user = new User(); 

Источник

Class ‘User’ not found in Laravel

When I’m logging in a user. I don’t think there’s any problem in eloquent.php. Please take a look at my login controller:

class Login_Controller extends Base_Controller < public $restful = true; public function get_index()< return View::make('login'); >public function post_index() < $username = Input::get('username'); $password = Input::get('password'); $user_details = array('username' =>$username, 'password' => $password); if ( Auth::attempt($user_details) ) < return Redirect::to('home.index'); >else < return Redirect::to('login') ->with('login_errors', true); > > > 

I used Eloquent as my authentication driver. I’ve tried changing it to Fluent, but after I click login button, it displays a login error made by this line return Redirect::to(‘login’)->with(‘login_errors’, true); in the else statement. What’s wrong with ‘User’ class when using Eloquent?

2 Answers 2

Mike’s right, this is because you’ve got no User model but there’s more .

The line where laravel’s searching for the user model and not finding it is the following:

if ( Auth::attempt($user_details) ) 

This happens because Laravels authentification system uses per default the eloquent driver. To satisfy Laravel you need a database table named ‘users’ with at least the columns ‘username’ and ‘password’ of type text and maybe also the columns ‘created_at’ and ‘updated_at’ when using timestamps but you can switch it off.

This is actually a comment to @Hexodus response, but I don’t have the required points to comment.

You can actually have your User authentication named whatever you want, for instance

But you have to go into app\config\auth.php and change the ‘model’ => ‘. ‘ and ‘table’ => ‘. ‘ values in order for Laravel’s authentication to work.

Also, according to the docs, you don’t even need ‘username’ or ‘password’ explicitly defined as such in your database

if (Auth::attempt(array('email' => $email, 'password' => $password)))

Take note that ’email’ is not a required option, it is merely used for example. You should use whatever column name corresponds to a «username» in your database. The Redirect::intended function will redirect the user to the URL they were trying to access before being caught by the authentication filter. A fallback URI may be given to this method in case the intended destination is not available.

Effectively, ’email’ in this instance is considered a ‘username’

Edit, and because I was having trouble with this at first, you do not need to hash passwords when you use Auth::attempt(. ) .

Источник

PHP class not found [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.

This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.

I solved this question my own. The filename was wrong lolz. Hello everyone! I’m building a CMS like Drupal and Joomla. I’m working on the module feature (plugins), and I got the following error:

Fatal error: Class 'settings' not found in C:\wamp\www\SYSTEM\view.php on line 22 
 //Check if the user wants shit from a module if(isset($_GET["m"]))//Yes the user want it < //Does the module exist and activated, and has it a function called view? if(isset($module_exists[$_GET["m"]]) && method_exists($_GET["m"], "view"))//Yep < //Load view (should be an array) eval("\$module_view = ".$_GET["m"]."::view();"); if(!is_array($module_view))//Not an array :( < error::e500module($_GET["m"], $_SERVER["REQUEST_URI"]); >else//The error would kill the entire script, m'kay < view::index(); >> else//Nope, so display error < error::e404($_SERVER['REQUEST_URI']); >> 
 function foot() < include("../THEMES/".settings::get("theme")."/foot.php"); >function left() < include("../THEMES/".settings::get("theme")."/left.php"); >function right() < include("../THEMES/".settings::get("theme")."/right.php"); >function index() < include("../THEMES/".settings::get("theme")."/index.php"); >> 

Start.php is obviously executed first. Not other pages are executed before it, except customsettings.php that contains database information. If I used $_SERVER[«db_prefix»] in my code above, it’s because I needed a superglobal which is set in customsettings.php: customsettings.php

Can anybody help me? It seems that view.php’s index function is called before settings.php is included. Sorry if this question is huge, I just want to be clear. Also don’t say eval() is evil, I know. So I want to know why the settings class could not be found. If you need more source code, please comment to this question.

Источник

Читайте также:  Php array количество элементов
Оцените статью