Re: I'm trying to make a good find with three HABTM models
Yes, I worked it out and I confirm that what's been said here all comes together just fine. Thank you all! On Jun 8, 9:45 am, John Andersen wrote: > The find('list') will give you the table ID column and the first > column thereafter (when no name or title column), so what you got was > the table ID and the user_id values. > > Add a field list to your find options like: > [code] > $options = array( > 'conditions' => array( > 'ProjectsUser.user_id' => 12 > ), > 'fields' => array( > 'user_id', 'project_id' > ) > ); > [/code] > > Enjoy, > John > > On Jun 8, 10:36 am, DrLaban wrote: > > > > > This comes very close to what I'm looking for, but the first find that > > I wrote (it isn't an exact copy of your code but should be equal): > > > $options = array( > > 'conditions' => array( > > 'ProjectsUser.user_id' => 12 > > ) > > ); > > debug($this->Project->ProjectsUser->find('list',$options)); > > > prints the unique id:s of the matched rows in the projects_users > > table. Unfortunately, it gives me a list of; > > > [0] => 61 > > [1] => 67 > > > but these id:s don't exist in the Project-table. > > > Just a small example of three rows of actual values in the > > projects_users table; > > > projects_users > > id | user_id | project_id > > 61| 12 | 2 > > 67 | 12 | 7 > > 68 | 13 | 5 > > > Now, I get the id-column when doing the suggested find and this I > > can't match to the Project-table id's. I guess what I want are the > > project_id's from the project_users table to be able to match this > > right. > > I'll go back and fiddle a bit more with this but to come with > > suggestions. > > > This worked almost right out of the box, I'm impressed! Thank you for > > these and any further comments! > > [snip] 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
Re: I'm trying to make a good find with three HABTM models
This comes very close to what I'm looking for, but the first find that I wrote (it isn't an exact copy of your code but should be equal): $options = array( 'conditions' => array( 'ProjectsUser.user_id' => 12 ) ); debug($this->Project->ProjectsUser->find('list',$options)); prints the unique id:s of the matched rows in the projects_users table. Unfortunately, it gives me a list of; [0] => 61 [1] => 67 but these id:s don't exist in the Project-table. Just a small example of three rows of actual values in the projects_users table; projects_users id | user_id | project_id 61| 12| 2 67 | 12 | 7 68 | 13 | 5 Now, I get the id-column when doing the suggested find and this I can't match to the Project-table id's. I guess what I want are the project_id's from the project_users table to be able to match this right. I'll go back and fiddle a bit more with this but to come with suggestions. This worked almost right out of the box, I'm impressed! Thank you for these and any further comments! On Jun 7, 10:02 pm, vekija wrote: > The easiest way that comes to mine mind would be to get the ids of the > projects you are involved at first and then pass those as condition in > the before mentioned find call. > > Something like... > > $this->loadModel('ProjectsUser'); > > $ids = $this->ProjectsUser->find('list', array('conditions' => > array('ProjectsUser.user_id => $yourId))); > > $projects = $this->Project->find('all', array( > 'contain' => array( > 'Group' => array('User') > ), > 'conditions => array('Project.id' => array_keys($ids)) > )); > > there are probably other ways of doing this, but I would have to think > and test before I recommend them. :) > > Cheers > > On Jun 7, 9:03 pm, DrLaban wrote: > > > > > Oooh! That's pretty awesome, and it seems to work like a charm, > > thanks! > > > Just one more question on this subject. This involves a bit more > > trickery I believe; > > > I'd also like to be able to view all the Groups/Users for all the > > projects I'm involved at. This would look something like > > [Project 1] > > [Group 1] > > [User 2] > > [User 3] > > [User 4] > > [Group 10] > > [User 1] > > [User 3] > > [Project 2] > > [Group 25] > > [User 1] > > [User 3] > > [User 7] > > > Now, the information about what projects I'm involved at is stored in > > projects_users. I guess I somehow have to use this information to be > > able to present it in the above described way? Otherwise I'm not sure > > as to how I could first filter out all the projects I'm involved with > > and then go hunt for the groups and users. Any insights on this matter > > is really appreciated. > > > Thank you in advance! > > > On Jun 7, 3:26 pm, vekija wrote: > > > > You can try Containable behavior. > > > > In models put > > > > var $actsAs = array('Containable'); > > > > and then in the controller > > > > $this->Project->find('all', array('contain' => array('Group' => > > > array('User'; > > > > you can find out more about the Containable behavior in the cook > > > bookhttp://book.cakephp.org/view/1323/Containable > > > > On Jun 7, 2:54 pm, DrLaban wrote: > > > > > My setup is pretty straightforward; > > > > User HABTM Group > > > > Group HABTM Project > > > > Project HABTM User > > > > > I would like to produce a find-query that takes a single project-id > > > > and builds a hierarchic contact list, in which the users belong to > > > > their respective group(s). > > > > > Something along these lines: > > > > [Project 1] > > > > [Group 1] > > > > [User 1] > > > > [User 5] > > > > [Group 2] > > > > [User 1] > > > > [User 2] > > > > [User 3] > > > > [Group 4] > > > > [User 3] > > > > [User 4] > > > > ... > > > > > Is this possible and if so, how? All I've been able to produce is > > > > something of a flat structure where I can't match the user to a group; > > > > [Project 1] > > > > [User 1] > > > > [User 3] > > > > [User 4] > > > > [User 6] > > > > [Group 1] > > > > [Group 3] > > > > [Group 4] > > > > > This is produced when I do; > > > > $this->Project->find('all'); 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
Re: I'm trying to make a good find with three HABTM models
Oooh! That's pretty awesome, and it seems to work like a charm, thanks! Just one more question on this subject. This involves a bit more trickery I believe; I'd also like to be able to view all the Groups/Users for all the projects I'm involved at. This would look something like [Project 1] [Group 1] [User 2] [User 3] [User 4] [Group 10] [User 1] [User 3] [Project 2] [Group 25] [User 1] [User 3] [User 7] Now, the information about what projects I'm involved at is stored in projects_users. I guess I somehow have to use this information to be able to present it in the above described way? Otherwise I'm not sure as to how I could first filter out all the projects I'm involved with and then go hunt for the groups and users. Any insights on this matter is really appreciated. Thank you in advance! On Jun 7, 3:26 pm, vekija wrote: > You can try Containable behavior. > > In models put > > var $actsAs = array('Containable'); > > and then in the controller > > $this->Project->find('all', array('contain' => array('Group' => > array('User'; > > you can find out more about the Containable behavior in the cook > bookhttp://book.cakephp.org/view/1323/Containable > > On Jun 7, 2:54 pm, DrLaban wrote: > > > > > My setup is pretty straightforward; > > User HABTM Group > > Group HABTM Project > > Project HABTM User > > > I would like to produce a find-query that takes a single project-id > > and builds a hierarchic contact list, in which the users belong to > > their respective group(s). > > > Something along these lines: > > [Project 1] > > [Group 1] > > [User 1] > > [User 5] > > [Group 2] > > [User 1] > > [User 2] > > [User 3] > > [Group 4] > > [User 3] > > [User 4] > > ... > > > Is this possible and if so, how? All I've been able to produce is > > something of a flat structure where I can't match the user to a group; > > [Project 1] > > [User 1] > > [User 3] > > [User 4] > > [User 6] > > [Group 1] > > [Group 3] > > [Group 4] > > > This is produced when I do; > > $this->Project->find('all'); 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
I'm trying to make a good find with three HABTM models
My setup is pretty straightforward; User HABTM Group Group HABTM Project Project HABTM User I would like to produce a find-query that takes a single project-id and builds a hierarchic contact list, in which the users belong to their respective group(s). Something along these lines: [Project 1] [Group 1] [User 1] [User 5] [Group 2] [User 1] [User 2] [User 3] [Group 4] [User 3] [User 4] ... Is this possible and if so, how? All I've been able to produce is something of a flat structure where I can't match the user to a group; [Project 1] [User 1] [User 3] [User 4] [User 6] [Group 1] [Group 3] [Group 4] This is produced when I do; $this->Project->find('all'); 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
How do I add a helper to an element
Hello all! I've been doing some Cake'ing for a while and find it lots of fun to work with seeing that it's quite fast and has a lot going for it so far. I'm having a bit of a headache with elements and helpers though, I've seen some notions about it but never quite figured it out so I thought I'd give this a shot to see if anyone can help me clear things up. What I'm trying to accomplish is quite simple; I have a sidebar to the left of my page where I'd like to add/edit/delete small notices (one short caption along with a short string of text). I've managed to make the entire site working insofar that every section on the page with editing capabilites does what it should. I can add/edit/delete users, add/edit/delete quotations, and so forth. The sidebar is stationary on the leftside of the page at all times and I haven't figured out a better or nicer way of adding this sidebar's contents other than an element, but here's where the troubles start; I've been trying for a few hours to sort this thing out but I can't make one of my helpers accessible to the element. >From what I've read here on the group it could be that it's not possible by design, but the answers have been a bit vague, so I'm not really sure of what to do. Here's the principle layout in wordings (I've copied the files contents to the bottom of this post); The following exists; Model -> Controller -> View (layout). The view uses renderElement() to invoke the element. The element contains a helper function call. The Controller has $helpers=[myHelper] defined. Problem: The helper isn't availbable in the Element. This is my file structure containing just the necessary (I think) information about my element and helper (btw, I'm not Cake-savvy in the least so there might be horrible errors or flaws, but I've also omitted alot of code to keep things a little less bloated); -[Model: notice.php]- class Notice extends AppModel { var $name = 'Notice'; } -[Controller: notices_controller.php]- class NoticesController extends AppController { var $name = 'Notices'; var $components = array('mysql'); var $helpers = array('Tools'); function index() { $notices = $this->Notice->findAll(); if(isset($this->params['requested'])) { return $notices; } $this->set('notices', $notices); } function add() { if(!empty($this->data)) { if($this->Notice->save($this->data)) { $this->flash('Notice added!', '/'); } } } function edit($id = null) { if(empty($this->data)) { $this->Notice->id = $id; $this->data = $this->Notice->read(); $this->set('notice', $this->Notice->read()); } else { if($this->Notice->save($this->data['Notice'])) { $this->flash('Notice updated!', '/'); } } } -[View: default.thtml]- renderElement('notices'); ?> --[Element: notices.thtml]-- requestAction('notices/index'); ?> getNoticesEdit($id); ?> -[Helper: tools.php]- var $helpers = array('Html'); function getNoticesEdit($id) { {conditional statements, etc, etc} $return = somestring; 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: Easy problem, not all that easy to figure out (set function)
That worked ace! Thanks! Regard DrLaban On Jul 29, 6:22 pm, Gorka <[EMAIL PROTECTED]> wrote: > If I understood you right, you are overwritting the value of 'gallery' > with the second call to $this->set(), when you wanted to merge both > values. Try preparing your data first, then setting 'gallery' for the > view. > > $galery = $this->Gallery->findAll(); > $gallery['numRows'] = $this->Gallery->getNumRows(); > $this->set('gallery', $gallery); > > On 29 jul, 17:30,DrLaban<[EMAIL PROTECTED]> wrote: > > > Hey all! > > > Short and simple; > > I'm trying to add more data to a Controller object with the help of > > set(). > > > So what I'm doing in practice: > > $this->set('gallery', $this->Gallery->findAll()); > > > Everything works out fine here. I get access to all the info I need in > > the view I'm working with. > > Now, I'd like to add something simple like "numRows" to the gallery > > variable. > > > What I've tried is: > > $this->set('gallery', array('numRows' => $this->Gallery- > > > >getNumRows()); > > > But, as it would seem, the gallery object now only contains the last > > set function call's info. How do I add info to the gallery object > > without losing info from the first set call? I'd just like to add a > > field called "numRows" that contains the int value of rows returned, > > into the gallery object. > > > Thanks in advance! > > > Regards > > DrLaban --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Easy problem, not all that easy to figure out (set function)
Hey all! Short and simple; I'm trying to add more data to a Controller object with the help of set(). So what I'm doing in practice: $this->set('gallery', $this->Gallery->findAll()); Everything works out fine here. I get access to all the info I need in the view I'm working with. Now, I'd like to add something simple like "numRows" to the gallery variable. What I've tried is: $this->set('gallery', array('numRows' => $this->Gallery- >getNumRows()); But, as it would seem, the gallery object now only contains the last set function call's info. How do I add info to the gallery object without losing info from the first set call? I'd just like to add a field called "numRows" that contains the int value of rows returned, into the gallery object. Thanks in advance! Regards DrLaban --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Structuring and modelling applications and just understanding the workings of cakePHP
Hello there! So I've started to get the hang of how the models, controllers and views work together. It was a bit of an uphill to start with but I've managed to create quite a few good, sound working sections in cakePHP which makes me think that I at least have some knowledge about how things should work. Now, I've been thinking about a specific part of an application I'm building and it has to do with newsletters and e-mail registrations. The section of the application's different functions are simple enough; * Index (Here you have the option to click subscribe and unsubscribe links) * Subscribe (Provide a valid email address, this in turn sends an email sent to you with a verification code) * Verify (With the help of your address and verification code, you verify that you've recieved the subscription email) * Unsubscribe (Provide an email-address to unsubscribe) I'm almost done with the entire section but I'm becoming more and more unsure if I'm attacking this from the right angles. It seems, as I've gotten further and further into trying to figure out how to solve different types of things, I'm more and more letting go of cakePHP's structure, almost coding everything by hand as I would without using cake. For example; The registration page. It works perfect, I get an email sent to me and whatnot but I've "lost" some of cakePHP's powers in the process. On the registration page I've got the following in my controller: if(!empty($this->data)) { $this->data['Lunch']['code'] = $this->Generic- >generatePassword(4); if($this->Lunch->save($this->data)) { $this->Generic->sendEmail($this->data['Lunch']['email'], $this- >data['Lunch']['code']); $this->flash('Data saved!', '/newsletter'); } } As you can see I'm using a component called "Generic" (I had a bit of a dry-out when choosing name, I'm aware) which holds both code generating functions and email handling. The view only consists of one field so far; "Enter your email address". It works fine insofar that if I don't provide an email address, I don't get an email and the address isn't stored anywhere. If I do provide an email address, but it's in the wrong format, I get notified of this by cake's built-in error handler. If I provide a correct email address, everything is working and I get a flash-message that everything has worked out. The model is very simple: class Newsletter extends AppModel { var $name = 'Newsletter'; var $validate = array( 'email' => VALID_EMAIL ); } Not very much to comment on here. The view: Subscribe to our newsletter Email address: input('Newsletter/email', array('size' => 20)); ?>tagErrorMsg('Newsletter/ email', 'You have to provide a valid email address!'); ?> submit('Subscribe!'); ?> As the model states, it gives me an error when the address is in the wrong format but do I have to state some other validation method to make it work with an empty field? What I've lost here in the process are the following: * My database table of this consists of a unique field called "email" apart from the regular "id" primary key field. When I enter an email address that already exists in the database I get an ugly SQL-parse error. None of the nicely styled and handled error messages that cake provides. * If I don't provide an email address, I get no error whatsoever. The page reloads as if nothing's happened and I get to provide the address again. I've completely and entirely lost the error handling. Now, what I'd like to know is this; Am I going about this the right way or am I not using cake's potential at all? Are there mutiple ways of solving this? Thank you for your time! It's much appreciated! Regards DrLaban --~--~-~--~~~---~--~~ 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 bit of a problem with forms and JavaScript
This worked perfectly! Thanks alot for your comment! Regards DrLaban On Jul 16, 8:22 am, wralph <[EMAIL PROTECTED]> wrote: > Use the ID, so if you have a textarea with ID of ModelField, then > access using: > > document.getElementById('ModelField').value = 'whatever value you wish > to assign'; > > Winston --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
A bit of a problem with forms and JavaScript
So I'm trying to figure out how to address the following problem: I'm using a textarea with the name "data[Model][Field]" so I have access to the short hand form validation inside CakePHP. Now, this is becoming a bit of a problem, since I use JavaScript to insert smileys and other code snippets into the text field. I'm having the JavaScript read the field properties, but since the format of the name of the textarea is the same as an array, JavaScript just halts, giving me an error telling me that, in my example here, "Model" is not defined. Can I somehow change either the behaviour of JavaScript or CakePHP so that I can use a name property without losing field validation? Regards DrLaban --~--~-~--~~~---~--~~ 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: CakePHP is great fun, but a bit tricky
It works great, thanks Geoff! I'll try and see if I understand what it does in more detail and test a couple of things. Perhaps I've even learned something! :D Regards DrLaban On Jul 13, 12:56 am, Geoff Ford <[EMAIL PROTECTED]> wrote: > Create a helper called SmileyHelper, add it to the GuestBookController > with var $helpers = array('Bbcode', 'Smiley'); > > In your view where you output the post, you should be using something > along the lines of $bbcode->display($this->data['GuestBook'] > ['post']); Make this in $smiley->display($bbcode->display($this- > > >data['GuestBook']['post'])); > > Then the smiley helper display() function should be a series of > regular expressions that convert :) to . > > To use your Smiley model in your helper you need something along the > lines of: > > loadModel('smiley'); > > class SmileyHelper extends Object { > > function display($in){ > $smiley = new Smiley(); > $smilies = $smiley->findAll(); > > // loop over the smilies and preg_replace all the smilies in > $in > }} > > ?> > > Helpers > Infohttp://www.thinkingphp.org/2006/06/29/simple-listshelper-for-displayi... > (Section > 2)http://www.thinkingphp.org/2006/06/29/simple-listshelper-for-displayi... > - Example of a simple helper > > Geoff > --http://lemoncake.wordpress.com > > On Jul 13, 7:07 am, DrLaban <[EMAIL PROTECTED]> wrote: > > > Wow, I'm totally stumped now. It could be that I just don't grasp the > > full extent of the MVC model (which I should be able to do, as I > > manage to create and actually make projects in Java just fine?), > > or the way CakePHP wants me to arrange and create models, views and > > controllers. At first glance, the blog tutorial was very simple to > > follow and (of course), everything worked just splendid. > > But adding more stuff to it is a bit... well, nottrickyanymore... > > it's more daunting. > > > So, what am I trying to accomplish? Well, a simple guestbook with some > > extras to it. The guestbook works like the blog, but with the > > additions of bbCode-parsing (that works perfect atm, with the help of > > a link handed to me of a Helper for just that), avatar-handling (which > > also works perfect, with a little reading and doodling with relations > > in the Models/Controllers) and last, smiley-handling. The last part > > just won't work. Doesn't matter what tip, trick or hint I try and add > > to it, I either get errors about Helpers not being found, parse errors > > that I can't create and instance of a specific class, errors about > > objects not being available and other obscure things. I know that it's > > not anything to do with Cake. It's to do with me. I'm not going to > > give this up, because I know the potential of what I'm trying to learn > > here, but I need some guidelines. I thought a tip or a pointer would > > make me understand what where I was at fault, but I can see now I need > > a bit more insight. > > > So, for those of you interested in what I've tried to create, here it > > is, in shortform; > > * A guestbook based on the Blog Tutorial. The main differences being > > bbCode, Avatars and Smileys. > > > What does it consist of? > > [ Database ] > > * guestbooks (everything related to the actual post, along with > > avatar_id for relations sake) > > * avatars (containing avatars of different types, related to the > > guestbooks table, through the guestbook model) > > * smileys (containing smileys of different types, not related to any > > other table) > > > [ Models ] > > * guestbook (contains the same as the blog tutorial model, addition; > > $belongsTo = Avatar for relation) > > * avatar (contains just the $name along with a $hasMany = Guestbook > > for relation) > > * smiley (contains just the $name variable) > > > [ Controllers ] > > * guestbook_controller (contains the same as the blog tutorial, along > > with a html helper called 'Bbcode'. I try adding a smiley object to > > the add() function (which corresponds to the add view) but I can't get > > it to work) > > > [ Views ] > > * index (Works like a charm. Bbcode is parsed and works splendid) > > * add (Creates new posts just like it should, adding the info to the > > database) > > * edit (Edits posts just as it should) > > * delete (Removes posts just as it should) > > > So, where am I missing out on things? I
Re: CakePHP is great fun, but a bit tricky
Wow, I'm totally stumped now. It could be that I just don't grasp the full extent of the MVC model (which I should be able to do, as I manage to create and actually make projects in Java just fine?), or the way CakePHP wants me to arrange and create models, views and controllers. At first glance, the blog tutorial was very simple to follow and (of course), everything worked just splendid. But adding more stuff to it is a bit... well, not tricky anymore... it's more daunting. So, what am I trying to accomplish? Well, a simple guestbook with some extras to it. The guestbook works like the blog, but with the additions of bbCode-parsing (that works perfect atm, with the help of a link handed to me of a Helper for just that), avatar-handling (which also works perfect, with a little reading and doodling with relations in the Models/Controllers) and last, smiley-handling. The last part just won't work. Doesn't matter what tip, trick or hint I try and add to it, I either get errors about Helpers not being found, parse errors that I can't create and instance of a specific class, errors about objects not being available and other obscure things. I know that it's not anything to do with Cake. It's to do with me. I'm not going to give this up, because I know the potential of what I'm trying to learn here, but I need some guidelines. I thought a tip or a pointer would make me understand what where I was at fault, but I can see now I need a bit more insight. So, for those of you interested in what I've tried to create, here it is, in shortform; * A guestbook based on the Blog Tutorial. The main differences being bbCode, Avatars and Smileys. What does it consist of? [ Database ] * guestbooks (everything related to the actual post, along with avatar_id for relations sake) * avatars (containing avatars of different types, related to the guestbooks table, through the guestbook model) * smileys (containing smileys of different types, not related to any other table) [ Models ] * guestbook (contains the same as the blog tutorial model, addition; $belongsTo = Avatar for relation) * avatar (contains just the $name along with a $hasMany = Guestbook for relation) * smiley (contains just the $name variable) [ Controllers ] * guestbook_controller (contains the same as the blog tutorial, along with a html helper called 'Bbcode'. I try adding a smiley object to the add() function (which corresponds to the add view) but I can't get it to work) [ Views ] * index (Works like a charm. Bbcode is parsed and works splendid) * add (Creates new posts just like it should, adding the info to the database) * edit (Edits posts just as it should) * delete (Removes posts just as it should) So, where am I missing out on things? I've read the replies and tried to implement them and reading them through to see where I was missing out on something crucial, but I just can't for the life of me get it to work. It might be that both replies works as they are expected to, but I just don't have the knowledge yet to understand them, I guess. Am I going totally in the wrong direction about thinking that the Model provides data to the Controller which in turn provides data to the View? Why is it, that I can't make/store a Smiley-model in the guestbook-controller, which in turn provides data to the View? I've tried to make some kind of reasoning with Components and Helpers too and I think I've understood them as being extensions to the original Controllers and Views but I've yet to understand when I should use them and when I should insert everything in the View itself or the Controller. I know this is getting a bit lenghty, but I really, really, really want to learn how to do this. Thank you all for your help so far. Too bad I'm not yet getting the hang of it. Regards DrLaban On Jul 10, 12:29 am, Geoff Ford <[EMAIL PROTECTED]> wrote: > >From what I can see you will need a helper that has access to the > > smiley model. > > You can do so with: > loadModel('smiley'); > class SmileyHelper extends Helper{ > var $Smiley = new Smiley(); > > } > > And then you can use it like $this->Smiley->find('ascii_code'=>';)'); > > Creating the regex find and replace is up to you. > > Geoff > --http://lemoncake.wordpress.com > On Jul 10, 6:18 am, DrLaban <[EMAIL PROTECTED]> wrote: > > > Hello there! > > > I'm at the moment trying to figure out how to fit a new model into the > > existing controller. As I mentioned earlier I did manage to create a > > relation between Avatars and Guestbooks, since it had the elements > > required to create such a relation in Cake's framework. > > > Now, thetrickything I have yet to grasp (I'm reading the replies > > here while I trial and error
Re: CakePHP is great fun, but a bit tricky
Hello there! I'm at the moment trying to figure out how to fit a new model into the existing controller. As I mentioned earlier I did manage to create a relation between Avatars and Guestbooks, since it had the elements required to create such a relation in Cake's framework. Now, the tricky thing I have yet to grasp (I'm reading the replies here while I trial and error a bit), is how to make the combine of the guestbook controller or its views to be able to get to the information stored in the model. I'm of the impression that I can't get to the data information stored in the model without shipping it into a controller first. I need to combine the Smileys information with the rest of the guestbook in order to translate an ASCII ":)" into an img-tag. I have an ERD that you can look at and as you can see there is no database relation between the Guestbooks and Smileys, but there will be a relation in the application (where the message text from the Guestbooks table will be parsed to replace ASCII smileys into img- tags). http://www.jhe.nu/upload/erd.jpg I'm sorry if I'm a bit slow in the understanding here, but programming like this in PHP is totally new for me. But I appreciate you taking your time to try and help me out! Regards DrLaban On Jul 7, 1:28 am, Grant Cox <[EMAIL PROTECTED]> wrote: > If you don't want to hard code them in your helper, then you will need > another database table for your smileys. And a model. > > Now you can get/set the database data just like any other model, > through $this->Smiley->find() and $this->Smiley->save(). To get a > list you might want to use $this->Smiley->generateList(). > > Now, how does Smiley relate to other models? I would have guessed > that the HTML code for a smiley is to be added to a textarea (ie in > your GuestBook post?) but after this point there is no dynamic > relationship. In which case there are no associations. Or perhaps a > single Smiley has to be chosen for the Guestbook post icon - in which > case you want a GuestBook belongsTo Smiley association (with > GuestBook.smiley_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?hl=en -~--~~~~--~~--~--~---
Re: CakePHP is great fun, but a bit tricky
Well, I *think* that's how I started out, but I'm not all clear on how the different models, controllers and views communicate with eachother. What I've done so far is this: -Model- * Guestbook (This collects all data from the guestbooks table making it available to the application) * Avatar (This collects all data from the avatar table making it available to the application BUT it's also combined with the Guestbook- model because they share information (key id's)) -Controller- * Guestbook (Assigns the views I'd like to use (taken from the Blog tutorial; index, add, edit, delete)) -Views- * Index * Add * Edit * Delete Now, I read a bit about combining data between tables and it sorted itself out with the help of $belongsTo and $hasMany. This means that the avatar_id's in Guestbook is combined and replaced by info from the Avatar table. This works right out of the box on the Index page. But I just can't get my head around adding a new model and combine it without using for example $belongsTo and $hasMany, since it's not really going to be used on every subsequent post stored in the Guestbook table. I'm trying to implement my Smileys array function into the Edit and Add views but I'm getting a bit confused as to what I should add and where. I'm thinking it should be a helper (it has alot to do with the presentation) but somehow I need to connect it with a Model or a Controller to be able to get to the table data. I think? :p Again, thanks for yout input, much appreciated! Regards DrLaban On Jul 6, 12:50 pm, Sergei <[EMAIL PROTECTED]> wrote: > So what's the problem? Make a function in a model that extracts smiley > data, and set it to view variable in your controller action. > > Then make a helper something like: > > $myhelper->smily($smilydata) > > or better, do it with element: > > $this->renderElement("smile",array('data'=>$smileydata)) > > I would choose an element for this. > > On 6 ???, 19:16, DrLaban <[EMAIL PROTECTED]> wrote: > > > I managed to figure out a bit about helpers and the way they work but > > I'm still a bit lost getting to know the workings of Cake. > > Now, seeing that a helper was great for bbCode parsing I'm now trying > > to figure out what the best way to handle an array of smileys is. --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
CakePHP is great fun, but a bit tricky
I managed to figure out a bit about helpers and the way they work but I'm still a bit lost getting to know the workings of Cake. Now, seeing that a helper was great for bbCode parsing I'm now trying to figure out what the best way to handle an array of smileys is. The problem is for most of you gurus probably both well known and simple to solve. I think I'm going basically in the right direction but I just can't reach the finnish line... Short: In one of my views I need to output a bunch of 30+ smileys extracted from a table. Longer: I've tried to use a helper for this, since I want the thtml-code to be as clean as possible. I've managed to create a helper that outputs items in an array but this array is a static one that I've declared myself with static keys. I haven't yet figured out how (or perhaps even when) I'm supposed to connect to the database and extract the info gathered there. The reason I want to store all my smilies in a database is of course that I want to be able to update them easily and it makes information in general much more manageable. The smileys are only being used on two views, one for adding and one for editing posts, so I can't say they're really "reusable" to any extent other than that and it might be that a helper is a bit over the top. Any hints in a general direction is appreciated. I'm reading posts and going through tutorials about this as time goes by but I haven't gotten to the details that can solve my minor issue quite yet. Thanks for your time! Regards DrLaban --~--~-~--~~~---~--~~ 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: Going nuts on components
So, I managed to solve it after even more extensive googling and experimenting. I didn't take into account that the information stored in the database I'm using has to be encoded with UTF-8 compliant extended characters. This resulted in having to perform two things; 1: Change the collation of the field from ISO-8859-1 to UTF-8-generic. 2: Search and replace all the extended characters you want to parse from its original encoding to UTF-8 compliant encoding. Thanks for the info about the helper! Regards DrLaban On Jul 4, 11:51 pm, DrLaban <[EMAIL PROTECTED]> wrote: > Thanks, it worked like a charm! > > Only one thing that I can't quite get to float; using ISO-8859-1 > character set instead of UTF-8. I've tried changing the UTF-8 setting > within the helper, but it seems as if it doesn't really care what I > change it to. > I'm using extended characters åäö as I live in Sweden and I'm trying > to figure out how to solve this issue. Anyone got a hint for me? > > As I said, it works real good so no complaining at all there, just > trying to figure out how to get the extended character set working. > Would it perhaps mean I have to make changes in the regular > expressions? > > Regards > DrLaban > > On Jul 4, 4:18 am, Geoff Ford <[EMAIL PROTECTED]> wrote: > > > Here is the Bakery's implementation as a helper > > :-https://cakeforge.org/plugins/scmsvn/viewcvs.php/trunk/bakery/views/h... > > > Basically in the view you call $bbcode->format($this->data['ModelName'] > > ['bbcode']); > > > Geoff > > --http://lemoncake.wordpress.com > > > On Jul 4, 11:30 am, DrLaban <[EMAIL PROTECTED]> wrote: > > > > Hey all and thank you for reading this post! > > > > I'm a newbie on cakePHP but it's a really fascinating project and > > > slowly I'm getting the hang of things. It might be that I'm going a > > > bit too fast and get a bit ahead of myself, but really, I can't see > > > why I have such problems with components. I'm trying to wrap my head > > > around some other minor things, I'll mention them below. > > > > Short: > > > This is for a guestbook I've done. I need to interpret bbCode inside > > > each users message and translate those into proper html. > > > I can't really get the grips on what's needed for it to work, perhaps > > > I'm looking in the wrong direction, but a component seems appropriate. > > > > Longer: > > > I've tried creating a component using the guide on cakePHP.org. Now, > > > everything works after doing some extensive search on google and > > > whatnot. I have problems in the Model/Controller/Component-block. If I > > > add a file ("Guestbook.php") in the components folder, along with the > > > code snippets from cakePHP.org I get a fatal error on MySQL telling me > > > that 'startup' isn't a valid query. Someone in a newsgroup post > > > mentioned that this could be due to the fact that I haven't defined > > > the functions in the model. So, I added them there and everything is > > > fins so far. But no matter what I add to the component file, I get > > > errors until I add them to the model too. This makes the component > > > file obsolete, since the functions become duplicated. > > > What am I missing here? > > > > Short 2: > > > How do I access instance variables or variables in general? There > > > aren't getters in cake as far as I've gathered and I find it tricky to > > > figure out how to get to a specific piece of data within a variable in > > > a class. I'm sure there's an easy way to read data from variables, but > > > I just haven't found it. > > > > Thanks for your time, I hope I didn't mess everything up with my > > > descriptions! > > > > Regards > > > DrLaban --~--~-~--~~~---~--~~ 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: Going nuts on components
Thanks, it worked like a charm! Only one thing that I can't quite get to float; using ISO-8859-1 character set instead of UTF-8. I've tried changing the UTF-8 setting within the helper, but it seems as if it doesn't really care what I change it to. I'm using extended characters åäö as I live in Sweden and I'm trying to figure out how to solve this issue. Anyone got a hint for me? As I said, it works real good so no complaining at all there, just trying to figure out how to get the extended character set working. Would it perhaps mean I have to make changes in the regular expressions? Regards DrLaban On Jul 4, 4:18 am, Geoff Ford <[EMAIL PROTECTED]> wrote: > Here is the Bakery's implementation as a helper > :-https://cakeforge.org/plugins/scmsvn/viewcvs.php/trunk/bakery/views/h... > > Basically in the view you call $bbcode->format($this->data['ModelName'] > ['bbcode']); > > Geoff > --http://lemoncake.wordpress.com > > On Jul 4, 11:30 am, DrLaban <[EMAIL PROTECTED]> wrote: > > > Hey all and thank you for reading this post! > > > I'm a newbie on cakePHP but it's a really fascinating project and > > slowly I'm getting the hang of things. It might be that I'm going a > > bit too fast and get a bit ahead of myself, but really, I can't see > > why I have such problems with components. I'm trying to wrap my head > > around some other minor things, I'll mention them below. > > > Short: > > This is for a guestbook I've done. I need to interpret bbCode inside > > each users message and translate those into proper html. > > I can't really get the grips on what's needed for it to work, perhaps > > I'm looking in the wrong direction, but a component seems appropriate. > > > Longer: > > I've tried creating a component using the guide on cakePHP.org. Now, > > everything works after doing some extensive search on google and > > whatnot. I have problems in the Model/Controller/Component-block. If I > > add a file ("Guestbook.php") in the components folder, along with the > > code snippets from cakePHP.org I get a fatal error on MySQL telling me > > that 'startup' isn't a valid query. Someone in a newsgroup post > > mentioned that this could be due to the fact that I haven't defined > > the functions in the model. So, I added them there and everything is > > fins so far. But no matter what I add to the component file, I get > > errors until I add them to the model too. This makes the component > > file obsolete, since the functions become duplicated. > > What am I missing here? > > > Short 2: > > How do I access instance variables or variables in general? There > > aren't getters in cake as far as I've gathered and I find it tricky to > > figure out how to get to a specific piece of data within a variable in > > a class. I'm sure there's an easy way to read data from variables, but > > I just haven't found it. > > > Thanks for your time, I hope I didn't mess everything up with my > > descriptions! > > > Regards > > DrLaban --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Going nuts on components
Hey all and thank you for reading this post! I'm a newbie on cakePHP but it's a really fascinating project and slowly I'm getting the hang of things. It might be that I'm going a bit too fast and get a bit ahead of myself, but really, I can't see why I have such problems with components. I'm trying to wrap my head around some other minor things, I'll mention them below. Short: This is for a guestbook I've done. I need to interpret bbCode inside each users message and translate those into proper html. I can't really get the grips on what's needed for it to work, perhaps I'm looking in the wrong direction, but a component seems appropriate. Longer: I've tried creating a component using the guide on cakePHP.org. Now, everything works after doing some extensive search on google and whatnot. I have problems in the Model/Controller/Component-block. If I add a file ("Guestbook.php") in the components folder, along with the code snippets from cakePHP.org I get a fatal error on MySQL telling me that 'startup' isn't a valid query. Someone in a newsgroup post mentioned that this could be due to the fact that I haven't defined the functions in the model. So, I added them there and everything is fins so far. But no matter what I add to the component file, I get errors until I add them to the model too. This makes the component file obsolete, since the functions become duplicated. What am I missing here? Short 2: How do I access instance variables or variables in general? There aren't getters in cake as far as I've gathered and I find it tricky to figure out how to get to a specific piece of data within a variable in a class. I'm sure there's an easy way to read data from variables, but I just haven't found it. Thanks for your time, I hope I didn't mess everything up with my descriptions! Regards DrLaban --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---