Re: ORDER BY id DESC
In 1.2 : $this-Post-find('first', array('conditions' = array('post.category_id' = intval($catId)), 'order' = 'post.id DESC')); On 10 mai, 13:39, Olexandr Melnyk [EMAIL PROTECTED] wrote: If you're using CakePHP 1.1, something like this should do the job: $this-Post-findAll('catid = ' . $catid, array('field1'), 'id DESC', 1, 0); Don't forget to make sure that $catid is an integer. On 5/10/08, koko [EMAIL PROTECTED] wrote: Hello, I've searched this group and all other resources (bakery, manual, book, API), but I found no useful results ... I have a table and that table contain some fields (it's only one table no HABTM here and no two tables relations): id . . catid . . I just mentioned the important fields ... and I have a function that takes $catId as parameter function getLastPost($catId) { $this-set('post', $this-Post-findByCatid($catId)); } this function return an array of results where the table field 'catid' = $catId (the parameter) what should i do to return only one result ordered by (table field) id desc, because I want only the one result with the last id (I want to use to show the last post from many categories) I mean something like that: SELECT * FROM posts WHERE catid = $catId ORDER BY id DESC; if I stick with this solution (give cake a query) ... cake returned an array based on 0,1,2,... locations but the API methods (find, findBy..) returned different array, based on table name instead of numbers I want a cakePHP function to do this query and return a will formated array: was that clear enough or not :S ?? -- Sincerely yours, Olexandr Melnykhttp://omelnyk.net/ --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: Protected File Download
Hello, I would suggest you to store your uploaded files on your filesystem, ex : /home/yourappname/uploads/ - Use app/config/core.php or bootstrap.php to write your file storage path : Configure::write('Music.uploadPath', '/home/yourappname/uploads/ music/'); or define('MUSIC_UPLOAD_PATH', 'yourpath'); - Then in your controller just add a download method : class MusicController extends AppController{ function download($song){ if(!isset($song)) $this-redirect('/'); if($this-isAuthenticatedUser()){ $file = MUSIC_UPLOAD_PATH . $song; $data = file_get_contents($file); $size = filesize($file); if(isset($_SERVER['HTTP_USER_AGENT']) strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE')) header('Content-Type: application/force-download'); else header('Content-Type: application/get-the-correct-mime-type'); header('Content-Length: '. $size); header('Content-disposition: attachment; filename=' . $song .'); echo $data; }else{ $this-redirect($this-referer(), 403); } } // download } Now link to your files with : $html-link(__('Download this file', true), '/music/download/your- song'); Bart wrote: Hi! (i'm a newbe) I want my site-visitors to be able after login to download an (audio/ image)file that is only for them. I have two options: uploading the files into the database or uploading the files onto the server in a folder with filedata in the DB. The first has the advantage of security but I have some problems with displaying the image after download (corrupted/characters are displayed instead of a pretty picture) The second has the advantage of transparancy/no corruption so far, but how do I secure files? Placing them in the webroot makes them publicly accessible. Which structure do you advice? Can you give me a direction/some keywords I should look into? Cheers, Bart --~--~-~--~~~---~--~~ 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: element: model or controller?
Hello, Assuming you have a newsletter Controller and a newsletter Model : in NewsletterController (newsletter_controller.php) : class NewsletterController extends AppController { var name = 'Newsletter'; function archive_list(){ $this-set('archives', $this-Newsletter-find('all', array(Newsletter.publish_date = NOW())) } } In your archive list view (archive_list.ctp), you'll be able to iterable over your archives through $archives. or .. in your controller above, (assuming its not the NewsletterController) just do : var uses = array('Newsletter'); function archive_list(){ $this-set('archives', $this-Newsletter-getArchives()); } in the Newsletter model, create a method for your archive list : function getArchives(){ $sql = 'SELECT id, to_char(publish_date, \'Mon, \') AS month FROM newsletter ' . 'WHERE publish_date NOW() ORDER BY publish_date DESC'; return $this-query($sql); } .. or simply correct the typo $this-Newsletter instead of $this- newsletter. On Dec 23, 4:09 am, subtropolis [EMAIL PROTECTED] wrote: I'm a n00b here and have been redoing an existing site in order to learn the Cake way. I'm jumping straight into the 1.2 branch.This is my first cry for help. I have a section for an online newsletter. Several pages list links for the archived issues. From what i've read, i should use an element for this. I've created the file newsletter_archive_list.ctp in the elements dir with the following: $archive_list = $this-requestAction('newsletter/archive_list'); // followed by markup to list the links The controller's archive_list method is simply: function archive_list() { $sql = 'SELECT id, to_char(publish_date, \'Mon, \') AS month FROM newsletter ' . 'WHERE publish_date NOW() ORDER BY publish_date DESC'; return $this-newsletter-query($sql); } The thing is, as i understand it, it's better to place as much code in the model, rather than the controller (which seems quite sensible). However, i haven't been able to figure out how to then call the function from the model. With the method in the controller, i get this error: Undefined property: NewsletterController::$newsletter [APP/ controllers/newsletter_controller.php, line 25] My head is spinning. The manuals are really not very clear on this. I understood that the model ($newsletter) was available anywhere inside the controller. Can someone please point me in the right direction? (extra points for explaining how the new cache system, would work here :-) --~--~-~--~~~---~--~~ 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: Need Suggestion on Accented Character
Set your (x)HTML page charset to UTF8. Like AD7Six said, you should set everything to UTF8 On Dec 12, 5:23 pm, bingo [EMAIL PROTECTED] wrote: hi so you mean to say Database..but how do I convert everything in UTF-8 format..I mean when someone paste something in textarea of my webform, I will need to take that and convert into UTF-8 ...but how do I know in what format it is. Regards, bingo On Dec 12, 8:04 am, AD7six [EMAIL PROTECTED] wrote: On Dec 12, 2:00 pm, bingo [EMAIL PROTECTED] wrote: hi, I never before built a website to handle accented characters. Currently this is becoming a big headache for me. if someone enters Sánchez (notice a is accented character) in my web form, only nchez is stored in the database. Can some tell me how to handle these accented characters in MySQL/CakePHP system. Currently, my database is set up with latin-1 characterset. Use UTF8 (for everything). AD --~--~-~--~~~---~--~~ 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: Preventing Duplicate Record Insertion on Page Refresh
You should use the redirect after post pattern, using a HTTP 302 or 303 status code after saving your fields. if($this-Model-save()) $this-redirect($url, $code, $exit); On Dec 11, 12:58 pm, chowdary [EMAIL PROTECTED] wrote: i am validating the data b4 inserting. but the data type is text.. the text will not be unique... explain me clearly... --~--~-~--~~~---~--~~ 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: Inline javascript in a view not executed
On Dec 4, 5:22 pm, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: Hi I have a question I have a index.thml where there are many divs. Then with ajax I substitute one of divs with another view ( view.thtml). In this view I use a javascript function attached to a link. So If I define this function in view.thtml I get an error instead I define the function in index.html all works fine. But I would define the function in view.thtml because I use this function only in this view. How I can do This ? Many Thanks Marco Hello, What Javascript library are you using ? With prototype, if think you can set evalScripts to true as an option when using Ajax.Request. You can also play with onSuccess callback to get things done. I hope it helps ! --~--~-~--~~~---~--~~ 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: PDF Creation in Cake 1.2
Hi, To generate PDFs, i used the fpdf library. In your vendor directory, create a directory named fpdf and simply drop fpdf classes into it, then, lets say you want to render / download a pdf from your controller : - in views/layouts : create a file 'pdf_layout.php' : ?php header(Content-type: application/pdf); echo $content_for_layout ? - in controllers/orders_controller : function invoice(){ // respond to a pdf format request vendor('fpdf/'fpdf.php'); $this-layout('pdf'); $this-render('pdfs/invoice_template'); } - in views/orders/ create a directory named pdf and a template file for your invoices inside, ex : invoice_template.ctp. fill your pdf invoice template with the data you need to render ( ex: $pdf-Ln(10); $pdf-Cell(0, 10, $order['total']) ). --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---