Jon Posted January 11, 2016 Posted January 11, 2016 Hello, I am just after a bit advice as to if this is the correct/best away of going about this. Iam looking to store booking information (no card info just names and booking information) with each booking being a new page. This is how I was thinking of doing it. Front end from which sends the relative information then I would great a page(s) in the admin tree Admin>Bookings>Booking To create this page I would be using the following code along with the information ill be storing $p = new Page(); // create new page object $p->template = 'booking'; // set template $p->parent = wire('pages')->get('/site-manager/bookings/'); ...... Is this the best practice to do this and secure? Cheers Jon
horst Posted January 11, 2016 Posted January 11, 2016 Looks good, only thing I would check is: You probaply will give a name and / or title to your new page. I would suggest to create it first and check if a page with that given name or title already exists: $parent = wire('pages')->get('/site-manager/bookings/'); $genericTitle = $somehowCreatedFromYourDataOrTimestampOrWhatever; $p = $pages->get("title={$genericTitle}, template=booking, parent.id=" . $parent->id); if(0 == $p->id) { // page does not exist, we can create a new one $p = new Page(); // create new page object $p->template = 'booking'; // set template $p->parent = $parent; $p->title = $genericTitle; ...... } else { // UUUPs! A Page with that title exists. // This case must be handled different! ...... } 1
Jon Posted January 12, 2016 Author Posted January 12, 2016 Hello Horst, Thats great thank I was going to use a timestamp it would be very unlikely we got a booking at the exact same time, but adding a check just in case would be a good idea! Thanks for that. Jon
bernhard Posted January 12, 2016 Posted January 12, 2016 Or something like While ($pages->count("title=".$title.", parent...) $title.="-1"; Sorry on mobile
Craig Posted January 12, 2016 Posted January 12, 2016 You could also get ProcessWire to handle duplicate cases for you. $p = new Page(); $p->name = uniqid(); ... $p->save(array('adjustName' => true)); From the API function: adjustName (boolean) - Adjust page name to ensure it is unique within its parent (default=false) 2
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now