xsanisty / SlimBoard

Starter Application built on Slim Framework in MVC (and HMVC) environment
http://www.xsanisty.com/project/slim-starter
MIT License
287 stars 72 forks source link

Folder structure #14

Closed rajneeshojha closed 9 years ago

rajneeshojha commented 9 years ago

How to setup the framework structure like every module reside in separate folder so suppose i develop a module to extend my application i just drop that folder somewhere with view, controller,model folders in it and it start working ,no need to put views,model,controller in app folders separately

ikhsan017 commented 9 years ago

Yes, you can drop the whole structure into modules dir, but still find best way to provide this feature

rajneeshojha commented 9 years ago

i can only see views,controllers folder inside each module in module folder no models folder , models folder is only available inside app folder, so if i write a module and put it inside module folder and now if i want to use model do i need to put it inside app/models or inside my module folder's model folder

rajneeshojha commented 9 years ago

i think currently script does not load available models inside modules model folder i modified Manager.php to fix this issue i added this is /src/SlimStarter/Module/Manager.php after line no 55 and now models are loading fine,Please tell me if i am doing it wrong or there is some better way to achieve this

foreach (glob(APPPATH.'modules/') as $module) { $module = APPPATH.'modules/'.basename($module) ."/models"; foreach (glob($module .'/.php') as $model) { include_once($model); }

         }
ikhsan017 commented 9 years ago

@rajneeshojha , no need to register model manually, just put it in the proper namespace inside the module dir, and it will be autoloaded

say you have Admin module, the directory structure will be like

modules
|---Admin
|   |---Controller
|   |---Model
|   |   |---SomeModel.php

then you can use it inside your controller

Admin\Model\SomeModel.php

<?php

namespace Admin\Model;

use Model;

class SomeModel extends Model{}

Controller


<?php

namespace Admin\Controller;

use Admin\Model\SomeModel;
...
public function someMethod(){
    $someModel = SomeModel::find(1);
}
...
rajneeshojha commented 9 years ago

great thank , It works perfectly