Monday, December 28, 2009

Re: Nested Models

When a user selects a contract to view, store the contract id
internally (session). Then when the user requests to view the related
messages, show the messages and add a form for the user to enter a new
message, and have the form url be /messages/add.

If the user adds a new message, retrieve the contract id (session) and
save the message together with the contract id.

Another way is to include the contract id as a hidden input field in
the add form or in the add forms url, but I don't like that as it
provides users with an oportunity to change the contract id.

Hope this helps you on the way,
John


On Dec 28, 11:09 pm, otisjs01 <jerem...@jeremiahotis.com> wrote:
> OK, so I'm asking lots of questions today...but I really want to
> learn! :)
>
> Anyway, I'm trying to create messages that can be left with a
> contract.
>
> So, I have a Contract model that has the following fields: id, some
> other contract pertinent info. And, a Message model that has the
> following fields: id, contract_id, title, message_text. A Contract has
> many message, and a message belongs to a given contract.
>
> Now, when I display a contract, I want a link that takes the user to a
> page full of messages specific to that contract. Once at the message
> page, they should be able to add a new message, or view existing
> messages. Viewing existing messages is easy, as far as I understand
> it. I'm already doing the same thing all over my application! But,
> creating new messages from this page is something I'm unsure of. How
> do I go about that? How do I store the contract_id in the view so that
> whenever I click "Add new contract" it automatically associates the
> message with the contract. And, so that the user can't accidentally
> add the message to a different contract.
>
> I'm thinking that a url that looks like: <a href="#">http://www.application.com/contract/1/message/add</a> where 1 is the
> contract_id) makes the most sense. I could do this in rails in a few
> seconds...but I can't seem to find a way to do it in CakePHP. The only
> thing I can come up with is: <a href="#">http://www.application.com/
> message/add/1</a> (where 1 is the contract_id).
>
> Am I missing something?
>
> Any help would be appreciated!
>
> Thanks,
>
> Jeremiah

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+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en

No comments: