1

Is this a problem / bad practice:
I have the same method names in both Model and Controller. For example:

In the Director Model:
function approve($company_id, $director_id){....}

In the DirectorsController:
function approve($id = null){...}

The reason to have these are for clarity (I know it looks confusing instead, but for this particular application, this makes it much clearer.)

Currently it is working, but I am not sure if this is fine.

Thank you for any input.

3
  • It's easy to mix up $this->Model->method() and $this->method() by mistake, but it shouldn't pose any technical problems. Commented Aug 26, 2011 at 20:34
  • Hello Juhana, thank you for your reply. Are there any naming conventions I can use in this case so that the next developer will have an easier time understanding my code. (I have a lot of comment, but still). The job both approve() methods do are the same. Commented Aug 27, 2011 at 2:34
  • Bear in mind, that while this is fine - if you have the same function names in a controller/component or model/behavior - it will present a problem. Commented Feb 1, 2012 at 16:36

1 Answer 1

2

If you understand how OOP works you'd know this would pose no problem, since one method is called in the model and the other in the controller which are separate objects.

If you do $this->approve() in your controller it would be different than doing $this->Model->approve() in the controller. You should be fine

Sign up to request clarification or add additional context in comments.

2 Comments

Hello 8vius, thank you for your reply. It is working, no problems. But is this a bad practice? I mean my concern is that if I get hit by a bus tomorrow and there is another CakePHP developer who is trying to understand my code, will this naming be a challenge? Sorry for the unclear question earlier. Or is there a better naming convention.
No, not at all, it is a one of the advantages of OOP, might as well make use of it :)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.