You should avoid such a tight coupling between your model and a specific controller/action. Your model’s reusability will be very limited otherwhise. So better put such restriction into the controller.
But if i want to call some function before save for create and not for update action then what shud i do.
bcoz i am going to add some more validations features like ‘invalid characters etc’ for checking the username in the utils file. but this is not required for update action.
Checks like these should also go into rules() as they belong to the business rules of your model. Use scenarios for the insert/update issue (read this). There are two scenarios predefined: insert and update. So you can just use a rule like this: