Re: Access model/controler data without requestAction
Hi Sebastian, I think that requestAction is often considered/used when a method that should be in a model is located in a controller - if you are only retreiving data from a model, possibly after manipulating it a bit, consider moving the logic that is in your controller to the model and then simply call the model(s) as required. That is, if you can´t get all the data you want via intelligent use of bind, unbind and recursive. Also if you are using requestAction just because you don´t want to duplicate your view code (a good thing) consider using elements for your relavent object views. I always use the same examples, but e.g.: /app/views/comments/view.thtml ? echo $this-renderElement (comment,Array(data=$data)); ? /app/views/blogs/view.thtml ? echo $this-renderElement (blog,Array(data=$data)); ? /app/views/elements/blog.thtml ? blog stuff foreach ($data['Comment'] as $comment) { echo $this-renderElement (comment,Array(data=$comment)); // probably need to rearrange the comment array a bit, writing from memory. } HTH, AD7six --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Re: Access model/controler data without requestAction
/app/views/elements/blog.thtml ? blog stuff foreach ($data['Comment'] as $comment) { echo $this-renderElement (comment,Array(data=$comment)); // probably need to rearrange the comment array a bit, writing from memory. } for a more accurate description of this rearranging-problem (and an easy way to solve it), check this: http://groups.google.com/group/cake-php/browse_thread/thread/238784e263438840/# --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Re: Access model/controler data without requestAction
A good place I use requestaction is for subtotal of shopping cart. This way I can place the subtotal of the shopping cart on as many views as I want just by calling the requestaction. I could have just as easily made it a method of the model, but then I would have to set variable for use in the view. Another good use is for a side menu. This way you don't have to call the data in each of the methods you want the menu to appear in to pass that data to the renderElement. Instead with the array('return') it already returns it properly formatted by a simple call in whatever views you want the side menu in. Other than these two examples, I do model-methods and set the data for use in the view. In your models if you use $this-query() to run any custom queries you need and format the query like CakePHP does it will return to a CakePHP array for easy use. Here is an example of where you would want code in the model and not controller. Say you have a configs table that stores parameters and values. You could have a controller method that gets the param and value passed to it. You then use $this-Config-saveField() to save the parameter's value. Instead you should just place code in the model so it can be called directly. $this-Config-saveparam and in that method it would run $this-saveField as well. The only difference is now I can call this directly instead of thru the requestAction. So, maybe what you are looking for is to make calls directly place your method in the model. And remember that you can use all the model available functions you just don't have to prefix them with the modelname anymore. --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Re: Access model/controler data without requestAction
Thanks for the excellent comments Troy and AD7six. I think I was actually trying to be too politically correct and I didn't want to use others models inside my controllers so I was using requestAction to get data from other models but also to avoid having duplicated views as AD7six mentioned; renderElement and $uses are going to be very handy from now on. --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Re: Access model/controler data without requestAction
You could consider setting the recursive variable of models and controllers that you don't need them to retrieve their full out associations. The associations can take up most of the time. What is taking up most of your time is not the actual requestaction itself, but all the SQL queries. Turn DEBUG 2 and see the number of SQL queries. You can see which ones you can cut. Unfortunately your database is very large and complex. So, your best bet is to look at places where you can optimize what you are retrieving from the database at the time. For example, my order table has two associations which those associations have other associations. So, if I recursive to level 3 I would get the favorites, items (actual order), photos (the picture they ordered), album (the album the photo belongs to). But most of the time I don't need all that extra. --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Re: Access model/controler data without requestAction
I also need to be able to call other controller methods such as save($data) without the requestAction abuse performance inconveniences. I read the article at: http://www.thinkingphp.org/2006/06/24/welcome-to-the-dark-side-of-plugins-in-cakephp/ I think that is kind of a good approach but not sure which is the best cake way of doing this. --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Re: Access model/controler data without requestAction
Hi Troy. I set DEBUG 2 and these are my results of 1 sample request: SQL Queries Time: 17 queries took 17 ms Total request processing time: 1.8491s I think 1.8 seconds is a long time considering that the SQL queries only take 17 ms and I'm the only user of my Dev server. I will be looking for requestAction alternatives an will post my results as I find anything. Thanks, Sebastian --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Re: Access model/controler data without requestAction
I develop on my laptop and get 1.3 second renderings. You could also paste your code to CakeBin for people to take a look at and see if there is a way to optimize it. http://cakephp.org/pastes --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Re: Access model/controler data without requestAction
Also you can just do $this-Airport-findAllByCity($this-data[Airtravelcalculator][city_input]) and then return stuff. In a controller method I don't find myself using requestaction much at all. I instead use the Models methods (findBy, findAll, etc.) to get any data I need in a specific view. I use requestaction a lot in the views to get side menus or small methods that return something without any layout that would later be updated using AJAX. I think you need to rethink your code and what you are doing in your controller that requires so many requestactions. Perhaps you are trying to be too politically correct and not using your var $uses parameter at all. --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---