CONTROLLERS, single method or different methods for different actions? |
(05-11-2016, 02:55 PM)PaulD Wrote: As for the colour removal, I would do the customer form as a normal form, but deleting and adding colours as a javascript function, so when the user deletes a colour it just pops off the screen (with a 'saving changes' pause in the middle - I always love using those animated loading gifs), without the user having to refresh the page for such a minor thing. Thanks, I have gone with the "quality" experience where colours can be assigned to a customer (or removed from a customer) using JavaScript / Ajax (colours are a many to one relationship). It works fine and is less clicks and less screens for the user to contend with, but what I am still unsure about is whether to route this to a different method to the one used to change the normal customer details (such as name and email address), or to a master method which then figures out whether the user is trying to change the customers email address, or whether they're trying to add or remove colours. (05-11-2016, 01:08 PM)cartalot Wrote:Quote:But if I had separate forms all going to the same controller, using a hidden task field, had I might as well not just have separate forms routing to separate controller methods? OK point taken, this makes sense. I did it this way initially and ended up with a big fat controller. Then I modified it slightly so it was a main controller, and I created several private sub controllers. Then I changed it again into separate public controllers, and pointed the different forms on the page to the relevant controllers (basically the opposite to what you're saying above). Now I'm inclined to go with what you're saying and change it back again! At some stage I'm going to have to get on with actually building the system, but I am going round in circles at the moment trying to get a feel for what is most appropriate way of doing things.
i think its good to keep trying different things. one suggestion is to push as much as possible to your models. basically the controller just asks if the form validated or did a result come back from the database search - and then chooses the appropriate view based on what happened. that keeps your controller as 'thin' as possible, and the ever changing granular details like field names are in the models.
(05-11-2016, 02:31 PM)cartalot Wrote:(05-10-2016, 03:28 PM)Narf Wrote: But we're in the PHP7 era now and "private" has a specific meaning. Also, making controller methods really private by using the keyword works just fine - you don't need to prefix those with an underscore and they still won't be routable. It may still be present in some conventions, CI too denotes non-public methods that way for easier readability. What I was explaining is that you don't actually need to use it and that he term "private" means a different thing. ![]() (05-12-2016, 01:02 AM)Narf Wrote: It may still be present in some conventions, CI too denotes non-public methods that way for easier readability. well then what does 'private' mean? i am referring specifically to what is in the codeigniter 3 manual for how to prevent methods in a controller from being publicly available. is there something else that bears on this and if yes please explain or link to a source so we can understand what you are referring to. https://codeigniter.com/user_guide/gener...te-methods (05-12-2016, 11:01 AM)cartalot Wrote:(05-12-2016, 01:02 AM)Narf Wrote: It may still be present in some conventions, CI too denotes non-public methods that way for easier readability. It is private because the "private" keyword is used, not because of the underscore. (05-12-2016, 03:52 PM)CINewb Wrote:(05-12-2016, 11:25 AM)Narf Wrote: It is private because the "private" keyword is used, not because of the underscore. Yes, as I explained - you can do that, but it's a legacy feature and "inaccessible" != "private". |
Welcome Guest, Not a member yet? Register Sign In |