From c796f738d23eddf5237b6c75bce5ba912c0f888a Mon Sep 17 00:00:00 2001 From: Chris Date: Sun, 3 Dec 2017 19:15:36 -0500 Subject: [PATCH 1/2] controller updates --- db/lamp_2017-12-01.sql | 87 ------------------- www/application/controllers/User_Tweets.php | 19 +++- www/application/models/Users_Tweets_Model.php | 17 +++- www/application/views/user.php | 17 ++++ 4 files changed, 48 insertions(+), 92 deletions(-) delete mode 100644 db/lamp_2017-12-01.sql diff --git a/db/lamp_2017-12-01.sql b/db/lamp_2017-12-01.sql deleted file mode 100644 index c1ed7f5..0000000 --- a/db/lamp_2017-12-01.sql +++ /dev/null @@ -1,87 +0,0 @@ -# ************************************************************ -# Sequel Pro SQL dump -# Version 4541 -# -# http://www.sequelpro.com/ -# https://github.com/sequelpro/sequelpro -# -# Host: 127.0.0.1 (MySQL 5.7.20) -# Database: lamp -# Generation Time: 2017-12-01 20:43:00 +0000 -# ************************************************************ - - -/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; -/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; -/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; -/*!40101 SET NAMES utf8 */; -/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; -/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; -/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */; - - -# Dump of table Tweets -# ------------------------------------------------------------ - -DROP TABLE IF EXISTS `Tweets`; - -CREATE TABLE `Tweets` ( - `id` int(11) unsigned NOT NULL AUTO_INCREMENT, - `tweet_id` int(11) DEFAULT NULL, - `tweet` char(140) DEFAULT NULL, - `date_time` datetime DEFAULT NULL, - `user_id` int(11) DEFAULT NULL, - PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=latin1; - -LOCK TABLES `Tweets` WRITE; -/*!40000 ALTER TABLE `Tweets` DISABLE KEYS */; - -INSERT INTO `Tweets` (`id`, `tweet_id`, `tweet`, `date_time`, `user_id`) -VALUES - (1,1,'testing tweet! one two three','1000-01-01 00:00:00',1), - (2,2,'hiiii this is my second tweet','1000-01-01 00:00:00',1), - (3,3,'first twitter tweet omg so kewl','1000-01-01 00:00:00',2), - (4,4,'3rd tweet now so pro','1000-01-01 00:00:00',1), - (5,5,'tweet tweet tweet cant stop me now','1000-01-01 00:00:00',2); - -/*!40000 ALTER TABLE `Tweets` ENABLE KEYS */; -UNLOCK TABLES; - - -# Dump of table Users -# ------------------------------------------------------------ - -DROP TABLE IF EXISTS `Users`; - -CREATE TABLE `Users` ( - `id` int(11) unsigned NOT NULL AUTO_INCREMENT, - `first_name` text, - `last_name` text, - `username` char(20) DEFAULT '', - `password` text, - `email` text, - `url` text, - `location` text, - PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=latin1; - -LOCK TABLES `Users` WRITE; -/*!40000 ALTER TABLE `Users` DISABLE KEYS */; - -INSERT INTO `Users` (`id`, `first_name`, `last_name`, `username`, `password`, `email`, `url`, `location`) -VALUES - (1,'shemona','singh','mona','pass','shemona.singh@uconn.edu',NULL,'milford'), - (2,'christopher','stumper','chris','pass2','chris.stumper@uconn.edu',NULL,'simsbury'); - -/*!40000 ALTER TABLE `Users` ENABLE KEYS */; -UNLOCK TABLES; - - - -/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; -/*!40101 SET SQL_MODE=@OLD_SQL_MODE */; -/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; -/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; -/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; -/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; diff --git a/www/application/controllers/User_Tweets.php b/www/application/controllers/User_Tweets.php index c97e90b..ed37b45 100644 --- a/www/application/controllers/User_Tweets.php +++ b/www/application/controllers/User_Tweets.php @@ -1,17 +1,32 @@ load->library('session'); + //$this->load->library('session'); $this->load->database(); // load database $this->load->model('Users_Tweets_Model'); // load model $this->output->enable_profiler(TRUE); } public function index() { + // load form to tweet + $this->load->helper(array('form', 'url')); + $this->load->library('form_validation'); + + $this->form_validation->set_rules('tweet', 'Tweet', 'required'); + + if ($this->form_validation->run() == FALSE) + $this->load->view('user_tweets'); + echo "false"; + else { + $this->Users_Tweets_Model->addTweet(); + $this->load->view('formsuccess'); + } + + $this->data['posts'] = $this->Users_Tweets_Model->getPosts(); // calling Post model method getPosts() $this->load->view('user', $this->data); // load the view file , we are passing $data array to view file } diff --git a/www/application/models/Users_Tweets_Model.php b/www/application/models/Users_Tweets_Model.php index e67ae08..4b6be20 100644 --- a/www/application/models/Users_Tweets_Model.php +++ b/www/application/models/Users_Tweets_Model.php @@ -1,9 +1,13 @@ load->database(); + } function getPosts(){ - - $_SESSION['user_id'] = $id; + + //$_SESSION['user_id'] = $id; $this->db->select("first_name, last_name, username, tweet, date_time"); @@ -14,5 +18,12 @@ function getPosts(){ return $query->result_array(); } + function addTweet(){ + $this->load->helper('url'); + $data = array( + 'tweet' => $this->input->post('tweet') + ); + } + } ?> diff --git a/www/application/views/user.php b/www/application/views/user.php index 535a957..3f0bcee 100644 --- a/www/application/views/user.php +++ b/www/application/views/user.php @@ -12,6 +12,23 @@

Tweets Feed

+ load->library('form_validation'); + echo validation_errors(); + echo form_open('user_tweets'); ?> + +
+
+
+
Tweet
+ + + +
+ + + +
From 149688ad08d57cafe34ebf50ced8a3383f224009 Mon Sep 17 00:00:00 2001 From: Chris Date: Sun, 3 Dec 2017 20:36:01 -0500 Subject: [PATCH 2/2] control --- www/application/controllers/User_Tweets.php | 54 +++++--------------- www/application/models/User_Tweets_Model.php | 43 +++++----------- 2 files changed, 27 insertions(+), 70 deletions(-) diff --git a/www/application/controllers/User_Tweets.php b/www/application/controllers/User_Tweets.php index 870d5f8..ea30205 100644 --- a/www/application/controllers/User_Tweets.php +++ b/www/application/controllers/User_Tweets.php @@ -1,41 +1,15 @@ -load->library('session'); -======= ->>>>>>> f4837a582f4adec40ee0abbdbcab7529d12c3238 - $this->load->database(); // load database - $this->load->model('User_Tweets_Model'); // load model - $this->output->enable_profiler(TRUE); +load->database(); + $this->load->model('User_Tweets_Model'); + $this->output->enable_profiler(TRUE); + } + + public function index(){ + $this->data['posts'] = $this->Users_Tweets_Model2->getPosts(); + $this->load->view('user', $this->data); + } } - - public function index() { -<<<<<<< HEAD - // load form to tweet - $this->load->helper(array('form', 'url')); - $this->load->library('form_validation'); - - $this->form_validation->set_rules('tweet', 'Tweet', 'required'); - - if ($this->form_validation->run() == FALSE) - $this->load->view('user_tweets'); - echo "false"; - else { - $this->Users_Tweets_Model->addTweet(); - $this->load->view('formsuccess'); - } - - - $this->data['posts'] = $this->Users_Tweets_Model->getPosts(); // calling Post model method getPosts() -======= - $this->data['posts'] = $this->User_Tweets_Model->getPosts(); // calling Post model method getPosts() ->>>>>>> f4837a582f4adec40ee0abbdbcab7529d12c3238 - $this->load->view('user', $this->data); // load the view file , we are passing $data array to view file - } - -} diff --git a/www/application/models/User_Tweets_Model.php b/www/application/models/User_Tweets_Model.php index f7211f3..c84a6c6 100644 --- a/www/application/models/User_Tweets_Model.php +++ b/www/application/models/User_Tweets_Model.php @@ -1,32 +1,15 @@ load->database(); - } - function getPosts(){ -<<<<<<< HEAD:www/application/models/Users_Tweets_Model.php - - //$_SESSION['user_id'] = $id; -======= ->>>>>>> f4837a582f4adec40ee0abbdbcab7529d12c3238:www/application/models/User_Tweets_Model.php - - - $this->db->select("first_name, last_name, username, tweet, date_time"); - $this->db->from('Users, Tweets'); - $this->db->where('Users.id = Tweets.user_id'); - $this->db->order_by('date_time', 'DESC'); - $query = $this->db->get(); - return $query->result_array(); - } - - function addTweet(){ - $this->load->helper('url'); - $data = array( - 'tweet' => $this->input->post('tweet') - ); - } - +class User_Tweets_Model extends CI_Model { + public function __construct(){ + $this->load->database(); + } + + function getPosts(){ + $this->db->select("first_name, last_name, username, tweet, date_time"); + $this->db->from('Users, Tweets'); + $this->db->where('Users.id = Tweets.user_id'); + $this->db->order_by('date_time', 'DESC'); + $query = $this->db->get(); + return $query->result_array(); + } } -?>