L
L
LittleFatNinja2015-08-30 00:29:55
PHP
LittleFatNinja, 2015-08-30 00:29:55

What am I doing wrong that does not find the class through namespace in php?

I declare a class with a namespace

namespace app\models;

class User extends Model {
      foo() { }
}

in another file I try to connect
<?php

use app\models\User;

class ControllerComments extends Controller {
      User::foo();
}

Class 'app\models\User' not found
what am I doing wrong?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Defman21, 2015-08-30
@LittleFatNinja

Do you have autoload configured at least?
Also, your whole code is wrong.

namespace app\models;

class User extends Model {
      public static function foo() { echo "I've called by a controller!"; }
}

use \app\models\User;

class ControllerComments extends Controller {
      public function __construct() { User::foo(); }
}
$test = new ControllerComments();

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question