Advertisement
Guest User

Untitled

a guest
Apr 16th, 2014
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.03 KB | None | 0 0
  1. <?php
  2.  
  3. class Xml_insert extends CI_Controller {
  4.  
  5. function index() {
  6.  
  7. $this->load->model('xml_insert_model');
  8. $data['rows'] = $this->xml_insert_model->getAll();
  9. $this->load->view('xml_insert_view', $data);
  10. }
  11.  
  12. function insert() {
  13. $this->load->model('xml_insert_model');
  14. $data['rows'] = $this->xml_insert_model->getAll();
  15.  
  16. foreach ($data['rows'] as $r) {
  17. $path1 = $r->xml_file_path;
  18. $xml = simplexml_load_file($path1);
  19.  
  20. $newAct = $_POST['activity'];
  21.  
  22. $root = $xml->firstChild;
  23.  
  24. $newElement = $xml->createElement('activity');
  25. $root->appendChild($newElement);
  26. $newText = $xml->createTextNode($newAct);
  27. $newElement->appendChild($newText);
  28.  
  29. $xml->save('$path1');
  30. $this->index();
  31. }
  32. }
  33.  
  34. }
  35.  
  36. <!doctype html>
  37. <html lang="en">
  38. <head>
  39. <meta charset="UTF-8">
  40. <title>Document</title>
  41. </head>
  42. <body>
  43. <?php foreach ($rows as $r): ?>
  44. <?php
  45. $path1 = $r->xml_file_path;
  46. $xml = simplexml_load_file($path1);
  47. ?>
  48. <?php foreach ($xml->children() as $activity) : ?>
  49. <?php echo "Activity : " . $activity . " <br />"; ?>
  50. <?php endforeach; ?>
  51. <?php endforeach; ?>
  52.  
  53. <form name="input" action="index.php/xml_insert/insert" method="post">
  54. insert activity:
  55. <input type="text" name="activity"/>
  56. <input type="submit" value="send"/>
  57. </form>
  58. </body>
  59. </html>
  60.  
  61. <?php
  62. class Xml_insert_model extends CI_Model
  63. {
  64. function getAll()
  65. {
  66.  
  67. $q = $this->db->get("XML");
  68.  
  69. if ($q->num_rows > 0) {
  70.  
  71. foreach ($q->result() as $row) {
  72. $data[] = $row;
  73. }
  74.  
  75. return $data;
  76. }
  77. }
  78. }
  79.  
  80. <?xml version="1.0"?>
  81. <list>
  82. <activity>swimming</activity>
  83. <activity>running</activity>
  84. <activity>Jogging</activity>
  85. <activity>Theatre</activity>
  86. <activity>Programming</activity>
  87. <activity>driving</activity>
  88. <activity>eating</activity>
  89. </list>
  90.  
  91. $xml = new DomDocument();
  92. $xml->load($path1);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement