model->delete error
Hi, I have v1.3.2 running on a production site that has in a controller: (effectively, some non-related code removed) $results = $this->Pipe->find('all', array('conditions'=>$conditions)); if(sizeof($results) > 1) { $pipes = sizeof($results); for($i = 0; $i < $pipes - 1; $i++) { $this->Pipe->id = $results[$i]['Pipe']['p_id']; $this->Pipe->delete(); unset($results[$i]); } } so that all but one matching record remains. Typically, for months now and even within seconds of the error, the SQL generated by this code was: DELETE FROM `pipe` WHERE `pipe`.`p_id` = 12345; until the one time on yesterday it issued: DELETE FROM `pipe` WHERE 1 = 1; (There went 36+ records) I see this in the MySQL binlog but cannot tell what value for id was set. It is my understanding that in no reasonable case should this cause this SQL to be generated. Does anyone have an alternate understanding or insight into what went wrong? Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
Recursive Association joins n-levels deep
Considering all of the new features in CakePHP 1.2, I have rewritten my Recursive Query support code to be completely encapsulated in a model Behavior. You can find information on it and the file at http://lloydhome.com/blog/development/2009/recursive-association-support-cakephp-12 and also at https://trac.cakephp.org/ticket/633 David Lloyd -- lloydhome consulting, inc. http://lloydhome.com --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
CakePHP developer wanted
Lloydhome Consulting, Inc. (http://lloydhome.com) is looking for a PHP developer for a six month contract with really good pay and a good chance for extensions for the right person. We provide fast, agile, out-sourced development for large international corporations. The candidate should have experience in enterprise environments and demonstrable ability to handle fast-changing requirements. CakePHP, AJAX, and MySql are required. Preference given based on experience, team synergy, and proximity to Atlanta Georgia USA/ North Georgia area as face time may be required but telecommuting is the norm. If interested, send Resume/CV and portfolio to [EMAIL PROTECTED] Thanks --~--~-~--~~~---~--~~ 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: Model->find with large datasets
You will still want to page through the results so that there is not a huge resultset in memory at once. $limit = 1000; // some optimal amount of records $page = 1; $results = null; do { $results = $his->MyModel->findAll($conditions, null, null, $limit, $page++); foreach ($results as $row) { // processing } } while (!empty($results); Something like the above to get pages of results. HTH, David Lloyd -- lloydhome consting, inc. http://lloydhome.com On Aug 7, 1:16 am, jheathco <[EMAIL PROTECTED]> wrote: > The problem is I need to retrieve them all at once because I'm > processing the returned rows in a cronjob. The pagination would be of > no use for this feature. Should I just run a manual query instead of > using the models in this case? > > On Aug 6, 9:00 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> > wrote: > > > set the limit in the $model->find(); to an acceptable performance > > level - you can set this dynamically - or look into the pagination > > component > > > On Aug 6, 6:41 pm, jheathco <[EMAIL PROTECTED]> wrote: > > > > In PHP, typically prior to cake I had done > > > > $res = mysql_query(); > > > while($row = mysql_fetch_array($res)) > > > { > > > > > > > } > > > > And now in cake, $results = Model->find([query here]) and then loop > > > thru the results. > > > > I am wondering about the limitations if, for instance, a few thousand > > > rows are returned. In PHP, it seems looping thru each, one at a time, > > > by calling mysql_fetch_array() was very efficient. However, it seems > > > like cake may have large performance (and memory) issues by trying to > > > dump all results into an array before looping thru. > > > > Am I correct in this thinking? Is there a way to have cake only > > > return the results one at a time, rather than buffering them all into > > > a large array? --~--~-~--~~~---~--~~ 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: Ajax tutorials
hmmm. Big word AJAX on the Bakery takes me to http://bakery.cakephp.org/tags/view/ajax searching this group for the word ajax gives 796 results, the first page has several useful answers. HTH, David Lloyd -- lloydhome consulting, inc. http://lloydhome.com On Feb 23, 12:49 pm, "Junal Rahman" <[EMAIL PROTECTED]> wrote: > I want to use Ajax in Cakephp. Can anybody give me a link of example where i > can see how to use Ajax in cake. --~--~-~--~~~---~--~~ 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: file upload
You need to put it under the webroot mysite -- app - webroot file HTH, David Lloyd -- lloydhome consulting, inc http://lloydhome.com On Feb 21, 6:58 pm, "bingo" <[EMAIL PROTECTED]> wrote: > Hi, > > I want to allow users to upload files on to the server...however, I > got all the code..but have some problem in providing a link to the > user.. > > my configuration is as follows > > mysite > -- app > -- cake > -- file //in this folder I will keep all the uploaded files > > however, if I create a link such ashttp://localhost/mysite/file/demo.pdf > cake takes over the control and display a page with error: > You are seeing this error because controller FilesController could > not be found. > > is there a way to avoid cakephp taking control over file the folder --~--~-~--~~~---~--~~ 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: View Caching of Home Page
The problem is that the file is created by the value of $this->here and if that is the same as cacheAction or in the array of cacheAction. Then when hitting the site the same url has to be used. The easiest solution off the top of my head is to use mod_rewrite to force ^$ and ^/$ to go to your custom controller/action RewriteRule ^$ index.php?url=/mycontroller/myaction [QSA,L] RewriteRule ^/$ index.php?url=/mycontroller/myaction [QSA,L] # everything else below I have not tried it but hope it helps, David Lloyd -- lloydhome consulting http://lloydhome.com On Feb 20, 6:51 pm, "PaulV" <[EMAIL PROTECTED]> wrote: > Hi Guys, > > I am trying to improve the performance of loading my home page by > turning on view caching in Cake Stable: 1.1.13.4450 > > My home page (e.g. at http:///) is routed to a custom > controller using the following in routes.php > > $Route->connect('/', array('controller' => 'pub', 'action' => > 'index', '')); > > where I have a custom controller "pub_controller.php" with a custom > action "index" and the appropriate CACHE_CHECK global and cacheAction > variables have been set. > > When I visit the home page, no file gets created in the tmp/cache/ > views directory. If I visit other URLs, a cache file is created (eg. I > visit pub/index as above). > > Can someone let me know how I can solve this problem? > > Thanks, >Paul --~--~-~--~~~---~--~~ 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: md5_file
hashes are just a number so a collision is certain with a large enough dataset. CRC is usually 32 - 64 bits and MD5 is 128 bit. They are pretty good at making sure you have the file you knew you wanted - i.e. checking for transmission errors. To check against a duplicate file I would want something better. At least the MD5 , filelength , and first n bytes of the file (32+?). If all three were the same it would be a real good check but not definitive. The more you can check against the better until you actually compare byte-to-byte the two files. My 2c, David Lloyd -- lloydhome consulting, inc. http://lloydhome.com On Feb 20, 11:44 am, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote: > Not really a cake question... but I was wondering... is md5 or crc a > good way to check if two files are identical? > > I guess my question is, what are the chances that md5_file would > create the same hash for 2 different files? I assume this is highly > unlikely, but not really my area of expertise. > > Thanks, > cook --~--~-~--~~~---~--~~ 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: Per-Controller Scaffolding
Documentation can be wrong just like code. Issues can be Trac'ed (trac.cakephp.org). If it is wrong, submit a bug. If you want to help, submit a patch. Thanks for your contributions, David Lloyd -- lloydhome consulting, inc http://lloydhome.com On Feb 20, 11:44 am, "the_woodsman" <[EMAIL PROTECTED]> wrote: > Right, sorry, I managed to solve this by looking at scaffold.php. > > It turns out that it includes views/controller_name/ > scaffold..thtml > > As opposed to, as the manual states, > > /app/views/controller_name/scaffold/.scaffold.thtml > > Sorry to waste people's time... I don't really see why the > documentaiton isn't correct on this though :) > > On 20 Feb, 16:22, "the_woodsman" <[EMAIL PROTECTED]> wrote: > > > Hi bakers, > > > Maybe I'm missing the obvious, but I can't override scaffolding for > > individual controllers. > > > I've managed to get this working for the app as a whole > > (seehttps://trac.cakephp.org/ticket/2113forwhy this took me a while!), > > but not for an individual controller. > > > For example, I have a TimecardController. > > I have a views/timecard/scaffold dir. > > In here I have both scaffold.edit.thtml and edit.scaffold.thtml, and I > > can't get either of them to work. > > > Any pointers? > > > Thanks in advance, > > > Woody --~--~-~--~~~---~--~~ 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: Per-Controller Scaffolding
Documentation can be wrong just like code. Issues can be Trac'ed (trac.cakephp.org). If it is wrong, submit a bug. If you want to help, submit a patch. Thanks for your contributions, David Lloyd -- lloydhome consulting, inc http://lloydhome.com On Feb 20, 11:44 am, "the_woodsman" <[EMAIL PROTECTED]> wrote: > Right, sorry, I managed to solve this by looking at scaffold.php. > > It turns out that it includes views/controller_name/ > scaffold..thtml > > As opposed to, as the manual states, > > /app/views/controller_name/scaffold/.scaffold.thtml > > Sorry to waste people's time... I don't really see why the > documentaiton isn't correct on this though :) > > On 20 Feb, 16:22, "the_woodsman" <[EMAIL PROTECTED]> wrote: > > > Hi bakers, > > > Maybe I'm missing the obvious, but I can't override scaffolding for > > individual controllers. > > > I've managed to get this working for the app as a whole > > (seehttps://trac.cakephp.org/ticket/2113forwhy this took me a while!), > > but not for an individual controller. > > > For example, I have a TimecardController. > > I have a views/timecard/scaffold dir. > > In here I have both scaffold.edit.thtml and edit.scaffold.thtml, and I > > can't get either of them to work. > > > Any pointers? > > > Thanks in advance, > > > Woody --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Recursive Association joins with conditions 3+ deep
I posted some questions on the group and on the IRC in late October and early November. http://groups.google.com/group/cake-php/browse_thread/thread/7ac86a4ad74198b4/8f2cbc16312a05e4?lnk=gst&q=recursive+query&rnum=1#8f2cbc16312a05e4 I'd post IRC archive links but I can't seem to connect to irc.cakephp.org Three and a half months later I have been refining this code from time to time while using it on two of my web sites. One of them is quite large and was the original need. The first of the patches was in 1.1.9 and then 1.1.10, 1.1.12, 1.2alpha. I may do a patch for 1.1.13 but have been focusing efforts on 1.2. Most of this code was complete about 11/14 after speaking with nate and phpnut on irc. The intense work load and holiday season keft me from writing it up. I have synopsis and the patched code at http://lloydhome.com/blog/archives/2007/02/Recursive-Association-Support-in-CakePHP.html. Please test this yourself and leave comments. I hope to write some unit tests that are generic as what I have is specific to my website and use. Then this will be ready to submit as a fix to Trac issue #633 (https://trac.cakephp.org/ticket/633). Thanks, David Lloyd -- lloydhome consulting http://lloydhome.com --~--~-~--~~~---~--~~ 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: Navigation Component / Helper
Your example is good but you need to set the return attribute. $this->set($menu, $this->Categories->requestAction('/categories/ getCategoryList', array('return'=>1))); This is the type of thing that could use a cache as I descibed http://lloydhome.com/blog/archives/2007/02/More-Caching-in-CakePHP.html and http://groups.google.com/group/cake-php/browse_thread/thread/5e0034e1ce6c4798/# If you follow the caching I posted then also add the cache parameter. $this->set($menu, $this->Categories->requestAction('/categories/ getCategoryList', array('return'=>1, 'cache'=>1))); HTH, David Lloyd -- lloydhome consulting, inc. http://lloydhome.com On Feb 17, 11:33 am, "Siegfried Hirsch" <[EMAIL PROTECTED]> wrote: > here is a small example: > > in your main controller or better in the app_controller in /app > > class AppController extends Controller { > function beforeFilter() { > $this->set($menu, > $this->Categories->requestAction('/categories/getCategoryList')); > } > ...} > > /* not tested - just as a hint */ > > now you can access $menu in your elements and even in the layout. > > Siegfried > > 2007/2/17, Helmi <[EMAIL PROTECTED]>: > > > > > > > i'll get attached to this. My current thoughts go in the same > > direction. The only question is where to get the data for the element? > > > I want to use a list of categories from the Category Model within my > > menu and i don't really know how to access the data from the Category > > Model within the elements. > > > Any further help for this? > > > Thanks, > > Frank > > -- > Siegfried Hirsch > hhS - Welserstr. 1 - 81373 M?nchen - (089) 5484 3564 - > skype:shirschhttp://gadgetgui.de/http://www.rss-blogger.dehttp://www.newsbee.deNewsBee > 2 - customized RSS solutions --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
requestAction view caching and user authentication of cached views
I have a user portal that gathers information from multiple controllers. The logic belongs in those controllers. The portal obtains these viewlets via requestAction() calls. RequestAction is notoriously slow and had no chance of using the view cache. This has really sped up my requestAction calls that are database and logic heavy. I modified my dispatcher.php dispatch method to first look for a cache if its an internal call... if (!empty($additionalParams) && !empty($additionalParams['cache'])) { // requestAction had no prior chance to get cached version so check here if (defined('CACHE_CHECK') && CACHE_CHECK === true) { $uri = Router::url($url); if (empty($uri)) { $uri = setUri(); } if (!isset($TIME_START)) { $TIME_START = getMicrotime(); } if (strpos($uri,'/bare/')===false) { // we want to force a bare cache $filename = CACHE . 'views' . DS . 'bare_' . convertSlash($uri) . '.php'; } ele { $filename = CACHE . 'views' . DS . convertSlash($uri) . '.php'; } if (file_exists($filename)) { uses('controller' . DS . 'component', DS . 'view' . DS . 'view'); $v = null; $view = new View($v); if ($view->renderCache($filename, $TIME_START, false)) { return; } } elseif(file_exists(CACHE . 'views' . DS . 'bare__' . convertSlash($uri) . '_index.php')) { uses('controller' . DS . 'component', DS . 'view' . DS . 'view'); $v = null; $view = new View($v); if ($view->renderCache(CACHE . 'views' . DS . convertSlash($uri) . '_index.php', $TIME_START)) { return; } } } } and modified my View::renderCache to accept a third parameter function renderCache($filename, $timeStart, $dieOnSuccess = true) { and not die(); in there if it is false. If this is not formatted in your email, see http://lloydhome.com/news/ view/6. Also, I have posted an article on user authentication within cached pages at http://lloydhome.com/news/view/5. It is a Smarty article but it is usable for ctp and thtml files that are cached and need a controller's beforeFilter() run to allow user authentication. - David Lloyd -- lloydhome consulting, inc. http://lloydhome.com --~--~-~--~~~---~--~~ 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: How to use smarty cache in cakephp?
I only have one page that is cached and has dynamic data on it. It was really messy with Smarty and there are some other features I wanted so I have decided to clean it all up. See http://www.lloydhome.com/news/view/5 for a full explaination. AS A BONUS, you get the controller's beforeFilter() to run before showing cached content - just be careful with what you do. It should be used to authenticate that the cache is available to the user. The short answer for those searching in the future: You have to set the $this->_tpl_vars array to the variables you want accessed. This can only be set if it is empty (cached case). This is a hoop to go through but the alternative is usually a worse set of {php} global $foo; {/php} . HTH, David Lloyd -- lloydhome consulting, inc. http://lloydhome.com On Feb 14, 8:56 am, "lloydhome" <[EMAIL PROTECTED]> wrote: > As this is using Cake's cache the SAME limitations are applied. > > How is it that 'time' will be set in the view if the controllers are > not run? When it is cached NO CONTROLLERS are run. NO SMARTY is > run. Only the session variables are available. > > I see in my template it is difficult to get a clean code except in my > situation so I will change the SmartyView to have easier caching. But > you still will have to rethink how your variables are accessed. > > I'll reply back soon, > > David Lloyd > -- > lloydhome consultinghttp://lloydhome.com > > On Feb 14, 7:48 am, "rollenc" <[EMAIL PROTECTED]> wrote: > > > I am puzzle. > > I put the Tag to layout/index.php And it no use too. > > And now, the code > > > > {#$time#} > > > > in /view/index.tpl is parsed as follow in cache file: > > _tpl_vars['time']; ?> > > > The value $this->_tpl_vars['time'] is not exist since the smarty > > complie not run(cache runed). > > > Can I get a demo? > > Tanks. > > > On 2月10日, 下午9时52分, "lloydhome" <[EMAIL PROTECTED]> wrote: > > > > Quote from previous: > > > >If you use it should work as long as the tag is in > > > the layout file. > > > > That means it is not working in the included views - like yours. It > > > would not work anyway with your case as no controller would run to set > > > $time. The dynamic part must come from session or other outside > > > means. > > > > HTH, > > > > David Lloyd > > > -- > > > lloydhome consultinghttp://lloydhome.com > > > > On Feb 9, 10:57 pm, "rollenc" <[EMAIL PROTECTED]> wrote: > > > > > Thx, But I am puzzle in part cache. > > > > I type this code: > > > > controler: > > > > var $view = 'Smarty'; > > > > var $helpers = array('Cache'); > > > > var $cacheAction = array('index' => 86400, 'view/' => 3600); > > > > function index() > > > > { > > > > $this->set('posts', $this->Test->findAll()); > > > > $this->set('time', date('H:i:s', time())); > > > > } > > > > In View > > > > {#foreach from=$posts item=post#} > > > > {#$post.Test.title#} > > > > {#$post.Test.body#} > > > > > > > > {#foreachelse#} > > > > There is nothing > > > > {#/foreach#} > > > > > > > > > {#$time#} > > > > > > > > > Website: {#$smarty.server.SERVER_NAME#} > > > > > Full page is cached. but nocache tag is ommited. > > > > And the cache file as this: > > > > > > > > 03:46:08 > > > > > > > > > These is no parse.And the cache is no useful. > > > > > What is correct? > > > > > On 2月10日, 上午3时12分, "lloydhome" <[EMAIL PROTECTED]> wrote: > > > > > > I have a SmartyView that handles caching by utilizing cake's page > > > > > caching. It handles full-page caching great. If you use > > > > > it should work as long as the tag is in the layout > > > > > file. I have need for a cachable, non-static ajax call with no layout > > > > > and this solution nor cake's default works for me. So I have an idea > > > > > for that too but you'll need to be patient. > > > > > > The file is athttp://www.lloydhome.co
Re: How to use smarty cache in cakephp?
As this is using Cake's cache the SAME limitations are applied. How is it that 'time' will be set in the view if the controllers are not run? When it is cached NO CONTROLLERS are run. NO SMARTY is run. Only the session variables are available. I see in my template it is difficult to get a clean code except in my situation so I will change the SmartyView to have easier caching. But you still will have to rethink how your variables are accessed. I'll reply back soon, David Lloyd -- lloydhome consulting http://lloydhome.com On Feb 14, 7:48 am, "rollenc" <[EMAIL PROTECTED]> wrote: > I am puzzle. > I put the Tag to layout/index.php And it no use too. > And now, the code > > {#$time#} > > in /view/index.tpl is parsed as follow in cache file: > _tpl_vars['time']; ?> > > The value $this->_tpl_vars['time'] is not exist since the smarty > complie not run(cache runed). > > Can I get a demo? > Tanks. > > On 2月10日, 下午9时52分, "lloydhome" <[EMAIL PROTECTED]> wrote: > > > Quote from previous: > > >If you use it should work as long as the tag is in > > the layout file. > > > That means it is not working in the included views - like yours. It > > would not work anyway with your case as no controller would run to set > > $time. The dynamic part must come from session or other outside > > means. > > > HTH, > > > David Lloyd > > -- > > lloydhome consultinghttp://lloydhome.com > > > On Feb 9, 10:57 pm, "rollenc" <[EMAIL PROTECTED]> wrote: > > > > Thx, But I am puzzle in part cache. > > > I type this code: > > > controler: > > > var $view = 'Smarty'; > > > var $helpers = array('Cache'); > > > var $cacheAction = array('index' => 86400, 'view/' => 3600); > > > function index() > > > { > > > $this->set('posts', $this->Test->findAll()); > > > $this->set('time', date('H:i:s', time())); > > > } > > > In View > > > {#foreach from=$posts item=post#} > > > {#$post.Test.title#} > > > {#$post.Test.body#} > > > > > > {#foreachelse#} > > > There is nothing > > > {#/foreach#} > > > > > > > {#$time#} > > > > > > > Website: {#$smarty.server.SERVER_NAME#} > > > > Full page is cached. but nocache tag is ommited. > > > And the cache file as this: > > > > > > 03:46:08 > > > > > > > These is no parse.And the cache is no useful. > > > > What is correct? > > > > On 2月10日, 上午3时12分, "lloydhome" <[EMAIL PROTECTED]> wrote: > > > > > I have a SmartyView that handles caching by utilizing cake's page > > > > caching. It handles full-page caching great. If you use > > > > it should work as long as the tag is in the layout > > > > file. I have need for a cachable, non-static ajax call with no layout > > > > and this solution nor cake's default works for me. So I have an idea > > > > for that too but you'll need to be patient. > > > > > The file is athttp://www.lloydhome.com/files/smarty.ph_.txtandneeds > > > > to be renamed and placed in your /app/views directory. > > > > > To use in your controller: > > > > > var $view = 'Smarty'; > > > > var $cacheAction = 300; // 5 minutes > > > > var $helpers = array('Cache'); > > > > > HTH, > > > > > David Lloyd > > > > -- > > > > lloydhome consultinghttp://lloydhome.com > > > > > On Feb 9, 8:42 am, "lloydhome" <[EMAIL PROTECTED]> wrote: > > > > > > I also use Smarty but since it is a View and not recognized by the > > > > > core it is not advantageous to use its caching. I would argue that > > > > > this it actually better to not try without good reason. The problem > > > > > with this approach is the logic still occurs in the controller ad the > > > > > only time savings is in rendering the view. > > > > > > The SmartyView doesn't cache the output the way cake wants it but I > > > > > have some ideas on that I am going to try... It will be easy to setup > > > > > whole page caching but using will be harder. I'll post > > > > > back with what I find. > > > > > > David Lloyd > > > > > -- > > > > > lloydhome consultinghttp://www.lloydhome.com > > > > > > On Feb 9, 4:39 am, "rollenc" <[EMAIL PROTECTED]> wrote: > > > > > > > I combine smarty & cackephp followng this article: http:// > > > > > > projects.simpleteq.com/CakePHP/smarty.html > > > > > > but I don't know how to use smarty cache . > > > > > > Call for help. Thanks. --~--~-~--~~~---~--~~ 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: How do I stop the return of unwanted associated data?
See http://manual.cakephp.org/chapter/models and then look at Section 2 "findAll" takes recursive that limits the depth or look at Section 3 where model has "var $recursive" that limits it as the default (overridden by calls like findAll, find, etc.). HTH, David Lloyd -- lloydhome consulting http://lloydhome.com On Feb 12, 7:35 pm, "Christopher E. Franklin, Sr." <[EMAIL PROTECTED]> wrote: > Hello, > > How do I stop the return or query of associated data? I can see this > becoming a huge problem in the future. > > This is how I have things set up: > > I have 3 tables: > -classifieds > -categories > -category_classified > > Classifieds $hasManyAndBelongsTo Categories > Categories $hasManyAndBelongsTo Classifieds > (I didn't know how else to set these up using $hasMany, etc) > > All of this works fine. Here is where my problem comes in: > > I created a helper class that will generate a custom category menu. > The links are not static but, rather dependant on which page you are > on. > > In my ClassifiedsController I do, $this->Category->findAll(). This > provides me with an array with which I want to pass to the helper to > parse and generate the menu. > > The drawback I am seeing when I print_r the array returned by > $this->Category->findAll(), the array includes all the classifieds > > associated with the category. So, I get an output like this: > > > [12] => Array > ( > [Category] => Array > ( > [id] => 0950 > [name] => Rentals > ) > > [Classified] => Array > ( > [0] => Array > ( > [id] => 2 > [user_id] => 1 > [itemno] => 123 > [acctcode] => 00-00 > [category_id] => 0950 > [start] => 2007-02-12 > [end] => 2007-02-19 > [editions] => A,B,D,Y > [specials] => > [dispname] => > [disptag] => > [dispcols] => 0 > [dispdepth] => > [text] => This is another test > classified > ) > > [1] => Array > ( > [id] => 3 > [user_id] => 1 > [itemno] => 11 > [acctcode] => 11-22 > [category_id] => 0950 > [start] => 2007-02-12 > [end] => 2007-02-12 > [editions] => A,B > [specials] => > [dispname] => > [disptag] => > [dispcols] => 0 > [dispdepth] => > [text] => Blah, another test! > ) > > ) > > ) > > > As you can see, this is just two test classified ads but, I deal with > thousands a week. I am afraid that this association will slow down my > site CONSIDERABLY. > > So, my question is, should I do a custom query() or should I make my > associations in a different way? > > Please, leave some feed back on your thoughts on how you would set > this up or, something I can do to limit what cake puts into the array. > > My ultimate goal with this helper is just to get an array of category > names, not the actual ad associated with the category. > > Thanks for reading, > Chris --~--~-~--~~~---~--~~ 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: Associations help - overriding primary key?
I have not tried doing this before but if I were to try I would first create duplicate model classes for the models needing a different primary key defined. There should be no reason why two model classes point to the same db table except that it seems weird. class ContactEmail extends AppModel { var $tableName = 'contacts'; var $primaryKey = 'emailAddress'; var $belongTo = ... } And override the various fields as needed and ditto for the MailMessage if needed. YMMV .... David Lloyd -- lloydhome consulting http://lloydhome.com On Feb 11, 2:05 pm, "Dan" <[EMAIL PROTECTED]> wrote: > Hi > > developing a very simple webmail app in cake and am having trouble > with the association between the MailMessage model and it's related > sender's Contact model. > > I want to relate the MailMessage as 'belongsTo' Contact via the > MailMessage and Contacts email field - only I can't seem to work out > how to do it, as it's automagically assuming that the field on the > Contact model is Contact.id. > > Can I override the primary key as follows? > > MailMessage.fromAddress = Contact.emailAddress > > I suspect, I've not fully understood associations and that there is a > much more striaghtforward way to do this :) > > Many thanks > > 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: How to use smarty cache in cakephp?
Quote from previous: If you use it should work as long as the tag is in the layout file. That means it is not working in the included views - like yours. It would not work anyway with your case as no controller would run to set $time. The dynamic part must come from session or other outside means. HTH, David Lloyd -- lloydhome consulting http://lloydhome.com On Feb 9, 10:57 pm, "rollenc" <[EMAIL PROTECTED]> wrote: > Thx, But I am puzzle in part cache. > I type this code: > controler: > var $view = 'Smarty'; > var $helpers = array('Cache'); > var $cacheAction = array('index' => 86400, 'view/' => 3600); > function index() > { > $this->set('posts', $this->Test->findAll()); > $this->set('time', date('H:i:s', time())); > } > In View > {#foreach from=$posts item=post#} > {#$post.Test.title#} > {#$post.Test.body#} > > {#foreachelse#} > There is nothing > {#/foreach#} > > > {#$time#} > > > Website: {#$smarty.server.SERVER_NAME#} > > Full page is cached. but nocache tag is ommited. > And the cache file as this: > > 03:46:08 > > > These is no parse.And the cache is no useful. > > What is correct? > > On 2月10日, 上午3时12分, "lloydhome" <[EMAIL PROTECTED]> wrote: > > > I have a SmartyView that handles caching by utilizing cake's page > > caching. It handles full-page caching great. If you use > > it should work as long as the tag is in the layout > > file. I have need for a cachable, non-static ajax call with no layout > > and this solution nor cake's default works for me. So I have an idea > > for that too but you'll need to be patient. > > > The file is athttp://www.lloydhome.com/files/smarty.ph_.txtandneeds > > to be renamed and placed in your /app/views directory. > > > To use in your controller: > > > var $view = 'Smarty'; > > var $cacheAction = 300; // 5 minutes > > var $helpers = array('Cache'); > > > HTH, > > > David Lloyd > > -- > > lloydhome consultinghttp://lloydhome.com > > > On Feb 9, 8:42 am, "lloydhome" <[EMAIL PROTECTED]> wrote: > > > > I also use Smarty but since it is a View and not recognized by the > > > core it is not advantageous to use its caching. I would argue that > > > this it actually better to not try without good reason. The problem > > > with this approach is the logic still occurs in the controller ad the > > > only time savings is in rendering the view. > > > > The SmartyView doesn't cache the output the way cake wants it but I > > > have some ideas on that I am going to try... It will be easy to setup > > > whole page caching but using will be harder. I'll post > > > back with what I find. > > > > David Lloyd > > > -- > > > lloydhome consultinghttp://www.lloydhome.com > > > > On Feb 9, 4:39 am, "rollenc" <[EMAIL PROTECTED]> wrote: > > > > > I combine smarty & cackephp followng this article: http:// > > > > projects.simpleteq.com/CakePHP/smarty.html > > > > but I don't know how to use smarty cache . > > > > Call for help. Thanks. --~--~-~--~~~---~--~~ 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: Component can't create a model
Assuming you are running on v1.2, you now have to specify loadModel('Session'); before allocating a model not specified in the uses array. Models are no longer automatically loaded but are loaded only as needed to improve performance. HTH, David Lloyd -- lloydhome consulting http://lloydhome.com On Feb 10, 6:05 am, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote: > I'm playing around with usermgmt from the cakeforge > > The component auth.php is having problems with this... > > $session = &new Session; > > I have session.php in my models directory and it all looks good. From > my research I can see that this should be valid. > > However the error I get is Cannot instantiate non-existent class: > session in ... > > Any ideas? --~--~-~--~~~---~--~~ 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: How to use smarty cache in cakephp?
I have a SmartyView that handles caching by utilizing cake's page caching. It handles full-page caching great. If you use it should work as long as the tag is in the layout file. I have need for a cachable, non-static ajax call with no layout and this solution nor cake's default works for me. So I have an idea for that too but you'll need to be patient. The file is at http://www.lloydhome.com/files/smarty.ph_.txt and needs to be renamed and placed in your /app/views directory. To use in your controller: var $view = 'Smarty'; var $cacheAction = 300; // 5 minutes var $helpers = array('Cache'); HTH, David Lloyd -- lloydhome consulting http://lloydhome.com On Feb 9, 8:42 am, "lloydhome" <[EMAIL PROTECTED]> wrote: > I also use Smarty but since it is a View and not recognized by the > core it is not advantageous to use its caching. I would argue that > this it actually better to not try without good reason. The problem > with this approach is the logic still occurs in the controller ad the > only time savings is in rendering the view. > > The SmartyView doesn't cache the output the way cake wants it but I > have some ideas on that I am going to try... It will be easy to setup > whole page caching but using will be harder. I'll post > back with what I find. > > David Lloyd > -- > lloydhome consultinghttp://www.lloydhome.com > > On Feb 9, 4:39 am, "rollenc" <[EMAIL PROTECTED]> wrote: > > > I combine smarty & cackephp followng this article: http:// > > projects.simpleteq.com/CakePHP/smarty.html > > but I don't know how to use smarty cache . > > Call for help. Thanks. --~--~-~--~~~---~--~~ 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: Change content on frontpage ?
Putting code in app/pages/... is not going to get you your notes as the NotesController (or some other controller you write) will need to be called. As is, the PagesController is being called and it does not get your notes. Following the tutorial you mentioned, you would want a page in /app/ views/notes/default.thtml and a method in NotesController called default() to get the notes. Or if you want to use the scaffold generated index, change your application app/config/routes.php to point "/" to "/notes/index". All of this is explained in the manual http://manual.cakephp.org - you really need to read it through several times to catch everything. HTH, David Lloyd -- lloydhome consulting http://lloydhome.com On Feb 9, 7:02 am, "Mr.Blue" <[EMAIL PROTECTED]> wrote: > HI there, > > Would you like to show me how could I use $scaffold on front page of > Cake PHP. I place this code on /app/pages/default.html in order to > list the notes on the front page. Such as:http://localhostinstead > ofhttp://localhost/notesas usual > (I follow this tutorial:http://www.sitepoint.com/article/application- > development-cakephp) > > My Notes > > >Id >Title >Created > > > > > > > > > > > > > > > However, cakePHP threw some errors. I read manual carefully, but it > doesn't mention how could I implement database to the front page. > Please help me. > > Thank you very much ! > Best Regards --~--~-~--~~~---~--~~ 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: How to use smarty cache in cakephp?
I also use Smarty but since it is a View and not recognized by the core it is not advantageous to use its caching. I would argue that this it actually better to not try without good reason. The problem with this approach is the logic still occurs in the controller ad the only time savings is in rendering the view. The SmartyView doesn't cache the output the way cake wants it but I have some ideas on that I am going to try... It will be easy to setup whole page caching but using will be harder. I'll post back with what I find. David Lloyd -- lloydhome consulting http://www.lloydhome.com On Feb 9, 4:39 am, "rollenc" <[EMAIL PROTECTED]> wrote: > I combine smarty & cackephp followng this article: http:// > projects.simpleteq.com/CakePHP/smarty.html > but I don't know how to use smarty cache . > Call for help. Thanks. --~--~-~--~~~---~--~~ 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: Problems with generateList and selectTag ... generateList adding a "Where" clause that I don't want...
Shouldn't getList be more like function getList() { $return = $this->generateList(null,null, 100,'{n}.App.app_id','{n}.App.app_name'); $this->set('return',$return); // not sure what you are trying here but it probably isn't setting $return return $return; } HTH, David Lloyd -- lloydhome consulting http://lloydhome.com On Feb 7, 7:06 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote: > Hey everyone, > > I've been trying to find an answer to this all day with no luck, so I > thought I'd poll the great minds on this list to see if anyone knows > what's going on here... > > What I've got: I'm working on a service request form, trying to build > a drop down selection box on the web form using data from a table > (Model) that is not part of my current Model/Controller/View. The > data resides in the Model "App" and I'm using the Model "Request". > What I'm trying to do is grab all the values (rows) from > App.app_name. (This table is very simple, it has two columns "app_id" > and "app_name".) > > Basically I want the selectTag method to build a selection box with > the query SELECT app_name FROM apps, the problem is that cakePHP is > constructing a query like SELECT app_name FROM apps WHERE request_id = > 'x' > > What I've tried: I've tried adding: > > var $hasMany = array('App' => array( > > 'className'=> 'App', > > 'conditions' => null, > > 'order'=> null, > > 'limit' => null, > > 'foreignKey' => 'app_id', > > 'dependent'=> false, > > 'exclusive' => false, > > 'finderQuery' => '' > ) > ); > > This code causes the where clause to be inserted where I do not want > it to be. > > I also have this in my Results Controller file to try and assign the > data into a variable to be used in my view: > > $this->set('list',$this->Request->App->getList()) < which calls a > function in my App controller that looks like: > > function getList() { > $this->set('return', $this->generateList(null,null, > 100,'{n}.App.app_id','{n}.App.app_name'); > return $return; > > } > > So my first problem is how in the world do I force this to pull back > the entire contents inside the apps table (there are only four rows in > this table, so it's not a lot of data). > > Then my second problem is getting a select box built with selectTag? > Currently I have this in my code: > > $html->selectTag('Request/App/app_name', > $list',null,array(),null,false,false) > > but of course, that's not working right now. > > This post may be a bit fragmented right now, so if anyone has any > thoughts on how to sort all of this out but needs more info, please > let me know! > > Thank you! > > --Patrick Holt --~--~-~--~~~---~--~~ 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: Passing non-model variables from controller to view to setting and retreiving HTML form tags
See http://manual.cakephp.org/chapter/controllers under 'Interacting with your Views' describes the controller's method 'set' HTH, David Lloyd -- lloydhome consulting, inc. http://www.lloydhome.com On Feb 7, 3:07 pm, "Daghe9193" <[EMAIL PROTECTED]> wrote: > Hello I am new to Cake and MVC, so please excuse my terminology. > > What is the easiest way to pass non-model variables back and forth > from the view and the controller for setting and retrieving HTML > control values, such as the checkbox? I need to add a currency > checkbox to the index view which will determine whether a price column > is displayed in Euro's or U.S. Dollars. The checkbox method of the > html helper class appears to be model specific. --~--~-~--~~~---~--~~ 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: Passing back a dynamically generated image
I do it quite often. I have sites that generate images from gd and sites that use ChartDirector. In the controller turn off the rendering engine $this->autoRender = false; or $this->layout = ''; You might have to set the MIME type if JPGraph doesn't header("Content-type: image/png"); // or jpeg or gif, etc. then output it print($c->makeChart2(PNG)); HTH, David Lloyd -- lloydhome consulting, inc. http://www.lloydhome.com On Feb 5, 8:00 am, "Macademic" <[EMAIL PROTECTED]> wrote: > I am trying to get JPGraph working in Cake as a vendor. > > I have changed any references to include, include_once, require_once > in the latest JPGraph distribution so there are no errors from nested > include files. My problem is that if I send the output of the > graphing function (i.e. using the $graph->Stroke() call at the end) > the data for the img just gets included in the page rather than being > rendered. > > So, how do I send back the img file to Cake? Really, what I need is > some way to stop the default.thtml file being used to spit back the > data from the file in this particular function is called. Can you do > that in Cake? > > I tried using requestAction in my controller to pass the code back but > it still does not work. > > Any suggestions? --~--~-~--~~~---~--~~ 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: legacy data
I think all you will need is to first verify that your User model can access users and your Product model can access products from their respective databases. Then create your association between the two as normal. The difference is that you should set the 'external' attribute to true in the association. i.e.: var $hasMany = array('Product'=>array('className'=>'Product','external'=>true,'foreign_key'=>'user_id'); HTH, David Lloyd -- lloydhome consulting, inc. http://www.lloydhome.com On Feb 5, 10:05 am, "lukemack" <[EMAIL PROTECTED]> wrote: > hi, > > i'm going to need to access some legacy data from another system in my > cake app. i understand that i can add an additional database > connection in the database config file and have the model use that > connection. however, if i then need the data in a legacy database > (e.g. product data) to relate to models in the main cake app database, > how is this best achieved? > > an example: I have a users table and a reviews table in my cake app in > the 'cakeApp' database. I need to associate a product review with a > user. Product data is stored in the products table in the 'legacyData' > database. how do i associate my user and review models with the legacy > product data? the legacy data is not aware of cakePHP and therefore > doesn't have foreign keys etc. configured correctly. > > any thoughts gratefully received. would it, for example, be a good > idea to create a view of the legacy data (the database kind of view) > in the cakeApp database? is that even possible in mySQL? > > many thanks, > > lukemack. --~--~-~--~~~---~--~~ 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: A Super Release
With the holidays over we have been getting ready to upgrade our production systems to 1.1.12. Now with '13 out the pressure is on. >From reading this list there are still many on 1.1.10 or even earlier. Here is one way we have reduced our workload and code complexity. I do not like littering the 'uses' array with unnecessary models and it defeats the lazy loading if you only need a model in some circumstance. In AppController: function & constructModel($modelname) { if (!class_exists($modelname)) { loadModel($modelname); } $m = new $modelname(); return $m; } function usesModel($modelname) { if ( !isset($this->{$modelname})) { if (!class_exists($modelname)) { loadModel($modelname); } $this->{$modelname} = new $modelname(); } } Then in the code I use constructModel like $auser = $this->contructModel('User'); // instead of $auser = new User(); or $this->usesModel('User'); // instead of $this->User = new User(); David Lloyd -- Lloydhome Consulting, Inc. http://www.lloydhome.com On Feb 5, 3:31 am, "Dr. Tarique Sani" <[EMAIL PROTECTED]> wrote: > On 2/5/07, cdomigan <[EMAIL PROTECTED]> wrote: > > > One question I have is what is the easiest way to upgrade to the > > latest version. Can I just copy my whole app folder across? Or do I > > need to just copy the user files I have created? > > Just rename the old cake folder and upload a new cake folder - try out > if everything works and then delete the renamed old cake folder - you > need not touch your app > > Cheers > Tarique. > > P.S. In most cases everything works as supposed to :) > > -- > = > PHP for E-Biz:http://sanisoft.com > Cheesecake-Photoblog:http://cheesecake-photoblog.org > = --~--~-~--~~~---~--~~ 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: Existing Projects
It certainly works! One of my client's database was built before I took over. It used to be spaghetti-code PHP that I have (mostly) converted to CakePHP. This database has as primary keys user_id, j_id, prodid, etc. A foreign key to user_id may be j_owner and to prodid is rfc_prodid. You have to specify the primary key's name and in the associations specify foreign key's name. It is more work but does work nicely. One caveat is how the magic functions work. Just remember how the conventions work and you'll do okay. To find the user_id use $this- >User->findByUserId(1) because the capital I means there is a _. To find by prodid use $this->Product->findByProdid(1). Notice no capital I prodid as there is no _. HTH, David Lloyd On Jan 26, 10:43 pm, "Chris Hartjes" <[EMAIL PROTECTED]> wrote: > On 1/26/07, Erich C. Beyrent <[EMAIL PROTECTED]> wrote: > > > > > Well, for instance, tables that have a primary key of ID instead of id, > > or perhaps even UserID. It's the modeling of the database that concerns > > me - what I need to do to get the models to work.Others can confirm or deny > > this for me, but I'm pretty sure you can > override some of the default values that the Cake models use for > primary key. I know you can do it in Rails (I have done so with > legacy tables). > > -- > Chris Hartjes > > My motto for 2007: "Just build it, damnit!" > > rallyhat.com - digitial photo scavenger hunt > @TheBallpark -http://www.littlehart.net/attheballpark > @TheKeyboard -http://www.littlehart.net/atthekeyboard --~--~-~--~~~---~--~~ 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: This->query output
Phil, For most things it is better to have the data the way it is returned. I would encourage you to work within the framework and not against it. That said, maybe you have some logic that is legacy like I do. I am porting a clumsy mess of code into Cake but it cannot be done all at once. I have old methods that want the data in a flat associative array as you describe. In my AppModel class I put: /** * Totally flatten an array. */ function & array_flatten(&$array) { if (is_array($array)) { $newarray = array(); foreach ($array as $k=>$v) { if (is_array($v)) { $newarray += $this->array_flatten($v); } else $newarray[$k] = $v; } return $newarray; } return $array; } Then to use: $newarray = array(); foreach ($results as $v) { $newarray[] = $this->User->array_flatten($v); } HTH, DL --~--~-~--~~~---~--~~ 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: Fetching data with join over 3 tables with recursive association query
Well, it seems I have found the previously reported Trac #633. The partial workaround mentioned by elsigh is clumsy, messy, and may not work for some implementations but has the advantage of actually working without changing core code. My implementation requires a proper recursion depth to be specified but it automagically gets the query right. The implementation proposed in #633 may not require a recursion to be set but requires the path. I think the both have merit. So the difference in my case is between $this->User->findAll(array('Region.region_name','Canada'),null,null,null,1,3); and $this->User->findAll(array('Subarea.Area.Region.region_name','Canada')) Can I get comments from 'those in the know' on which way this should be implemented? Is there work occurring on #633? If so, I would like to know the strategy so my code won't break. If not, I can clean up my implementation to work the way it should and submit it. Thanks, David --~--~-~--~~~---~--~~ 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: Fetching data with join over 3 tables
I have used CakePHP for several months and answered a few posts without needing to post and I probably don't need to now but I cannot find the answer. I have tried setting the recursive var to 2, 3, 4, 5 and no help to my problem. I have a User model that has a belongsTo a Subarea that belongsTo an Area that belongsTo a Region. The associations are corret (I think) because the recursion works in the case described above. My problem is when a field is in a condition that is not 'close' to the first model. regions -- region_id int primary key, region_name varchar(50) not null unique key ...snip... areas -- area_id int primary key, area_regionid int references regions(region_id), area_name varchar ... ...snip... subareas -- subarea_id int primary key, subarea_areaid int references areas(area_id), subarea_name varchar ... ...snip... users -- u_id int primary key, u_subareaid int references subareas(subarea_id), login_name varchar(50) not null unique key, ...snip... class Region extends AppModel { var $name = 'Region'; var $primaryKey = 'region_id'; var $hasMany = array( 'Area'=>array('className'=>'Area','association'=>'Area','foreignKey'=>'area_regionid') ); } class Area extends AppModel { var $name = 'Area'; var $primaryKey = 'area_id'; var $belongsTo = array('Region'=> array('className'=>'Region','association'=>'Region', 'foreignKey'=>'area_regionid') ); var $hasMany = array( 'Subarea'=>array('className'=>'Subarea','association'=>'Subarea','foreignKey'=>'subarea_areaid') ); } class Subarea extends AppModel { var $name = 'Subarea'; var $primaryKey = 'subarea_id'; var $recursive = 2; var $belongsTo = array('Area'=> array('className'=>'Area','association'=>'Area', 'foreignKey'=>'subarea_areaid') ); // ...snip business logic... } class User extends AppModel { var $name = 'User'; var $belongsTo = array('Subarea'=> array('className'=>'Subarea','association'=>'Subarea', 'foreignKey'=>'u_subareaid') ); var $primaryKey = 'u_id'; // ...snip business logic... } if I query from my controller ... $result_count = $this->User->findCount(array('Region.region_name'=>'Canada'), 4); I get an error in this generated query: SELECT COUNT(*) AS count FROM `users` AS `User` LEFT JOIN `subareas` AS `Subarea` ON `User`.`u_subareaid` = `Subarea`.`subarea_id` WHERE (`Region`.`region_name` = 'Canada') 1109: Unknown table 'Region' in where clause If I commit a cardinal sin and modify dbo_source.php and insert the following 10 lines into the read method before the comment here: //DAL: HACK in recursive query joins! if ($model->recursive > 1) { foreach($model->__associations as $type) { foreach($model->{$type} as $assoc => $assocData) { $linkModel =& $model->{$assocData['className']}; $this->__dal__generateRecursiveQuery($model, $linkModel, $queryData, $model->recursive); } } } ---> before // Build final query SQL and add the methed mentioned: function __dal__generateRecursiveQuery(&$model, &$linkModel, &$queryData, $recursive) { if ($recursive>0) { foreach($linkModel->__associations as $type) { foreach($linkModel->{$type} as $assoc => $assocData) { $newLinkModel =& $linkModel->{$assocData['className']}; $external = isset($assocData['external']); $null=null; if ($newLinkModel && $model->useDbConfig == $newLinkModel->useDbConfig) { $this->generateAssociationQuery($linkModel, $newLinkModel, $type, $assoc, $assocData, $queryData, $external, $null); $this->__dal__generateRecursiveQuery($model,$newLinkModel,$queryData,$recursive-1); } } } } } It gets better. Now modify the REALLY weird code in the __filterResults method if (isset($model->{$className}) && is_object($model->{$className})) { $data = $model->{$className}->afterFind(array(array($key => $results[$i][$key]))); } else { //DAL: this makes no sense. The 'if' above proves it is not an object to call ... //DAL: $data = $model->{$className}->afterFind(array(array($key => $results[$i][$key]))); $data[0][$key]=& $results[$i][$key]; } AND IT WORKS! But I get suspicious when I go modifying the core One caveat to my
Re: View caching
I appreciate your pointing this out to me. Especially since I have read everything I can find about CakePHP but I have never seen any documentation for this. PEAR::Cache_Lite has a 4 year history of improvement, stability, and speed. Other than the complete obscurity of Cake's cache (which now I know its name a simple search reveals it is in basics.php) are there any benefits besides being able to use in an environment where PEAR is not allowed? Sorry for the flame bait. I think the simplest workable solution is best. So when I wanted a local cache I loked at Cake first. Seeing the docs for Cache model and no reference of any other, I thought that was it. If I had seen docs I would have used it. If I found NO docs on caching I would have asked. Lorenzo: I avoided the Cache Model class because of the DB calls. There is nothing intrinsically wrong with it. In some situations you may atually want that. I just wanted a local cache that need not hit the network or database. Thanks, David --~--~-~--~~~---~--~~ 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: View caching
For lengthy operations I create a method in the model and cache the results. Say I have sale people whose main portal page contains action items, deals about to close, closed deals, and current prospect status. This data is referenced slightly different ways in various parts of the app. Also, this main page is shown repeatedly through the session when the user is navigating. Parts of the data can update alot, others rarely. so closed deals changes rarely (less than once a day) but the query is real harsh: class Revenue extends AppModel { function getRevenue( $country, $region, $year ) { $cache =& $this->getCache(); // constructs Cache_Lite object $cachedata = $cache->get("$country-$region-$year",'revenue'); if ($cachedata === false) { $revenue = array(); // do big query here // populate $revenue with results optimized for reuse $cache->save( serialize($revenue) ); } else { $revenue = unserialize($cachedata); } // allow getCache to not reconstruct // if needed again soon $this->releaseCache($cache); return $revenue; } } Part of my AppModel: define('_APPMODEL_CACHE_DEFAULT_TIME_', HOUR * 15); class AppModel extends Model{ var $_cache = null; const CACHE_DEFAULT_TIME = _APPMODEL_CACHE_DEFAULT_TIME_; function & getCache() { if (!$this->_cache) { $cache = $this->createCache(); } else { $cache = $this->_cache; } $this->_cache = null; return $cache; } function & createCache($lifetime=AppModel::CACHE_DEFAULT_TIME) { $options = array( 'cacheDir' => APP.'tmp/cache/persistent/', 'lifeTime' => $lifetime, 'pearErrorMode' => CACHE_LITE_ERROR_DIE, 'fileNameProtection' => false ); $cache = new Cache_Lite($options); return $cache; } function releaseCache(&$cache) { $this->_cache = & $cache; } } and you can do the same with other data on the page. ALL of my simple lookups that are database tables that change rarely are cached and retrieved this way so no form has to do constant DB lookups just to get a list of product codes, countries, whatever. Stay off of your database as much as possible and yor scalability soars. HTH, David --~--~-~--~~~---~--~~ 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: View caching
I agree that smarty is a great drop in view replacement for cake and it is what I use. However, for user specific differences, my best bang for the buck has been long term model caching. I use Pear's Cache_Lite in my model classes where I know a lengthy operation can be cached. I create accessor method in the model which performs the query(ies) and caches the results for several hours. If you categorize your caches correctly, then you can invalidate only the ones affected by a data change. The advantages I get are some caches are 5 minutes, some are 15 hours - I decide how long based on the data stored. Many times what I store is not table data but end result of large calculations specific to my needs. Pages that would take 5+ seconds to load everytime now take 3 seconds on the first hit and <1 for subsequent hits by the same user (Iknow it doesn't add up, it reuses other caches). Also the advantage is storing the caches on the local file system. That way multiple webservers have local caches and do not hit the network or database to get a result - except when the cache is stale. HTH, David --~--~-~--~~~---~--~~ 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: formatting model values
I think it is a matter of taste and how you want to use it. The simple solutions are if it is view-centric then a simple helper might do the trick. The other is to create a lookup table in the database, a model, and hookup the associations. HTH, David --~--~-~--~~~---~--~~ 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: Just starting.. mod_rewrite behaviour?
Have you tried $this->redirect('/downloads/index'); HTH, David --~--~-~--~~~---~--~~ 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: Errorviews with Smarty View class ( 1.1 )
I use var $view = 'Smarty'; in app_controller.php. This doesn't do any better than your results though. I have had limited success copying cake/libs/view/templates/errors to app/views. I have not taken the time to figure it out yet (on the bottom of a long list). Hope That Helps, David --~--~-~--~~~---~--~~ 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: pretty code.
You can achieve what you want if you use Smarty as the template engine. I currently do {if_user_allowed access=some/protected/resource} {$html->link('New Case','/ccases/add')} {/if_user_allowed} I had to write the if_user_allowed plugin but they are extremely easy in 20-30 lines. HTH, David --~--~-~--~~~---~--~~ 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: Pulling data to the home page
I think AD7six was referring to your comment of wanting to use getUserList as an AJAX call. With AJAX, you would want to set your layout to something bare so you do not get the full page layout. RequestHandler would take care of some of this but not for this case AFAICT. In getUserList() call $this->layout = ''; or set it to 'ajax' or other bare layout. This way it works for ajax and for when you call it via requestAction. HTH, David --~--~-~--~~~---~--~~ 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: Map non-cake PHP files to a default controller like PagesController
There is no old() method. See the pages controller to see how the display() method gets called for everything and parses the path info itself. As far as placing it in the webroot/content: you might get that to work ... dunno and don't really wanna try ... maybe by playing with $viewPath or filename. Might be easy enough to create a views/spages/default.thtml that has include "/path/to/webroot/content/$myfilename" and have the controller $this->set('myfilename', ) But your milage may vary :/ HTH, David --~--~-~--~~~---~--~~ 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: Map non-cake PHP files to a default controller like PagesController
I moved all of my legacy files to the view directory of my controller. I then added this to the top of my .htaccess RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} ^(.*)php$ RewriteRule ^(.*)\.php$ index.php?url=/spages/old/$1 [QSA,L] where Spages is my controller and my legacy files are in views/spages/old/ Esentially, Spages is a secure Pages controller with extra logic. I copied what I needed from pages_controller (most of it) and added my extra logic, beforeFilter, etc. The code from pages controller takes care of the old files and your extra logic for session authentication and such is the extra logic. I have some files that render Excel or PNG and don't want the layout around it. So in the controllers display() method set $this->layout='' for those files. This is a pretty quick and dirty way to do it without fighting the framework. HTH, david --~--~-~--~~~---~--~~ 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: Lookup Values (Scaffolding)
I think you want in the State model var $displayField = 'value'; if state_id is setup as a foreign key to State.id. --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---