Guest User

Untitled

a guest
Oct 23rd, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. /*
  2. I'm inserting a text object with a structure like this (it's a PHP object but here's what
  3. it looks like in JSON)
  4.  
  5. { "title": "My text",
  6. "other_details": 5,
  7. "phrases": [
  8. { "sentence": "séres humanos", "translation": "human" },
  9. { "sentence": "derechòs", "translation": "rights" } ]
  10. }
  11.  
  12. */
  13.  
  14. public function create() {
  15.  
  16. $text_data = array(
  17. 'title' => $this->input->post('title'),
  18. 'other_details' => $this->input->post('other_details'),
  19. );
  20.  
  21. $text_id = $this->text_model->insert($text_data);
  22.  
  23. $phrases = $this->input->post('phrases');
  24. $this->phrase_model->insert_many($phrases);
  25.  
  26. redirect('texts/show/' . $id);
  27.  
  28. }
  29.  
  30. /*
  31.  
  32. Question is: what is the PHP way to iterate through $phrases and add
  33. stick that $text_id field on there?
  34.  
  35. */
Add Comment
Please, Sign In to add comment