Guest User

Untitled

a guest
Sep 18th, 2018
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.81 KB | None | 0 0
  1. Understanding the passing of data/life of a script in web development/CodeIgniter
  2. <?php
  3.  
  4. class Site extends CI_Controller {
  5.  
  6. var $task1;
  7. var $tasks = array(
  8. "task1" => NULL,
  9. "date1" => 0,
  10. "date2" => 0,
  11. "diff" => 0);
  12.  
  13. function __construct()
  14. {
  15. parent::__construct();
  16. include 'timetask.php';
  17. $this->task1 = new TimeTask("create");
  18. }
  19.  
  20. function index()
  21. {
  22. $this->tasks['task1'] = $this->task1->getTask();
  23. $this->tasks['diff'] = $this->task1->getTimeDiff();
  24.  
  25. if($this->tasks['diff'] == NULL)
  26. {
  27. $this->tasks['diff'] = 0;
  28. }
  29.  
  30. $this->load->view('usability_test', $this->tasks);
  31. }
  32.  
  33. function origIndex()
  34. {
  35. $this->task1->setDate1(new DateTime());
  36. $this->tasks['date1'] = $this->task1->getDate1()->getTimestamp();
  37. $data = array();
  38.  
  39. if($q = $this->site_model->get_records())
  40. {
  41. $data['records'] = $q;
  42. }
  43.  
  44. $this->load->view('options_view', $data);
  45. }
  46.  
  47. function create()
  48. {
  49. $this->task1->setDate2(new DateTime());
  50. $this->tasks['date2'] = $this->task1->getDate2()->getTimestamp();
  51.  
  52. $data = array(
  53. 'author' => $this->input->post('author'),
  54. 'title' => $this->input->post('title'),
  55. 'contents' => $this->input->post('contents')
  56. );
  57.  
  58. $this->site_model->add_record($data);
  59. $this->index();
  60.  
  61. }
  62.  
  63. <?php
  64.  
  65. class TimeTask
  66. {
  67. private $task;
  68.  
  69. /**
  70. * @var DateTime
  71. */
  72. private $date1, $date2;
  73.  
  74. function __construct($currTask)
  75. {
  76. $this->task = $currTask;
  77. }
  78.  
  79. public function getTimeDiff()
  80. {
  81. $hasDiff = $this->date1 && $this->date2;
  82. if ($hasDiff) {
  83. return $this->date2->getTimestamp() - $this->date1->getTimestamp();
  84. } else {
  85. return NULL;
  86. }
  87. }
  88.  
  89. public function __toString()
  90. {
  91. return (string) $this->getTimeDiff();
  92. }
  93.  
  94. /**
  95. * @return DateTime
  96. */
  97. public function getDate1()
  98. {
  99. return $this->date1;
  100. }
  101.  
  102. /**
  103. * @param DateTime $date1
  104. */
  105. public function setDate1(DateTime $date1)
  106. {
  107. $this->date1 = $date1;
  108. }
  109.  
  110. /**
  111. * @return DateTime
  112. */
  113. public function getDate2()
  114. {
  115. return $this->date2;
  116. }
  117.  
  118. /**
  119. * @param DateTime $date2
  120. */
  121. public function setDate2(DateTime $date2)
  122. {
  123. $this->date2 = $date2;
  124. }
  125.  
  126. /**
  127. * @return get current task
  128. */
  129. public function getTask()
  130. {
  131. return $this->task;
  132. }
  133.  
  134. }
  135.  
  136. ?>
  137.  
  138. <?php echo form_open('site/create');?>
  139. ...and...
  140. <?php echo anchor("site/delete/$row->id", $row->title); ?>
  141.  
  142. CREATE TABLE IF NOT EXISTS `ci_sessions` (
  143. session_id varchar(40) DEFAULT '0' NOT NULL,
  144. ip_address varchar(45) DEFAULT '0' NOT NULL,
  145. user_agent varchar(120) NOT NULL,
  146. last_activity int(10) unsigned DEFAULT 0 NOT NULL,
  147. user_data text NOT NULL,
  148. PRIMARY KEY (session_id),
  149. KEY `last_activity_idx` (`last_activity`)
  150.  
  151. $config['sess_use_database'] = TRUE;
  152. $config['sess_table_name'] = 'ci_sessions';
Add Comment
Please, Sign In to add comment