0

Sorry if this has been asked I've been searching documentation and stack overflow and can't find it being solved.

Here is my scenario. I have a model for a league, this model has many teams, each team has many team_members.

I have a view that is displaying a selection list of leagues and I want to disable the selection of leagues that the current logged in user is already registered for. I need a quick way in a view while iterating through leagues and displaying UI related to the league to determine if this leagues selection should be disabled. What I need is a simple way to query the Leagues object and provide a user_id to have it give me a true false response. Basically a model based helper function to help me determine what UI I should present.

I've been pouring over the documentation and trying to figure out where my simple method needs to reside which will just query all team_members with a user_id and the desired league_id.

  • Doesn't seem to go in Helpers because I can't figure out how a view helper would access a model Table object.
  • Doesn't seem to go in the models entity object because I don't have access to the model to perform a find() on the table object from a method in my entity class.
  • I don't want this to go into the controller and have to build some sort of array I reference and set for the view to have available.
  • It doesn't seem right to make a behavior. Why do I need a whole class for one method that is for a specific model and not to be re-used for multiple.

Am I missing something big or is this partially by design to keep code in proper places and for me specifically not to do what I want to do?

It seems to me there should be a simple way to create custom model logic but I can't figure out where I should be doing it.

Hazmit
  • 165
  • 6
  • Maybe put the function in whatever class you're using for the Identity, and pass the league to that, instead of having a league-centric function that you pass a user to? That function might even do a more generic lookup of all the user's leagues and cache it in the Identity object, so as to very quickly answer any further league questions, instead of needing a query for each league. – Greg Schmidt Aug 28 '23 at 23:32
  • 1. Authorize user in controller using AuthComponent. 2. From controller pass id of user to table finder and get variable as array. 3. Pass variable from controller to view. View layer should not be able to execute any database related methods. Thats standard flow for cakephp and generally mvc in php. – Dariusz Majchrzak Aug 29 '23 at 22:05

0 Answers0