views:

96

answers:

1

I'm trying to write a cakephp app. I need to validate input based on availability. an example would be if someone is trying to take out a book from a library. I would reference the book to see if it's currently out, and if it is report that to the user.

another example would be trying to book rooms at a hotel, the user would enter a date and a length of their visit, and the function would check to see if that room is available for that length of time.

I'm writing this in the controller, but I'm confused about how to a) grab the data I need from the database, and b) how to pass that data between functions. I know how I would do this using php/mysql but I'm not familiar with cakephp and I can't find a tutorial that just goes over the basics.

edit: i think i got it down, i'll update in a bit.

+1  A: 

Check out the Blog tutorial on the CakePHP website. That's where I started. It guides you through all the steps, including Data Validation.

Read the rest of the CakePHP documentation as you start writing your own application.

Wil
I did look through that, but it mostly refers to grabbing unconstrained data from a single table.it was somewhat helpful, but i found it lacking since it really didn't touch on the subject of associated data. like if it were to show comments on a post, and if it showed how to limit results so it only showed posts from a certain time frame.thank you for the post though.
Adrian Guido
Isn't that explained here http://book.cakephp.org/view/66/Models ??
Wil
I have all my associations setup already. I tested them using scaffolding and every table seemed to be linked properly to each other. now i need to write my own code for this application. so i made a few controller functions, they really just passed data to the view which worked fine. now I'm trying pull data from the database to use inside a function to generate a list that i can pass to a view. i can get the data from the model to the view using a controller but i am not sure how to use the data inside the controller.
Adrian Guido
Maybe an idea to store the data you retrieve from the db in $var, then use the function pr($var) to see what the data array you retrieved from the db looks like before you pass it to the view.
Wil
the cakephp documentation helped me find out what i needed to know, mostly that i needed to make components for the bits of code i was trying to write. i don't like documentation because i always find the examples lacking, and i still don't have working code, but i believe i am on the right track.
Adrian Guido