Re: Class, filename and naming conventions
I think for admin functionality and consistency with the general thrust of cakePHP you should consider the admin model that is implicit in CakePHP itself. (check the manual, under configuration or controller.) Your Admin_method() code can even choose a specific layout and view by changing its own properties on the fly to those appropriate for administration. (for instance, I embed breadcrumbing as a set variable that is a nested array of labels and links that I run through a $html-link loop; the admin functions start with '/admin/ home' = 'Admin', where the non-admin breadcrumb starts with '/' = 'Home'. I would suggest instead of multiple model classes you create a single model class that forks when necessary depending on an admin flag in session. I guarantee that though the code is fresh in mind now and seems like an irrefutably great idea, six months ago when bugs occur you'll be making two stops for every bug and cursing yourself for ever having split your code base unnecessarily. I would also point out that if you are going to continue this route, instead of messing with the views, you could simply alter the data arrays in the methods that receive and CRUD the data. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Cake PHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: Class, filename and naming conventions
Yeah, correct ideas guys, thanks for the feedback. The intention though of the discussion is in review of the purpose of the naming conventions so as to obtain clarity and maybe shared thought on the current consistency of the classes and names. I moved away from this scenary a while ago, I am not saying that I would do this in practice. 1 model is still the better way forward. Thick models and thin controllers and views... definitely something that I have started to implement and move to over the last month. It is without a doubt VERY good practice. What are your thoughts though on the naming conventions and the last aspects of my previous reply? ie. *** I agree with what you are saying about writing less. If this is the case then, perhaps the controller filename would be better being the same as the helpers, components etc. filename = users.php; class = UsersController. Then the same theory should perhaps apply to the models to maintain consistency... filename = user.php; class = UserModel. Overall this would be adopting better conformity to the conventions across the files and class names. *** --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Cake PHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Class, filename and naming conventions
Hi Guys, I've got a question, and hopefully one of the cakephp guys can give an answer. First, the scenario... I often will used more than one model file to represent the same data. A common reason is to separate admin functions from normal ones, so the normal model is less intensive to load. There may be other reasons like two different data sources, but the same data model. Now although this does not seem a problem at first, it becomes a problem when you start creating forms to represent and manage that data. In all these models, the $name variable is set the same (e.g. User), so I have transparency between the models (and the models may be named: UserModel1, UserModel2 etc). However, when we populate a form with the model data using the FormHelper, it requires the following name: ModelClass.field (1.2) or ModelClass/field (1.1). Now naturally this causes a problem when the models have different class names (This may be so that we can store all the models in the same directory or even load more than one of them at the same time.) Now my only argument or frustration is why does the FormHelper use the Classname as part of the naming of the input field rather than the $name variable of the class? I have no problem in it needing the class name to initiate and retrieve the input name value, but I think that it would be best that the resulting name was: data[ModelNameVariable] [field]. What are your thoughts? Then, the second part of the conventions is why are controller class files named differently to all the other files like models, helpers, components etc? Surely to remain consistent, one should keep the naming convention the same all across? My personal preference would be that they are all named according to their class name, so much like the current controllers are. I understand the impact this would have, but I think that this would help keep a stronger convention on the naming of the files. A third case to look at is if a component and a model share the same $name variable value or Similar class names (Component: User user_component; Model: User user). This causes a problem. To get around that I named all my components iClassComponent. However, I would think that the best way really to solve this would be to name the objects according to their class names, ie: Models would be UserModel and Components would be UserComponent. This also allows for better usability as you thereby know automatically the type of object it is. What are your thoughts? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Cake PHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: Class, filename and naming conventions
Ok, it seems the problem with the model names and the form element names is not as I previously experienced in 1.1, my guess is that I was probably doing something wrong. hahahaha! Anyway, my questions still remain with regards to the naming conventions. :D --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Cake PHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: Class, filename and naming conventions
On Dec 20, 10:37 am, lordG [EMAIL PROTECTED] wrote: Hi Guys, I've got a question, and hopefully one of the cakephp guys can give an answer. First, the scenario... I often will used more than one model file to represent the same data. A common reason is to separate admin functions from normal ones, so the normal model is less intensive to load. There may be other reasons like two different data sources, but the same data model. Now although this does not seem a problem at first, it becomes a problem when you start creating forms to represent and manage that data. In all these models, the $name variable is set the same (e.g. User), so I have transparency between the models (and the models may be named: UserModel1, UserModel2 etc). However, when we populate a form with the model data using the FormHelper, it requires the following name: ModelClass.field (1.2) or ModelClass/field (1.1). Now naturally this causes a problem when the models have different class names (This may be so that we can store all the models in the same directory or even load more than one of them at the same time.) The above sounds rather over complex to me. What is the benefit of making several 'models' for one model? (The fact that I ask should imply that I don't percieve any of the above reasons as a benefit). Now my only argument or frustration is why does the FormHelper use the Classname as part of the naming of the input field rather than the $name variable of the class? Why is the $name not the same as the class name. That´s begging for things not to work IMO. 1.2 uses the alias afaik btw, which defaults to the model name. I have no problem in it needing the class name to initiate and retrieve the input name value, but I think that it would be best that the resulting name was: data[ModelNameVariable] [field]. What are your thoughts? Then, the second part of the conventions is why are controller class files named differently to all the other files like models, helpers, components etc? You are refering to plural or _controller? I can´t remember the specifics but when the _controller was dropped there were naming conflicts. Surely to remain consistent, one should keep the naming convention the same all across? My personal preference would be that they are all named according to their class name, so much like the current controllers are. I understand the impact this would have, but I think that this would help keep a stronger convention on the naming of the files. If anything were to change I prefer writing less :). A third case to look at is if a component and a model share the same $name variable value or Similar class names (Component: User user_component; Model: User user). This causes a problem. To get around that I named all my components iClassComponent. However, I would think that the best way really to solve this would be to name the objects according to their class names, ie: Models would be UserModel and Components would be UserComponent. This also allows for better usability as you thereby know automatically the type of object it is. What are your thoughts? Component Model name conflicts are indeed a problem. Although I don't think writing Component and Model after each of them is necessarily that good an idea. For chained model calls that makes them quite long, and writing $this-SessionComponent-write(); would probable get tiring rather quickly. only IMO of course, AD --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Cake PHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: Class, filename and naming conventions
I've also run into a few conflicts when naming models and helpers... eg. i had a model image and an imagehelper, when baking the view page it generate $this-set('image', $image); which would obviously conflict with my helper. I ended up naming my helper MagicImage instead :) However it would be great if we could avoid this situation. One solution is to wait until we have namespaces (or modules, as I think they may be referred to) in PHP6. Another idea I had (maybe not feasible) is to add an alias for loaded classes var $uses = array('Image' = 'ImageModel'); var $helpers = array('Image' = 'ImageHelper'); or var $uses = array('Image' = array('alias' = 'ImageModel')); var $helpers = array('Image' = array('alias' = 'ImageHelper')); $this-set('image', $this-ImageModel-findAll()); so you can then use them without conflict Thoughts anyone? I don't have enough experience with the core to know if the above enhancement would have any negative side-effects. Cheers, Adam On Dec 20, 10:45 pm, AD7six [EMAIL PROTECTED] wrote: On Dec 20, 10:37 am, lordG [EMAIL PROTECTED] wrote: Hi Guys, I've got a question, and hopefully one of the cakephp guys can give an answer. First, the scenario... I often will used more than one model file to represent the same data. A common reason is to separate admin functions from normal ones, so the normal model is less intensive to load. There may be other reasons like two different data sources, but the same data model. Now although this does not seem a problem at first, it becomes a problem when you start creating forms to represent and manage that data. In all these models, the $name variable is set the same (e.g. User), so I have transparency between the models (and the models may be named: UserModel1, UserModel2 etc). However, when we populate a form with the model data using the FormHelper, it requires the following name: ModelClass.field (1.2) or ModelClass/field (1.1). Now naturally this causes a problem when the models have different class names (This may be so that we can store all the models in the same directory or even load more than one of them at the same time.) The above sounds rather over complex to me. What is the benefit of making several 'models' for one model? (The fact that I ask should imply that I don't percieve any of the above reasons as a benefit). Now my only argument or frustration is why does the FormHelper use the Classname as part of the naming of the input field rather than the $name variable of the class? Why is the $name not the same as the class name. That´s begging for things not to work IMO. 1.2 uses the alias afaik btw, which defaults to the model name. I have no problem in it needing the class name to initiate and retrieve the input name value, but I think that it would be best that the resulting name was: data[ModelNameVariable] [field]. What are your thoughts? Then, the second part of the conventions is why are controller class files named differently to all the other files like models, helpers, components etc? You are refering to plural or _controller? I can´t remember the specifics but when the _controller was dropped there were naming conflicts. Surely to remain consistent, one should keep the naming convention the same all across? My personal preference would be that they are all named according to their class name, so much like the current controllers are. I understand the impact this would have, but I think that this would help keep a stronger convention on the naming of the files. If anything were to change I prefer writing less :). A third case to look at is if a component and a model share the same $name variable value or Similar class names (Component: User user_component; Model: User user). This causes a problem. To get around that I named all my components iClassComponent. However, I would think that the best way really to solve this would be to name the objects according to their class names, ie: Models would be UserModel and Components would be UserComponent. This also allows for better usability as you thereby know automatically the type of object it is. What are your thoughts? Component Model name conflicts are indeed a problem. Although I don't think writing Component and Model after each of them is necessarily that good an idea. For chained model calls that makes them quite long, and writing $this-SessionComponent-write(); would probable get tiring rather quickly. only IMO of course, AD --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Cake PHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: Class, filename and naming conventions
I'd like helper instances to be capitalized in the view, to avoid this - i.e. $Html-image(...) instead of $html-image(...) The reason is the same as Adam's; models and helpers can often be named the same, and this causes problems. I've thought about the helper alias thing, I agree it would be cool - mainly so I could write MyHtmlHelper which extends HtmlHelper, but access it in the view as $html (not $myHtml). This would make certain things a lot easier (setting default parameters, overriding certain field types in FormHelper, etc...). But actually having models have 'Model' as part of the name? No way, far too much typing : $this-CategoryModel-ProductModel-find(...); Although the actual class could be called 'CategoryModel' and the controller's instance could be accessed through the member variable 'Category' I suppose. On Dec 20, 1:43 pm, Adam Royle [EMAIL PROTECTED] wrote: I've also run into a few conflicts when naming models and helpers... eg. i had a model image and an imagehelper, when baking the view page it generate $this-set('image', $image); which would obviously conflict with my helper. I ended up naming my helper MagicImage instead :) However it would be great if we could avoid this situation. One solution is to wait until we have namespaces (or modules, as I think they may be referred to) in PHP6. Another idea I had (maybe not feasible) is to add an alias for loaded classes var $uses = array('Image' = 'ImageModel'); var $helpers = array('Image' = 'ImageHelper'); or var $uses = array('Image' = array('alias' = 'ImageModel')); var $helpers = array('Image' = array('alias' = 'ImageHelper')); $this-set('image', $this-ImageModel-findAll()); so you can then use them without conflict Thoughts anyone? I don't have enough experience with the core to know if the above enhancement would have any negative side-effects. Cheers, Adam On Dec 20, 10:45 pm, AD7six [EMAIL PROTECTED] wrote: On Dec 20, 10:37 am, lordG [EMAIL PROTECTED] wrote: Hi Guys, I've got a question, and hopefully one of the cakephp guys can give an answer. First, the scenario... I often will used more than one model file to represent the same data. A common reason is to separate admin functions from normal ones, so the normal model is less intensive to load. There may be other reasons like two different data sources, but the same data model. Now although this does not seem a problem at first, it becomes a problem when you start creating forms to represent and manage that data. In all these models, the $name variable is set the same (e.g. User), so I have transparency between the models (and the models may be named: UserModel1, UserModel2 etc). However, when we populate a form with the model data using the FormHelper, it requires the following name: ModelClass.field (1.2) or ModelClass/field (1.1). Now naturally this causes a problem when the models have different class names (This may be so that we can store all the models in the same directory or even load more than one of them at the same time.) The above sounds rather over complex to me. What is the benefit of making several 'models' for one model? (The fact that I ask should imply that I don't percieve any of the above reasons as a benefit). Now my only argument or frustration is why does the FormHelper use the Classname as part of the naming of the input field rather than the $name variable of the class? Why is the $name not the same as the class name. That´s begging for things not to work IMO. 1.2 uses the alias afaik btw, which defaults to the model name. I have no problem in it needing the class name to initiate and retrieve the input name value, but I think that it would be best that the resulting name was: data[ModelNameVariable] [field]. What are your thoughts? Then, the second part of the conventions is why are controller class files named differently to all the other files like models, helpers, components etc? You are refering to plural or _controller? I can´t remember the specifics but when the _controller was dropped there were naming conflicts. Surely to remain consistent, one should keep the naming convention the same all across? My personal preference would be that they are all named according to their class name, so much like the current controllers are. I understand the impact this would have, but I think that this would help keep a stronger convention on the naming of the files. If anything were to change I prefer writing less :). A third case to look at is if a component and a model share the same $name variable value or Similar class names (Component: User user_component; Model: User user). This causes a problem. To get around that I named all my components iClassComponent. However, I would think that the best way really to solve this would be to name the objects
Re: Class, filename and naming conventions
Adam, I think your idea of the alias naming is good. It would help considerably. Adam Royle wrote: var $uses = array('Image' = 'ImageModel'); var $helpers = array('Image' = 'ImageHelper'); or var $uses = array('Image' = array('alias' = 'ImageModel')); var $helpers = array('Image' = array('alias' = 'ImageHelper')); $this-set('image', $this-ImageModel-findAll()); --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Cake PHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: Class, filename and naming conventions
AD7six, thanks for your feedback. below are some further thoughts. The above sounds rather over complex to me. What is the benefit of making several 'models' for one model? (The fact that I ask should imply that I don't percieve any of the above reasons as a benefit). Here is another example (just an example)... Lets say we have a dedicated site menu and a dedicated admin menu. The site menu is stored in table 'site_menu' and the admin one in 'admin_menu'. Both share the same table structure, so many of the functions and views for managing them are the same. However, there may be a few possible functions you may call in the 2 models when saving that are different to one another. So... by keeping the $name variable in both the as 'Menu', this means one could use 1 set of controllers and views to manage both sets of tables, and therefor reduce the amount of code one writes. This is just one theory or example. Lets not debate why one would create 2 tables that in reality are the same structure. This is merely an example for us to work with. You are refering to plural or _controller? I can�t remember the specifics but when the _controller was dropped there were naming conflicts. Surely to remain consistent, one should keep the naming convention the same all across? My personal preference would be that they are all named according to their class name, so much like the current controllers are. I understand the impact this would have, but I think that this would help keep a stronger convention on the naming of the files. If anything were to change I prefer writing less :). I agree with what you are saying about writing less. If this is the case then, perhaps the controller filename would be better being the same as the helpers, components etc. filename = users.php; class = UsersController. Then the same theory should perhaps apply to the models to maintain consistency... filename = user.php; class = UserModel. Overall this would be adopting better conformity to the conventions across the files and class names. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Cake PHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: Class, filename and naming conventions
mhm sorry but you're aware of the fat models , thin controllers idea ? imo let's stick to it. in you example you should have a controller with admin_actions and using the same model. If many of the structures are the same then just put them in the same model and call them from admin/user actions. These action can use the same views if you want. Create one controller with different actions for different users ( you probably should check permissions in the app/controller) and use one model - the data manipulation functions ( M (from MVC) like data Manipulation ;) will be the same. greets, Marcin Domanski On Dec 20, 4:48 pm, lordG [EMAIL PROTECTED] wrote: AD7six, thanks for your feedback. below are some further thoughts. The above sounds rather over complex to me. What is the benefit of making several 'models' for one model? (The fact that I ask should imply that I don't percieve any of the above reasons as a benefit). Here is another example (just an example)... Lets say we have a dedicated site menu and a dedicated admin menu. The site menu is stored in table 'site_menu' and the admin one in 'admin_menu'. Both share the same table structure, so many of the functions and views for managing them are the same. However, there may be a few possible functions you may call in the 2 models when saving that are different to one another. So... by keeping the $name variable in both the as 'Menu', this means one could use 1 set of controllers and views to manage both sets of tables, and therefor reduce the amount of code one writes. This is just one theory or example. Lets not debate why one would create 2 tables that in reality are the same structure. This is merely an example for us to work with. You are refering to plural or _controller? I can�t remember the specifics but when the _controller was dropped there were naming conflicts. Surely to remain consistent, one should keep the naming convention the same all across? My personal preference would be that they are all named according to their class name, so much like the current controllers are. I understand the impact this would have, but I think that this would help keep a stronger convention on the naming of the files. If anything were to change I prefer writing less :). I agree with what you are saying about writing less. If this is the case then, perhaps the controller filename would be better being the same as the helpers, components etc. filename = users.php; class = UsersController. Then the same theory should perhaps apply to the models to maintain consistency... filename = user.php; class = UserModel. Overall this would be adopting better conformity to the conventions across the files and class names. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Cake PHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---