{"action":"created","issue":{"url":"https://api.github.com/repos/laruence/php-yaf/issues/155","labels_url":"https://api.github.com/repos/laruence/php-yaf/issues/155/labels{/name}","comments_url":"https://api.github.com/repos/laruence/php-yaf/issues/155/comments","events_url":"https://api.github.com/repos/laruence/php-yaf/issues/155/events","html_url":"https://github.com/laruence/php-yaf/issues/155","id":60091061,"number":155,"title":"Call class/models from module in libray","user":{"login":"famonsei","id":2834269,"avatar_url":"https://avatars.githubusercontent.com/u/2834269?v=3","gravatar_id":"","url":"https://api.github.com/users/famonsei","html_url":"https://github.com/famonsei","followers_url":"https://api.github.com/users/famonsei/followers","following_url":"https://api.github.com/users/famonsei/following{/other_user}","gists_url":"https://api.github.com/users/famonsei/gists{/gist_id}","starred_url":"https://api.github.com/users/famonsei/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/famonsei/subscriptions","organizations_url":"https://api.github.com/users/famonsei/orgs","repos_url":"https://api.github.com/users/famonsei/repos","events_url":"https://api.github.com/users/famonsei/events{/privacy}","received_events_url":"https://api.github.com/users/famonsei/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":5,"created_at":"2015-03-06T11:33:31Z","updated_at":"2015-03-30T07:35:01Z","closed_at":"2015-03-30T07:35:01Z","body":"Hey,\r\n\r\nAnd thanks for your job.\r\n\r\nI want to use the \"modules\" concept and I need to call a *classModel* into another class locate in library repository but it doesn't works.\r\n\r\nAny solution to register and autoload maybe like this :\r\n ```\r\npublic function _initLoader(Yaf\\Dispatcher $dispatcher)\r\n    {\r\n    \t$loader = Yaf\\Loader::getInstance();\r\n    \t$loader->autoload('../modules/Paybag/models/Webapp');\r\n    }\r\n```\r\nresult :\r\n```\r\nPHP Warning:  Yaf\\\\Loader::autoload(): Failed opening script /var/www/api/models/Webapp.php: No such file or directory in /var/www/api/vendor/SORM/SORM.php\r\n```\r\nmy application.ini\r\n```\r\n[yaf]\r\napplication.ext         = 'php'\r\napplication.view.ext    = 'phtml'\r\napplication.modules\t\t= 'Default,Evaluation,Paybag'\r\napplication.directory       = APP_PATH\r\napplication.bootstrap       = APP_PATH'/Bootstrap.php'\r\napplication.library         = APP_PATH'/vendor'\r\napplication.dispatcher.defaultRoute     = ''\r\napplication.dispatcher.throwException   = 0\r\napplication.dispatcher.catchException   = 0\r\napplication.dispatcher.defaultModule        = 'Default'\r\napplication.dispatcher.defaultController    = 'Default'\r\napplication.dispatcher.defaultAction        = 'Index'\r\n```\r\nOne more thing, module name is obliged to have the first letter capitalized ?\r\n\r\nThanks for any reponses and sorry for my bad english."},"comment":{"url":"https://api.github.com/repos/laruence/php-yaf/issues/comments/87579977","html_url":"https://github.com/laruence/php-yaf/issues/155#issuecomment-87579977","issue_url":"https://api.github.com/repos/laruence/php-yaf/issues/155","id":87579977,"user":{"login":"famonsei","id":2834269,"avatar_url":"https://avatars.githubusercontent.com/u/2834269?v=3","gravatar_id":"","url":"https://api.github.com/users/famonsei","html_url":"https://github.com/famonsei","followers_url":"https://api.github.com/users/famonsei/followers","following_url":"https://api.github.com/users/famonsei/following{/other_user}","gists_url":"https://api.github.com/users/famonsei/gists{/gist_id}","starred_url":"https://api.github.com/users/famonsei/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/famonsei/subscriptions","organizations_url":"https://api.github.com/users/famonsei/orgs","repos_url":"https://api.github.com/users/famonsei/repos","events_url":"https://api.github.com/users/famonsei/events{/privacy}","received_events_url":"https://api.github.com/users/famonsei/received_events","type":"User","site_admin":false},"created_at":"2015-03-30T07:35:01Z","updated_at":"2015-03-30T07:35:01Z","body":"Hi,\r\nMeanwhile I found another solution.\r\nMy *SORM* class/vendor allows to make multiconnexions, so a database by module.\r\nEach model of a module is an extend of *Host* root model for remember the source. The source is stored in the construct.\r\n```\r\nfunction __construct($host = NULL)\r\n{\r\n    $this->setHostFrom(\r\n        !empty($host) ? \r\n        strtolower($host) : \r\n        strtolower(\\Yaf\\Dispatcher::getInstance()->getRequest()->getModuleName())\r\n    );\r\n}\r\n```\r\nAnd I make my call like this :\r\n```\r\n// call entity from module Module1\r\n$order = SORM::getOne('Module1/Order', 38);\r\n// call entity from module Module2\r\n$order = SORM::getOne('Module2/Order', 37);\r\n// call entity form module where wse are\r\n$order = SORM::getOne('Order', 36);\r\n```\r\n\r\nThen I added the loading modules in Bootstrap like this :\r\n```\r\npublic function _initModule(Yaf\\Dispatcher $dispatcher)\r\n    {\r\n        //load script for each  module\r\n        $app = $dispatcher->getApplication();\r\n        $modules = $app->getModules();\r\n        foreach ($modules as $module)\r\n        {\r\n            // index modules located on root folder and already load\r\n            if ('index' == strtolower($module)) continue;\r\n\r\n            //import class from all modules\r\n            $pathModule = $app->getAppDirectory() . '/modules/' . $module . '/models';\r\n            $models = scandir($pathModule);\r\n            foreach ($models as $model)\r\n            {\r\n                //load only class PHP (except '.', '..', etc)\r\n                if (strstr($model, '.php'))\r\n                    Yaf\\Loader::import($pathModule . '/' . $model);\r\n            }\r\n        }\r\n    }\r\n```\r\nIf it helps you a little ...\r\n\r\nOtherwise move your api in library if it becomes too \"common\" as use."}}