From dec56918c3a126b5c78178ea6046b021c8724e4e Mon Sep 17 00:00:00 2001 From: Chris Date: Mon, 4 Dec 2017 11:59:38 -0500 Subject: [PATCH] tweet db insert --- www/README.md | 3 +- www/application/config/database.php | 5 ++- www/application/controllers/User_Tweets.php | 34 ++++------------ www/application/models/User_Tweets_Model.php | 43 +++++++++++--------- www/application/views/formsuccess.php | 2 - www/application/views/user.php | 34 +--------------- 6 files changed, 37 insertions(+), 84 deletions(-) diff --git a/www/README.md b/www/README.md index 6a36455..bbd921e 100644 --- a/www/README.md +++ b/www/README.md @@ -7,8 +7,7 @@ For your final project you will work in teams of 2 to build a fully-functioning 2. Login (session management) 3. User profile page with the users’ tweets. 4. View tweets from all users. -5. Ability to “Like” tweets when logged-in -6. Ability to search all tweets. +5. Ability to search all tweets. ### Optional Features 1. DMs diff --git a/www/application/config/database.php b/www/application/config/database.php index 6c634b5..4d3bb20 100755 --- a/www/application/config/database.php +++ b/www/application/config/database.php @@ -70,7 +70,10 @@ | The $query_builder variables lets you determine whether or not to load | the query builder class. */ -$active_group = 'default'; +if ($_SERVER['HTTP_HOST'] == 'web.digitalmediauconn.org') + $active_group = 'production'; +else $active_group = 'default'; + $query_builder = TRUE; $db['default'] = array( diff --git a/www/application/controllers/User_Tweets.php b/www/application/controllers/User_Tweets.php index 870d5f8..e5b6fb6 100644 --- a/www/application/controllers/User_Tweets.php +++ b/www/application/controllers/User_Tweets.php @@ -4,38 +4,18 @@ class User_Tweets extends CI_Controller { function __Construct(){ - parent::__Construct (); -<<<<<<< HEAD - //$this->load->library('session'); -======= ->>>>>>> f4837a582f4adec40ee0abbdbcab7529d12c3238 - $this->load->database(); // load database - $this->load->model('User_Tweets_Model'); // load model - $this->output->enable_profiler(TRUE); + parent::__Construct(); + //$this->load->library('session'); + $this->load->database(); // load database + $this->load->model('User_Tweets_Model'); // load model + $this->output->enable_profiler(TRUE); } 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('templates/header', NULL); $this->load->view('user', $this->data); // load the view file , we are passing $data array to view file + $this->load->view('templates/footer', NULL); } } diff --git a/www/application/models/User_Tweets_Model.php b/www/application/models/User_Tweets_Model.php index f7211f3..d9eb2f4 100644 --- a/www/application/models/User_Tweets_Model.php +++ b/www/application/models/User_Tweets_Model.php @@ -1,32 +1,37 @@ 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(); + } - public function __construct() - { - $this->load->database(); - } - function getPosts(){ -<<<<<<< HEAD:www/application/models/Users_Tweets_Model.php + function addTweet(){ + $this->load->helper('url'); - //$_SESSION['user_id'] = $id; -======= ->>>>>>> f4837a582f4adec40ee0abbdbcab7529d12c3238:www/application/models/User_Tweets_Model.php + $slug = url_title($this->input->post('title'), 'dash', TRUE); + $data = array( + 'id' => 500, + 'tweet' => $this->input->post('tweet'), + 'date_time' => 10, + 'user_id' => 1 + ); - $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(); - } + return $this->db->insert('Tweets', $data); - function addTweet(){ + /* $this->load->helper('url'); $data = array( 'tweet' => $this->input->post('tweet') ); + + return $this->db->insert('tweets', $data); + */ } } -?> diff --git a/www/application/views/formsuccess.php b/www/application/views/formsuccess.php index eb2f877..ac1472b 100644 --- a/www/application/views/formsuccess.php +++ b/www/application/views/formsuccess.php @@ -1,3 +1 @@

Your form was successfully submitted!

- -

diff --git a/www/application/views/user.php b/www/application/views/user.php index d8f59ca..bcf8f1e 100644 --- a/www/application/views/user.php +++ b/www/application/views/user.php @@ -1,34 +1,5 @@ - - - - - User Tweets - - - - +

Tweets Feed

- load->library('form_validation'); - echo validation_errors(); - echo form_open('user_tweets'); ?> - -
-
-
-
Tweet
- - - -
- - - -
@@ -43,6 +14,3 @@
- - -