smile 22121
smile 22121

Reputation: 295

Slim framework can't create a class

I have small issue in create a result class where I want to save all error messages in my app Here is my files tree :

enter image description here

Here is my simple Result class:

class Result {
    public $errors;
    public $data;

    public function __construct($errors = array(), $data = null) {
        $this->errors = $errors;
        $this->data = $data;
    }
}

And here is my Home Controller function:

namespace MyApp\Controller;
require_once 'lib/result.php';
class Home extends \SlimController\SlimController
{
    public function dataAction()
    {
        $result = new Result;
    }
}

I get error in my PHP built-in server :PHP Fatal error: Class 'MyApp\Controller\Result' not found

Upvotes: 1

Views: 608

Answers (1)

jmattheis
jmattheis

Reputation: 11135

You are trying to get the Result class in the current namespace you could do

$result = new \Result();

or with

use Result;

after the namespace

Upvotes: 2

Related Questions