# Loading classes with namespaces in CakePHP 2.0

**URL:** <https://discourse.cakephp.org/t/loading-classes-with-namespaces-in-cakephp-2-0/3276>\
**Category:** Need Help\
**Created:** [September 27, 2017, 12:07am UTC](https://discourse.cakephp.org/t/loading-classes-with-namespaces-in-cakephp-2-0/3276 "2017-09-27T00:07:00Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![pdatartech](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/pdatartech/32/822_2.png) [@pdatartech](https://discourse.cakephp.org/u/pdatartech)\
**Post date:** [September 27, 2017, 12:07am UTC](https://discourse.cakephp.org/t/loading-classes-with-namespaces-in-cakephp-2-0/3276/1 "2017-09-27T00:07:00Z")

</div>

I have the following folder structure

```
Controller
    - MainController.php
Model
    - FolderA
        - FolderAA
            - ModelA.php
        - FolderAB
            - ModelA.php

```

And the FolderA/FolderAA/ModelA.php file is the following -

```
<?php

    namespace Model\FolderA\FolderAA;

    class ModelA extends \AppModel{

    public $useTable = false;

    public function test(){

        $return_data['success'] = $this->success;
        $return_data['message'] = $this->message;

        return $return_data;

    }

}

```

And the FolderA/FolderAB/ModelA.php file is the following -

```
<?php

    namespace Model\FolderA\FolderAB;

    class ModelA extends \AppModel{

    public $useTable = false;

    public function test(){

        $return_data['success'] = $this->success;
        $return_data['message'] = $this->message;

        return $return_data;

    }

}

```

And in the MainController.php file, I’m trying to do the following -

```
try{

    $ModelA = new \Model\FolderA\FolderAA\ModelA();

    $result = $ModelA->test();

    if($result['success'] !== true){
        $this->set_request_status(false, $result['message']);
    }

}catch(Exception $e){

    $e->getMessage();
    exit();

}

```

I’m getting the following error fatal error -

`Error: Class 'Model\FolderA\FolderAA\ModelA' not found`

What am I doing wrong?

This is an attempt to organise my code into folders so that it becomes easier to maintain. I can make the name of the actual ModelFile - FolderAFolderAAModelAA.php and put that into the Model folder, but I’ll have many such folders and sub folders that having all of them in a single folder level will be very hard to manage. I did read that CakePHP 2.0 allows you to organise model files into folders - [http://cakebaker.42dh.com/2007/11/22/organizing-your-code-with-folders/](http://cakebaker.42dh.com/2007/11/22/organizing-your-code-with-folders/)

Thank you in advance for your time and assistance.

Regards,

Prathamesh.
