-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
model instances inside Proxy are not cached #4199
Comments
In the Override Engine we faced the same problem and decided to replace it with decorators: Each model class instantiation is wrapped up by a decorator class which has the needed methods for the before and after event triggers. Much easier to use IMHO. E.g. something like this: system/engine/decorator.php:
system/library/model_decorator.php:
|
I am facing with this issue as well. It makes impossible to use models as actually models, but not just a library of functions. It has never been possible to pass parameters to model constructor via the load->model() method. Now any custom model setter doesn't work either.
and now we want to use the model in some controller:
The getParam() method will return "2" despite that we have just set the "param" property to "3" |
@igorokb: Try using our system/engine/decorator.php Modify the system/engine/loader.php, replacing the lines
with something like this:
Personally, I find Daniel's way of using a proxy with the callback methods a bit cumbersome to read its code, I find using the decorator design pattern for this more natural. |
I agree, the decorator pattern fits perfectly in this scenario. |
Thanks @mhcwebdesign,
It is not the best practice to instantiate an object and abandon it though (I am referring to the one which is created inside load->model()). However the solution should be compatible with OC1.5 and OC 2 including the latest version. However by adding a comment here my goal was not to get a solution for my particular case but attract the attention to this issue, since there are lots of extensions, which now have to be adjusted in sake of compatibility with 2.2.0.0 |
I am closing the issue since the proxy is now cached in the registry container as the model service and the model instances are cached in a static var inside the callback method. |
I have an issue on this Undefined property: Proxy::getConfigArray So after I tried to upload a AMP module ( actually it was just 2 folders ) to opencart version 2.2.0.0 I got the errors I will list below. I then deleted the files to try and clear the error, but ended up still having them and now I can not login to admin, nor can I see my site. Here are the error codes that I am getting. ( also I am new to this so please explain like you would to a child ) at my sites homepage I get this
In error files I get these
Here is what the files are/say that first location
Here is #0
Here is #1
Here is #4
Here is #5
lastly here is #6
I am having a hard time finding a fix for my specific issue. Any help would be very much appreciated. |
With the new Proxy implementation of model method calls, we end up having a new model instance
for every proxy method call.
the code above lies inside the anonymous function which is the one called in the proxy model objects.
You can add a static var counter to verify that new is called multiple times for the same $class.
In my opinion model instances should be cached and shared as it was before, maybe using a new different (something like
proxy_model_{route}
) registry key.Also, model $file is already checked included in loader::model() method and the classname
$class
is already resolved: there is no need to check and include the file again (thus generating redundant filesystem stat calls) and $class could be passed as a 3rd argument into loader::callback().kind regards
The text was updated successfully, but these errors were encountered: