Re: Picture Upload with Resize to MySQL
Clemens, Use $this->data['Picture']['File']['tmp_name'] as src, create a scaled image file and use it to set up $this->data['Picture']. Here's the function I use: private function scaleImage($srcpath, $args) { // cache functionality, no extra charge if (file_exists($args['filepath'])) { return; } // create src image, depending on image_type switch ($args['image_type']) { case IMAGETYPE_JPEG: $srcimg = imagecreatefromjpeg($srcpath); break; case IMAGETYPE_GIF: $srcimg = imagecreatefromgif($srcpath); break; case IMAGETYPE_PNG: $srcimg = imagecreatefrompng($srcpath); break; default: return; // unknown type, so can't create new file } if ($srcimg === false) { return; // error reading src image } // create dst image $dstimg = imagecreatetruecolor($args['width'], $args['height']); if ($dstimg == null) { imagedestroy($srcimg); return; // error creating dst image, so can't create new file } // copy image imagecopyresampled($dstimg, $srcimg, 0, 0, 0, 0, $args['width'], $args['height'], $args['orig_width'], $args ['orig_height']); // save dst image, depending on image_type switch ($args['image_type']) { case IMAGETYPE_JPEG: imagejpeg($dstimg, $args['filepath'], 40); break; case IMAGETYPE_GIF: imagegif($dstimg, $args['filepath']); break; case IMAGETYPE_PNG: imagepng($dstimg, $args['filepath']); break; default: break; // can't happen--we switched on type earlier } // destroy both images, clean up imagedestroy($srcimg); imagedestroy($dstimg); } On Jun 2, 2:26 am, "Clemens K." wrote: > hi. > > i can already upload pictures to my mysql database in blob format. i > want to add an automatical resize when uploading. my code: > > $fileData = fread(fopen($this->data['Picture']['File']['tmp_name'], "r > +"), $this->data['Picture']['File']['size']); > > $this->data['Picture']['name'] = $this->data['Picture']['File'] > ['name']; > $this->data['Picture']['type'] = $this->data['Picture']['File'] > ['type']; > $this->data['Picture']['size'] = $this->data['Picture']['File'] > ['size']; > $this->data['Picture']['data'] = $fileData; > > $this->Picture->save($this->data); > > how can i implement a resize function now? does someone have any idea > and some code? :) > > thanks and regards, > clemens --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Re: Tinyints cause big problems
Ok. Trying to save some bytes is old school. But "I know this is documented?" Why waste the time typing it if you can't cite a source? Where is it documented, and for that matter where are these imaginary "CakePHP conventions" documented? The cookbook mentions tinyint only the context of forms. The api is silent. Golding (Beginning CakePHP) and Chan/Omokore (Practical CakePHP Projects) don't have tinyint in their indexes. You might have been referring to trac ticket #1253, which described the bug I ran into. It was written up three years ago, in some detail, but was promptly closed by Nate, who wrote "Cake interprets MySQL tinyint(1) fields as virtual boolean fields, which can only have a value of 0 or 1 (true or false). Use a different column type if you don't want this behavior." In March 2008, another user tripped on the same problem and wrote ticket #3903. Nate closed that, too. Google 'cakephp tinyint'--4,120 hits, many of them developer blogs trying to help others over this speed bump. I'm fairly new to Cake. Do I need to comb through the set of things that real users thought were bugs to find the pearls of wisdom by which the Cake developers explained their disinterest in fixing them? Seriously, is this what you meant when you said you knew this was documented? Thanks, Mark and Larry, for welcoming me to Cake land. /alastair/ On Jun 1, 4:09 pm, "Larry E. Masters aka PhpNut" wrote: > I know this is documented and it is part of the CakePHP conventions. > Maybe it is time to upgrade your 1.44 floppy to something like a zip drive? > > -- > /** > * @author Larry E. Masters > * @var string $userName > * @param string $realName > * @returns string aka PhpNut > * @access public > */ > > On Mon, Jun 1, 2009 at 5:49 PM, adallas wrote: > > > I just tracked a bug through Cake's Model code (specifically, model/ > > datasources/dbo_source.php). I was shocked at how small the scope of > > the problem turned out to be. > > > My find('all'...) included a condition, Model.fld = 3. The results > > were wrong and after some wasted time, I saw that the generated SQL > > included Model.fld = 1. Cake wasn't just adding some identity > > condition; or if it was, it was throwing my condition away. It's a > > complicated model (Model, in this case, has 9 associations). I assumed > > it had something to do with that, but it did not. > > > Cake thinks that Tinyints are booleans. Cake parses and reconstructs > > your conditional phrases. Put those two facts together, and you see > > that Model.fld = 0 will work. Model.fld = 1 will work. Model.fld = 2 > > will morph into Model.fld = 3. > > > One solution is to use ints instead of tinyints. Ints take 4 bytes per > > record, tinyints take 1. I can't bring myself to waste the space > > without a good reason. I suppose that's the Cake way--if you'll be > > treating the field like an ordinary int, use an ordinary int type. > > > The solution I used was the result of carefully plodding through the > > dbo_source code--I override Model::getColumnType(). You can force any > > type for a given key. The code is: > > > public function getColumnType($key) > > { > > if ($key == 'MyModel.fld') { > > return 'integer'; // not 'int' > > } > > return parent::getColumnType($key); > > } > > > I hope it helps someone avoid some debugging. > > > /alastair/ --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Tinyints cause big problems
I just tracked a bug through Cake's Model code (specifically, model/ datasources/dbo_source.php). I was shocked at how small the scope of the problem turned out to be. My find('all'...) included a condition, Model.fld = 3. The results were wrong and after some wasted time, I saw that the generated SQL included Model.fld = 1. Cake wasn't just adding some identity condition; or if it was, it was throwing my condition away. It's a complicated model (Model, in this case, has 9 associations). I assumed it had something to do with that, but it did not. Cake thinks that Tinyints are booleans. Cake parses and reconstructs your conditional phrases. Put those two facts together, and you see that Model.fld = 0 will work. Model.fld = 1 will work. Model.fld = 2 will morph into Model.fld = 3. One solution is to use ints instead of tinyints. Ints take 4 bytes per record, tinyints take 1. I can't bring myself to waste the space without a good reason. I suppose that's the Cake way--if you'll be treating the field like an ordinary int, use an ordinary int type. The solution I used was the result of carefully plodding through the dbo_source code--I override Model::getColumnType(). You can force any type for a given key. The code is: public function getColumnType($key) { if ($key == 'MyModel.fld') { return 'integer'; // not 'int' } return parent::getColumnType($key); } I hope it helps someone avoid some debugging. /alastair/ --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Re: Database and Model Design for HABTM
Your code looks right, but you could combine main and sub categories into a Category table that uses Tree behavior. Then a recipe would HABTM categories, and subcategories could have sub-subcategories. /alastair/ On May 28, 7:03 am, Luke wrote: > Hi, > > I am still a Cake newbie, but maybe someone give me a hint on my > issue. I am trying to learn cake by developing a recipe site. > > There are Maincategories and Subcategories. > F.e. > > BBQ -> (Pork, Beef, Vegetarian) > Main Dish -> (Vegetarian) > > A recipe can belong to different Categories, so a "Steak" could show > up under "BBQ" and "Main Dish" and there under Beef. > > I'm planing to have a Form which reads out the Maincategories from the > DB and when you click on a checkbox, the subcategories should show up > (AJAX Request?) > > I have been thinking about the DB Design now for a while and thought I > first had a solution. Than I got doubts and re-designed the tables and > the models. I am now rather confused if this design is correct and > would hope that someone could give some feedback. Okay, here the > tables: > === > maincategories *** this table is filled manually > - id > - maincategory > === > subcategories *** this table is filled manually > - id > - subcategory > - maincategory_id > === > recipes_subcategories ** this will be filled in when Add Recipe Form > was send off > - id > - subcategory_id > - recipe_id > === > recipes ** this will be filled in when Add Recipe Form was send off > - id > - recipename > === > > My Models: > > == Recipe Model > === > class Recipe extends AppModel { > var $name = 'Recipe'; > var $belongsTo = array( > 'User' => array( > 'className' > => 'User' > ) > ); > > var $hasAndBelongsToMany = array( > 'Subcategory' > => > > array( > > 'className' => 'Subcategory', > > 'joinTable' => 'recipes_subcategories', > > 'foreignKey' => 'recipe_id', > > 'associationForeignKey' => 'subcategory_id' > > ) > ); > > > > == Subcategory Model > === > class Subcategory extends AppModel { > var $name = 'Subcategory'; > var $belongsTo = array('Maincategory'); > var $hasAndBelongsToMany = array( > > 'Recipe' => > > array( > > 'className' => 'Recipe', > > 'joinTable' => 'recipes_subcategories', > > 'foreignKey' => 'subcategory_id', > > 'associationForeignKey' => 'recipe_id' > > ) > ); > > } > > Is this setup correct or any advice how it should look instead? Thanks > a lot in advance. --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Re: Saving record HABTM
I may not understand the situation clearly, but I have several HABTM relationships, and I don't have controllers for the association tables. Can you work from either the products or the assets controller? /alastair/ --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Re: View Images
I have the same problem. My solution is to build the url using the define FULL_BASE_URL (defined in CAKE/config/paths.php), and $this- >webroot (where $this is a helper or a controller, but not a view), plus a webroot-relative literal. There doesn't seem to be a define for URL directory separators, but webroot has one before and after, like '/ mysite/'. A view has a property called base which is the same as webroot, without the '/' after. So, in a controller or helper: $url = FULL_BASE_URL . $this->webroot . 'img/user/photos/large'; In a view: $url = FULL_BASE_URL . $this->base . '/img/user/photos/large'; If there's a better way to do this, I'd love to learn. Obviously, one wants a site that transfers smoothly from localhost to a production domain. --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Re: AJAX form submission
I used the same example you did and made the same mistake. The 2nd argument to $ajax->form is the model, not the form method. Instead of 'post', you need your model name (author?) there. Also, I don't think you need $ajax->submit. $form->end('Add') does the right thing. Your controller looks fine. I didn't initially understand what the 2nd arg to $this->render('view','ajax') did, but it's easy to find in the code. The 2nd arg is the layout, so instead of default.ctp, which presumably has your page frame and navigation, it uses ajax.ctp, which has exactly nothing around your view. Glad I could help. /alastair/ On Apr 18, 7:28 am, hugocaracol wrote: > I'm creating an ajax form but it's not working and I can't figure out > why. > > The view to the ajax form is: > > $ajax->form('/authors/add','post',array('url' => '/authors/add', > 'update'=>'DivAddAuthor')); > $form->input('name'); > $ajax->submit('Add', array('url' => '/authors/add', > 'update'=>'DivAddAuthor')); > $form->end(); > > I have the helpers defined in the controller > > var $helpers = array('Html', 'Form','Ajax','Javascript'); > > And the controller code is: > > function add() { > if (!empty($this->data)) { > $this->Author->create(); > $this->Author->save($this->data); > } > $this->render('add','ajax'); > } > > Could you help me? Am I missing something? > > Hugo --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Re: AJAX form submission
I used the same example you did and made the same mistake. The 2nd argument to $ajax->form is the model, not the form method. Instead of 'post', you need your model name (author?) there. Also, I don't think you need $ajax->submit. $form->end('Add') does the right thing. Your controller looks fine. I didn't initially understand what the 2nd arg to $this->render('view','ajax') did, but it's easy to find in the code. The 2nd arg is the layout, so instead of default.ctp, which presumably has your page frame and navigation, it uses ajax.ctp, which has exactly nothing around your view. Glad I could help. /alastair/ hugocaracol wrote: > > ... > > $ajax->form('/authors/add','post',array('url' => '/authors/add', > 'update'=>'DivAddAuthor')); > $form->input('name'); > $ajax->submit('Add', array('url' => '/authors/add', > 'update'=>'DivAddAuthor')); > $form->end(); > > ... > > -- View this message in context: http://www.nabble.com/AJAX-form-submission-tp23113847p23119194.html Sent from the CakePHP mailing list archive at Nabble.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 -~--~~~~--~~--~--~---
Trouble combining Javascript and Ajax
I have code that invokes an Ajax action in the controller that renders a specific view into a . The view includes an $ajax->link that invokes a different Ajax action. The 2nd action renders a different view into the same . These two switch back and forth. When I add a $javascript->codeBlock('alert("huh?");'); call to the view, not only don't I see an alert, but the Ajax functionality stops working, as well. In Firebug, I see no Javascript code in the Ajax- updated . However, looking at $this->output in the controller just after the $this->render code, I see it. I can guess only two possibilities. 1) the controller renders the view but then filters out the Javascript code for some reason as it builds the Ajax response (I use the 'ajax' parameter to the render call, by the way). Or, 2) The Ajax Javascript in the conflicts somehow with the other Javascript and Firebug is lying to me. I'm inclined toward explanation #1, but it's odd that $this->output is unfiltered. The render call specified 'ajax'--if you want to filter Javascript in the case of Ajax, I would think render would do it when you utter 'ajax'. And why did the Ajax link stop working? Does this sound familiar to anyone? --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---