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 <img src="" />.

To use your Smiley model in your helper you need something along the
lines of:

<?php
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 Info
http://www.thinkingphp.org/2006/06/29/simple-listshelper-for-displaying-nested-ul-ol-lists/
(Section 2)
http://www.thinkingphp.org/2006/06/29/simple-listshelper-for-displaying-nested-ul-ol-lists/
- 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, 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 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 [email protected]
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to