Re: Best Practice for Views
Couldn't you create an Element for the data? http://manual.cakephp.org/chapter/views On Jul 30, 6:58 pm, Grant Cox [EMAIL PROTECTED] wrote: Are you talking about several different skins, but really the same data and presentation? Or are you talking about some non-trivial data calculation, then you want to show the result in several independent areas of your site? I'm just not sure of the reason for the several views on a single action. For the former, have a variable (perhaps session) that determines which layout to use, or even to choose another view file to render (if the structure needs to be quite different). For the latter, you should move the functionality into the appropriate model or component file, so that it can be called from any number of controller actions without duplication. --~--~-~--~~~---~--~~ 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: Best Practice for Views
Thanks for the reply! The problem I am running into is that I need different views for the same information. For example, when someone visits http://www.some.com/controller/view/1 it will show say a list of links. In http://www.some.com/controller/view/2 it will show similar information from the database but as a table instead of a list of links. Right now for me to do this I set the a variable that holds the view that I want to show. So in my actual view.thtml file I have a switch statement off of this view variable I set in my controller so the actually view.thtml knows what view I need to show (in this example the list or the table). Does this make sense? On Jul 30, 5:58 pm, Grant Cox [EMAIL PROTECTED] wrote: Are you talking about several different skins, but really the same data and presentation? Or are you talking about some non-trivial data calculation, then you want to show the result in several independent areas of your site? I'm just not sure of the reason for the several views on a single action. For the former, have a variable (perhaps session) that determines which layout to use, or even to choose another view file to render (if the structure needs to be quite different). For the latter, you should move the functionality into the appropriate model or component file, so that it can be called from any number of controller actions without duplication. --~--~-~--~~~---~--~~ 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: Best Practice for Views
I think I understand... It sounds to me like you should have two actions, not one: http://www.some.com/controller/viewList/ http://www.some.com/controller/viewTable/ Having one view to encapsulate two doesn't sound correct... but I'm still new at this myself. On Jul 31, 12:48 pm, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: Thanks for the reply! The problem I am running into is that I need different views for the same information. For example, when someone visitshttp://www.some.com/controller/view/1 it will show say a list of links. Inhttp://www.some.com/controller/view/2 it will show similar information from the database but as a table instead of a list of links. Right now for me to do this I set the a variable that holds the view that I want to show. So in my actual view.thtml file I have a switch statement off of this view variable I set in my controller so the actually view.thtml knows what view I need to show (in this example the list or the table). Does this make sense? On Jul 30, 5:58 pm, Grant Cox [EMAIL PROTECTED] wrote: Are you talking about several different skins, but really the same data and presentation? Or are you talking about some non-trivial data calculation, then you want to show the result in several independent areas of your site? I'm just not sure of the reason for the several views on a single action. For the former, have a variable (perhaps session) that determines which layout to use, or even to choose another view file to render (if the structure needs to be quite different). For the latter, you should move the functionality into the appropriate model or component file, so that it can be called from any number of controller actions without duplication. --~--~-~--~~~---~--~~ 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: Best Practice for Views
That's what I'll probably end up doing since I'm still prototyping this stuff out. I'm guessing it would be better practice to have multiple view files instead of combining several views in one thtml file and also having several different controller actions. I'm just left here thinking about other views for the same data and making those views dynamic. Okay, so here's a random thought. What if I put the thtml code of each view into the database. Then extract it in the controller and use the set method to set the code as a variable for the view. Then in the view eval() the code? Good idea or not? hm. On Jul 31, 12:02 pm, starkey [EMAIL PROTECTED] wrote: I think I understand... It sounds to me like you should have two actions, not one:http://www.some.com/controller/viewList/http://www.some.com/controller/viewTable/ Having one view to encapsulate two doesn't sound correct... but I'm still new at this myself. On Jul 31, 12:48 pm, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: Thanks for the reply! The problem I am running into is that I need different views for the same information. For example, when someone visitshttp://www.some.com/controller/view/1 it will show say a list of links. Inhttp://www.some.com/controller/view/2 it will show similar information from the database but as a table instead of a list of links. Right now for me to do this I set the a variable that holds the view that I want to show. So in my actual view.thtml file I have a switch statement off of this view variable I set in my controller so the actually view.thtml knows what view I need to show (in this example the list or the table). Does this make sense? On Jul 30, 5:58 pm, Grant Cox [EMAIL PROTECTED] wrote: Are you talking about several different skins, but really the same data and presentation? Or are you talking about some non-trivial data calculation, then you want to show the result in several independent areas of your site? I'm just not sure of the reason for the several views on a single action. For the former, have a variable (perhaps session) that determines which layout to use, or even to choose another view file to render (if the structure needs to be quite different). For the latter, you should move the functionality into the appropriate model or component file, so that it can be called from any number of controller actions without duplication. --~--~-~--~~~---~--~~ 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: Best Practice for Views
I think that would be overkill (and unnecessarily complex). Besides, you'd need to setup a model to get to your views... I suggest sticking with how Cake does things (which is pretty darn good). On Jul 31, 2:23 pm, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: That's what I'll probably end up doing since I'm still prototyping this stuff out. I'm guessing it would be better practice to have multiple view files instead of combining several views in one thtml file and also having several different controller actions. I'm just left here thinking about other views for the same data and making those views dynamic. Okay, so here's a random thought. What if I put the thtml code of each view into the database. Then extract it in the controller and use the set method to set the code as a variable for the view. Then in the view eval() the code? Good idea or not? hm. On Jul 31, 12:02 pm, starkey [EMAIL PROTECTED] wrote: I think I understand... It sounds to me like you should have two actions, not one:http://www.some.com/controller/viewList/http://www.some.com/controlle... Having one view to encapsulate two doesn't sound correct... but I'm still new at this myself. On Jul 31, 12:48 pm, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: Thanks for the reply! The problem I am running into is that I need different views for the same information. For example, when someone visitshttp://www.some.com/controller/view/1 it will show say a list of links. Inhttp://www.some.com/controller/view/2 it will show similar information from the database but as a table instead of a list of links. Right now for me to do this I set the a variable that holds the view that I want to show. So in my actual view.thtml file I have a switch statement off of this view variable I set in my controller so the actually view.thtml knows what view I need to show (in this example the list or the table). Does this make sense? On Jul 30, 5:58 pm, Grant Cox [EMAIL PROTECTED] wrote: Are you talking about several different skins, but really the same data and presentation? Or are you talking about some non-trivial data calculation, then you want to show the result in several independent areas of your site? I'm just not sure of the reason for the several views on a single action. For the former, have a variable (perhaps session) that determines which layout to use, or even to choose another view file to render (if the structure needs to be quite different). For the latter, you should move the functionality into the appropriate model or component file, so that it can be called from any number of controller actions without duplication. --~--~-~--~~~---~--~~ 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: Best Practice for Views
One of the primary parts of Cake is to keep your data separate from your application interface (controllers), separate from your presentation (views). Changing one of these elements should not require modification to the others. You want the first two to remain the same, you just want different views. If the controller functionality remains the same between the different modes (list vs table), which I imagine it does, then you should stick to a single controller action. Allow the request to determine what format to output, and render the appropriate view from this. So requesting /controller/view/list vs /controller/view/table will execute the same controller action, but just render the list.ctp or table.ctp view file. --~--~-~--~~~---~--~~ 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: Best Practice for Views
I'm with grant - use one action with a differnt view as needed function action1($layout = 'list'){ // set data and other stuff switch ($layout){ case 'table': $this-render('action1_table'); break; default: $this-render('action1_list'); break; } } You could use if...else if there are only two possible options Geoff -- http://lemoncake.wordpress.com On Aug 1, 9:19 am, Grant Cox [EMAIL PROTECTED] wrote: One of the primary parts of Cake is to keep your data separate from your application interface (controllers), separate from your presentation (views). Changing one of these elements should not require modification to the others. You want the first two to remain the same, you just want different views. If the controller functionality remains the same between the different modes (list vs table), which I imagine it does, then you should stick to a single controller action. Allow the request to determine what format to output, and render the appropriate view from this. So requesting /controller/view/list vs /controller/view/table will execute the same controller action, but just render the list.ctp or table.ctp view file. --~--~-~--~~~---~--~~ 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: Best Practice for Views
Are you talking about several different skins, but really the same data and presentation? Or are you talking about some non-trivial data calculation, then you want to show the result in several independent areas of your site? I'm just not sure of the reason for the several views on a single action. For the former, have a variable (perhaps session) that determines which layout to use, or even to choose another view file to render (if the structure needs to be quite different). For the latter, you should move the functionality into the appropriate model or component file, so that it can be called from any number of controller actions without duplication. --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---