{"action":"created","issue":{"url":"https://api.github.com/repos/opencart/opencart/issues/6387","repository_url":"https://api.github.com/repos/opencart/opencart","labels_url":"https://api.github.com/repos/opencart/opencart/issues/6387/labels{/name}","comments_url":"https://api.github.com/repos/opencart/opencart/issues/6387/comments","events_url":"https://api.github.com/repos/opencart/opencart/issues/6387/events","html_url":"https://github.com/opencart/opencart/issues/6387","id":294306526,"number":6387,"title":"Multiply model creation (opencart 2.3, 3.x)","user":{"login":"butsds","id":17113736,"avatar_url":"https://avatars2.githubusercontent.com/u/17113736?v=4","gravatar_id":"","url":"https://api.github.com/users/butsds","html_url":"https://github.com/butsds","followers_url":"https://api.github.com/users/butsds/followers","following_url":"https://api.github.com/users/butsds/following{/other_user}","gists_url":"https://api.github.com/users/butsds/gists{/gist_id}","starred_url":"https://api.github.com/users/butsds/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/butsds/subscriptions","organizations_url":"https://api.github.com/users/butsds/orgs","repos_url":"https://api.github.com/users/butsds/repos","events_url":"https://api.github.com/users/butsds/events{/privacy}","received_events_url":"https://api.github.com/users/butsds/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":4,"created_at":"2018-02-05T08:19:46Z","updated_at":"2018-02-06T07:21:08Z","closed_at":null,"author_association":"NONE","body":"Forexample:\r\n\r\nmodel\r\nclass ModelCatalogTest extends Model {\r\n    public function __construct($registry) {\r\n        parent::__construct($registry);\r\n        echo \"instance created <br>\";\r\n    }\r\n    \r\n    public function test1() {}\r\n    public function test2() {}\r\n    public function test3() {}\r\n}\r\ncontroller\r\nclass ControllerCommonTest extends Controller {\r\n    \r\n    public function index() {\r\n        $this->load->model('catalog/test');\r\n        \r\n        $this->model_catalog_test->test1();\r\n        $this->model_catalog_test->test2();\r\n        $this->model_catalog_test->test3();\r\n    }\r\n}\r\noutput:\r\ninstance created\r\ninstance created\r\ninstance created\r\n\r\nproblem code system/engine/loader.php in callback method\r\n\r\nsolution:\r\nprotected function callback($registry, $route) {\r\n\t\treturn function($args) use($registry, &$route) {\r\n\t\t\t//-static $model = array(); \t\t\t\r\n\t\t\t\r\n\t\t\t$output = null;\r\n\t\t\t\r\n\t\t\t// Trigger the pre events\r\n\t\t\t$result = $registry->get('event')->trigger('model/' . $route . '/before', array(&$route, &$args, &$output));\r\n\t\t\t\r\n\t\t\tif ($result) {\r\n\t\t\t\treturn $result;\r\n\t\t\t}\r\n\t\t\t\r\n            $model_route = substr($route, 0, strrpos($route, '/'));\r\n            \r\n\t\t\t// Store the model object\r\n\t\t\t//-if (!isset($model[$route])) {\r\n\t\t\tif (!$registry->get($model_route)) {\r\n                \r\n\t\t\t\t$file = DIR_APPLICATION . 'model/' .  $model_route . '.php';\r\n\t\t\t\t$class = 'Model' . preg_replace('/[^a-zA-Z0-9]/', '', $model_route);\r\n\r\n\t\t\t\tif (is_file($file)) {\r\n\t\t\t\t\tinclude_once($file);\r\n                    \r\n\t\t\t\t\t//-$model[$route] = new $class($registry);\r\n                    $registry->set($model_route, new $class($registry));\r\n                \r\n\t\t\t\t} else {\r\n\t\t\t\t\tthrow new \\Exception('Error: Could not load model ' . $model_route . '!');\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\t$method = substr($route, strrpos($route, '/') + 1);\r\n\t\t\t\r\n\t\t\t//-$callable = array($model[$route], $method);\r\n\t\t\t$callable = array($registry->get($model_route), $method);\r\n\r\n\t\t\tif (is_callable($callable)) {\r\n\t\t\t\t$output = call_user_func_array($callable, $args);\r\n\t\t\t} else {\r\n\t\t\t\tthrow new \\Exception('Error: Could not call model/' . $route . '!');\r\n\t\t\t}\r\n\t\t\t\r\n\t\t\t// Trigger the post events\r\n\t\t\t$result = $registry->get('event')->trigger('model/' . $route . '/after', array(&$route, &$args, &$output));\r\n\t\t\t\r\n\t\t\tif ($result) {\r\n\t\t\t\treturn $result;\r\n\t\t\t}\r\n\t\t\t\t\t\t\r\n\t\t\treturn $output;\r\n\t\t};\r\n\t}"},"comment":{"url":"https://api.github.com/repos/opencart/opencart/issues/comments/363333101","html_url":"https://github.com/opencart/opencart/issues/6387#issuecomment-363333101","issue_url":"https://api.github.com/repos/opencart/opencart/issues/6387","id":363333101,"user":{"login":"butsds","id":17113736,"avatar_url":"https://avatars2.githubusercontent.com/u/17113736?v=4","gravatar_id":"","url":"https://api.github.com/users/butsds","html_url":"https://github.com/butsds","followers_url":"https://api.github.com/users/butsds/followers","following_url":"https://api.github.com/users/butsds/following{/other_user}","gists_url":"https://api.github.com/users/butsds/gists{/gist_id}","starred_url":"https://api.github.com/users/butsds/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/butsds/subscriptions","organizations_url":"https://api.github.com/users/butsds/orgs","repos_url":"https://api.github.com/users/butsds/repos","events_url":"https://api.github.com/users/butsds/events{/privacy}","received_events_url":"https://api.github.com/users/butsds/received_events","type":"User","site_admin":false},"created_at":"2018-02-06T07:21:08Z","updated_at":"2018-02-06T07:21:08Z","author_association":"NONE","body":"Please, test it http://sandbox.onlinephpfunctions.com/code/209f76d609631a6ce9a5738bec9e08f2f9025666 . Static variable in closure is senselessly."}}
{"actor":{"display_login":"butsds"}}