When executing $model->unsetAttributes() I get an error

Fatal error: Call to undefined method MyModule :: unsetAttributes ()

Tell me how to fix it?

  • four
    This is the answer to what question? - Visman
  • The author, apparently, just wanted to share a useful observation :) - Dmitry Novikov
  • four
    I vote for closing this question as not relevant, because it is not a question at all. - Vladimir Glinskikh
  • All this is of course great, but without a description of the MyModule class it is MyModule say anything concrete. - Dmitriy Simushev

2 answers 2

This error indicates that your variable is not a model, but an instance of the class MyModule that does not have an unsetAttributes() method.

First, you need to fix the creation of the model, and secondly, you need to add a check, so as not to frighten ordinary users:

 if(method_exists($model, 'unsetAttributes')){ // action } 

    The answer is from the question itself.


    Most likely, the model with the same name is already somewhere initialized. Because most often initialize models and components like this:

     $this->setImport(array( 'mymodules.models.*', )); 

    it is possible where the machine hooked.