Re: find('first') query cakephp1.2 vs 1.3
$data = $this-User-read(null, 4); that is the official way to get one row.. another possible ways: $this-User-findById(4); $this-User-find('first', array('conditions' = array('User.id' = 4))) bye, gonzalo On 2 jun, 09:09, bram brammele...@gmail.com wrote: I'm porting my app from cakephp 1.2 to 1.3 and followed all steps in the migration guide. Still having troubles with find queries. I have quite some queries doing: $this-User-id = 4; $data = $this-User-find('first'); Cake 1.2 builds the following query: SELECT `User`.`id`, FROM `users` AS `User` WHERE `User`.`id` = 4 ORDER BY `name` ASC LIMIT 1 Cake 1.3.1 builds a different query: SELECT `User`.`id`, FROM `users` AS `User` WHERE 1 = 1 ORDER BY `name` ASC LIMIT 1 I just get the first record, but not the one that matches the set id. I like the short and readable notation of this query. Is this a wrong way of retreiving model data? Should I go for the long notation (including the conditions option that tells find to search for User.id = 4) ?? Or is it a cake bug? Bests, Bram 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
Caching with new find methods
Hi to everyone, im moving/converting all my getFromUser() methods from my models to: find('fromUser') because now its the new cakephp way, so well.. but the problem that i find here is that i cannot assign the caching logic to this methods, because the only things that them do is to prepare the query and the params for the real find method. Is there a way to combine this logic or i have to make a wrapper over the new _findBlabla methods to make Caching logic. For ex. public function getFromUser($userId) { $cacheKey = 'blabla_from_users_' . $userId; if (($results = Cache::read($cacheKey)) === false) { $results = $this-find('fromUsers', array('conditions' = array('User.id' = $userId))); Cache::write($cacheKey, $results); } return $results; } It would not be convenient to have a way to exit the _find behavior in the before state, so that this can be accomplished? libs/model/model.php line 1787 (rc3) if ($type != 'all') { if ($this-_findMethods[$type] === true) { $query = $this-{'_find' . ucfirst($type)}('before', $query); } } maybe if the query has a return key, and assuming that it comes with a value different than null (or false), the function will directly return this. Only weird ideas... Thanks in advance, gonzalo --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Paginating inside admin in new 1.2 release
Using the latest svn version i was making a simple paginated list inside the admin section: it was called from: /admin/news/index the code used in the controller is: function admin_index() { $news = $this-paginate('News'); $this-set('news', $news); } the view code (with paginator helper) is simple from my point of view: tr th?php echo $paginator-sort('Id', 'id');?/th th?php echo $paginator-sort('Categoru', 'category_id');?/th th?php echo $paginator-sort('Titlte', 'title');?/th th?php echo $paginator-sort('Date', 'created');?/th /tr the problem here is that the url formed by Router is not extracting the admin_ part from the url, so the link points here: /admin/news/admin_index/page:1/sort:category_id/direction:asc this obviously generates an error because admin_index is pointed to admin_admin_index method, that doesn't exists. If i forced the action with this: $this-paginate['options']['action'] = 'index'; the link now is well formed but the direction clause is never changed, getting all the time the Ascending direction. I look throught the Router code and i didn't found anything strange, i tried to modify the lines 674 to 680 in cake/libs/router.php with this hackish and ugly code only to see if works: if ($admin) { if (!isset($url[$admin]) !empty($params[$admin])) { $url[$admin] = true; if (substr($url['action'], 0, 6) == 'admin_') $url['action'] = str_replace('admin_', '', $url['action']); } elseif ($admin array_key_exists($admin, $url) ! $url[$admin]) { unset($url[$admin]); } } and now everythings works fine, i know that this isn't the better solution, but i run all the controller and paginator helper tests and all passes. It's to late here in argentina and i'm still at work, when i arrive home i'll be looking to create some tests that reproduce this ¿bug? or im missing something? Thanks in advance gonzalo --~--~-~--~~~---~--~~ 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: Testing controllers again - using 'test' DB config
What i've done is to modified the app_model _construct for this: function __construct($id = false, $table = null, $ds = null) { parent::__construct($id, $table, $ds); if (defined('APP_TEST_CASES')) { $this-useDbConfig = 'testSuite'; } } APP_TEST_CASES is a constant defined in test.php so i feel is a secure way of doing this, although im sure is not the best way of doing it. On 10 oct, 08:50, Dr. Tarique Sani [EMAIL PROTECTED] wrote: Am using a fairly recent 1.2 In my test I have a statement like $this-testAction('/posts/index'); I would expect that the Post model (inside the Posts controller) would use the test DB config while testing but it does not uses the 'default' instead I can't seem to find a simple way to do the same... I think I am missing something obvious - If someone can enlighten it would be a help TIA Tarique -- = Cheesecake-Photoblog:http://cheesecake-photoblog.org PHP for E-Biz:http://sanisoft.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 -~--~~~~--~~--~--~---
RequestAction in 1.2 with Admin Routing
When calling requestAction from an admin method (for example admin_edit()), cake automatically adds /admin to the method. For example function admin_edit() { $this-requestAction('/users/writeConfig'); } looks for: /admin/users/writeConfig in 1.1 requestAction didn't adds the admin prefix, to call a protected method one has to added it by hand like $this-requestAction('/admin/users/writeConfig'); is this a planned changed? there is a way of calling a not admin method from one that it is? cake team, you need a ticket for this? Thanks in advance, gonza --~--~-~--~~~---~--~~ 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: RequestAction in 1.2 with Admin Routing
I usually write thigs without sense... solved, my problem kill me, but do it quickly.. thanks! gonzalo On Aug 29, 5:13 pm, Gonza [EMAIL PROTECTED] wrote: When calling requestAction from an admin method (for example admin_edit()), cake automatically adds /admin to the method. For example function admin_edit() { $this-requestAction('/users/writeConfig'); } looks for: /admin/users/writeConfig in 1.1 requestAction didn't adds the admin prefix, to call a protected method one has to added it by hand like $this-requestAction('/admin/users/writeConfig'); is this a planned changed? there is a way of calling a not admin method from one that it is? cake team, you need a ticket for this? Thanks in advance, gonza --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Question about validation in model
When using model-validates($data), the lines of code that execute the validation are: foreach($this-validate as $field_name = $validator) { if (isset($data[$field_name]) !preg_match($validator, $data[$field_name])) { $this-invalidate($field_name); } } the problem with this is that if the variables is not defined, is not validated, something weird, because if i told that a variable has to be NOT_EMPTY and is not defined no error is thrown. This behaviour is normal and i have to defined the variable always or as i think when the variables were not defined model has to mark them as not valid? Thanks! Gonza --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Stripescape in 1.1.15.5144
Just update the cake version, and notice some strange behaviour, when i pass number or boolean params in my routes, php throws warnings and notices: Warning: Invalid argument supplied for foreach() in C:\_wwwroot\system \include_path\cake\libs\router.php on line 210 Notice: Undefined variable: return in C:\_wwwroot\system\include_path \cake\libs\router.php on line 219 Looking at router.php i realize that the problem was in stripEscape(), the function is: function stripEscape($param) { if(is_string($param) || empty($param)) { $return = preg_replace('/^ *-!/', '', $param); return $return; } foreach($param as $key = $value) { if(is_string($value)) { $return[$key] = preg_replace('/^ *-!/', '', $value); } else { foreach ($value as $array = $string) { $return[$key][$array] = preg_replace('/^ *-!/', '', $string); } } } return $return; } So, when a number or a boolean is passed, nothing capture it. I never upload a bug to trac, and i dont know if this is really a bug, so i ask it here first. What do you think? Byes, Gonzalo PD: my ugly patch function stripEscape($param) { if(is_string($param) || empty($param)) { $return = preg_replace('/^ *-!/', '', $param); return $return; } if (is_numeric($param)) { return (int) $param; } if (is_bool($param)) { return (bool) $param; } if (is_array($param) count($param) 1) { foreach($param as $key = $value) { if(is_string($value)) { $return[$key] = preg_replace('/^ *-!/', '', $value); } else { foreach ($value as $array = $string) { $return[$key][$array] = preg_replace('/^ *-!/', '', $string); } } } return $return; } } --~--~-~--~~~---~--~~ 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: Stripescape in 1.1.15.5144
Always late... thanks! On May 24, 1:46 pm, Larry E. Masters aka PhpNut [EMAIL PROTECTED] wrote: Fixed yesterday in the core: https://trac.cakephp.org/changeset/5163 -- /** * @author Larry E. Masters * @var string $userName * @param string $realName * @returns string aka PhpNut * @access public */ --~--~-~--~~~---~--~~ 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 arguments to a nested element
Hi Mariano, Gracias. Like you said, it's not the most elegant solution but it'll probably work. Thanks! Gonzalo On Apr 21, 8:55 pm, Mariano Iglesias [EMAIL PROTECTED] wrote: You can do it through a quick hack, though it is not very elegant. Let's say that on your view you have: ?php echo $this-renderElement('element1', array('arg1' = 'Hello', 'arg2' = 'World')); ? And element1 includes element2. Element2 looks like: ?php echo $arg1 . ' ' . $arg2; ? Then the hack is to make element1 look like: ?php $loaded = am(array_keys($this-viewVars), array_keys($this-loaded)); $args = array_diff_key($___dataForView, array_flip($loaded)); echo $this-renderElement('element2', $args); ? -MI --- Remember, smart coders answer ten questions for every question they ask. So be smart, be cool, and share your knowledge. BAKE ON! blog:http://www.MarianoIglesias.com.ar De: cake-php@googlegroups.com [mailto:[EMAIL PROTECTED] En nombre de Gonzalo Servat Enviado el: Sábado, 21 de Abril de 2007 08:35 p.m. Para: cake-php@googlegroups.com Asunto: Re: Passing arguments to a nested element .. but not quite the solution I was looking for. What I'm trying to avoid is having to specifically write each and every variable in either method. I was hoping for a way to grab them all and send the arguments to the next renderElement call. Maybe I understood how to use compact? I'd really appreciate an example. --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Cake assumption with params
In controller.php line 262 Cake make this assumption: 259 function constructClasses() { 260 if (empty($this-params['pass'])) { 261 $id = false; 262 } else { 263 $id = $this-params['pass']['0']; 264 } this means that ALWAYS the first param received by GET is the model Id, is this a bug? Because i want to use the first param for other thing but cake loads my model with the id so i update my data instead of inserting a new one. Would be nice if this assumption is configurable. Any ideas? Thanks in advance! --~--~-~--~~~---~--~~ 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: Cake assumption with params
ok thanks for response i was looking for something like create(), but i dont have the time to read the api documentation yet. 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 -~--~~~~--~~--~--~---