Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Understanding the passing of data/life of a script in web development/CodeIgniter
- <?php
- class Site extends CI_Controller {
- var $task1;
- var $tasks = array(
- "task1" => NULL,
- "date1" => 0,
- "date2" => 0,
- "diff" => 0);
- function __construct()
- {
- parent::__construct();
- include 'timetask.php';
- $this->task1 = new TimeTask("create");
- }
- function index()
- {
- $this->tasks['task1'] = $this->task1->getTask();
- $this->tasks['diff'] = $this->task1->getTimeDiff();
- if($this->tasks['diff'] == NULL)
- {
- $this->tasks['diff'] = 0;
- }
- $this->load->view('usability_test', $this->tasks);
- }
- function origIndex()
- {
- $this->task1->setDate1(new DateTime());
- $this->tasks['date1'] = $this->task1->getDate1()->getTimestamp();
- $data = array();
- if($q = $this->site_model->get_records())
- {
- $data['records'] = $q;
- }
- $this->load->view('options_view', $data);
- }
- function create()
- {
- $this->task1->setDate2(new DateTime());
- $this->tasks['date2'] = $this->task1->getDate2()->getTimestamp();
- $data = array(
- 'author' => $this->input->post('author'),
- 'title' => $this->input->post('title'),
- 'contents' => $this->input->post('contents')
- );
- $this->site_model->add_record($data);
- $this->index();
- }
- <?php
- class TimeTask
- {
- private $task;
- /**
- * @var DateTime
- */
- private $date1, $date2;
- function __construct($currTask)
- {
- $this->task = $currTask;
- }
- public function getTimeDiff()
- {
- $hasDiff = $this->date1 && $this->date2;
- if ($hasDiff) {
- return $this->date2->getTimestamp() - $this->date1->getTimestamp();
- } else {
- return NULL;
- }
- }
- public function __toString()
- {
- return (string) $this->getTimeDiff();
- }
- /**
- * @return DateTime
- */
- public function getDate1()
- {
- return $this->date1;
- }
- /**
- * @param DateTime $date1
- */
- public function setDate1(DateTime $date1)
- {
- $this->date1 = $date1;
- }
- /**
- * @return DateTime
- */
- public function getDate2()
- {
- return $this->date2;
- }
- /**
- * @param DateTime $date2
- */
- public function setDate2(DateTime $date2)
- {
- $this->date2 = $date2;
- }
- /**
- * @return get current task
- */
- public function getTask()
- {
- return $this->task;
- }
- }
- ?>
- <?php echo form_open('site/create');?>
- ...and...
- <?php echo anchor("site/delete/$row->id", $row->title); ?>
- CREATE TABLE IF NOT EXISTS `ci_sessions` (
- session_id varchar(40) DEFAULT '0' NOT NULL,
- ip_address varchar(45) DEFAULT '0' NOT NULL,
- user_agent varchar(120) NOT NULL,
- last_activity int(10) unsigned DEFAULT 0 NOT NULL,
- user_data text NOT NULL,
- PRIMARY KEY (session_id),
- KEY `last_activity_idx` (`last_activity`)
- $config['sess_use_database'] = TRUE;
- $config['sess_table_name'] = 'ci_sessions';
Add Comment
Please, Sign In to add comment