From 72e12bc768c58b7cd0578ad2992398e7d7f8e5bf Mon Sep 17 00:00:00 2001 From: Chris Date: Mon, 4 Dec 2017 15:03:47 -0500 Subject: [PATCH] search --- www/application/controllers/All_Tweets.php | 10 ++++++ www/application/controllers/Login.php | 2 +- www/application/controllers/Register.php | 2 +- www/application/controllers/Search.php | 14 ++++++++ www/application/models/All_Tweets_Model.php | 10 ++++++ www/application/models/Search_Model.php | 16 +++++++++ www/application/models/User_Info_Model.php | 2 +- www/application/models/User_Tweets_Model.php | 29 +++++----------- www/application/views/home.php | 36 +++++++++++++++++++- www/application/views/templates/footer.php | 2 +- 10 files changed, 98 insertions(+), 25 deletions(-) create mode 100644 www/application/controllers/Search.php create mode 100644 www/application/models/Search_Model.php diff --git a/www/application/controllers/All_Tweets.php b/www/application/controllers/All_Tweets.php index 8816ca7..4e32d65 100644 --- a/www/application/controllers/All_Tweets.php +++ b/www/application/controllers/All_Tweets.php @@ -12,9 +12,19 @@ function __Construct(){ public function index() { $this->data['posts'] = $this->All_Tweets_Model->getPosts(); // calling Post model method getPosts() + $this->load->view('templates/header', NULL); $this->load->view('home', $this->data); // load the view file , we are passing $data array to view file $this->load->view('templates/footer', NULL); } + function search_keyword(){ + $keyword = $this->input->post('keyword'); + $data['results'] = $this->All_Tweets_Model->search($keyword); + + $this->load->view('templates/header'); + $this->load->view('home', $data); // load the view file , we are passing $data array to view file + $this->load->view('templates/footer'); + } + } diff --git a/www/application/controllers/Login.php b/www/application/controllers/Login.php index eaa8137..a86eb16 100644 --- a/www/application/controllers/Login.php +++ b/www/application/controllers/Login.php @@ -15,7 +15,7 @@ public function index(){ // load the homepage if login successful // https://www.codeigniter.com/user_guide/libraries/form_validation.html#callbacks-your-own-validation-methods else { - $this->load->view('formsuccess'); + redirect('/all_tweets'); } } } diff --git a/www/application/controllers/Register.php b/www/application/controllers/Register.php index a9f7707..cda503f 100644 --- a/www/application/controllers/Register.php +++ b/www/application/controllers/Register.php @@ -29,7 +29,7 @@ public function index(){ // https://www.codeigniter.com/user_guide/libraries/form_validation.html#callbacks-your-own-validation-methods else { $this->User_Info_Model->addUser(); - $this->load->view('formsuccess'); + redirect('/all_tweets'); } } } diff --git a/www/application/controllers/Search.php b/www/application/controllers/Search.php new file mode 100644 index 0000000..c716fdc --- /dev/null +++ b/www/application/controllers/Search.php @@ -0,0 +1,14 @@ +load->model('Search_Model'); + } + function index(){ + $this->load->view('search', NULL); + } + + +} diff --git a/www/application/models/All_Tweets_Model.php b/www/application/models/All_Tweets_Model.php index 1e0f488..0c70fb7 100644 --- a/www/application/models/All_Tweets_Model.php +++ b/www/application/models/All_Tweets_Model.php @@ -10,5 +10,15 @@ function getPosts(){ return $query->result_array(); } + function search($keyword){ + $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'); + $this->db->like('tweet', $keyword); + $query = $this->db->get(); + return $query->result_array(); + } + } ?> diff --git a/www/application/models/Search_Model.php b/www/application/models/Search_Model.php new file mode 100644 index 0000000..7d46821 --- /dev/null +++ b/www/application/models/Search_Model.php @@ -0,0 +1,16 @@ +load->database(); // load database + } + + function search($keyword) + { + $this->db->like('tweet', $keyword); + $query = $this->db->get('Tweets'); + return $query->result(); + } +} diff --git a/www/application/models/User_Info_Model.php b/www/application/models/User_Info_Model.php index fd6b042..2a43411 100644 --- a/www/application/models/User_Info_Model.php +++ b/www/application/models/User_Info_Model.php @@ -4,7 +4,7 @@ class User_Info_Model extends CI_Model { function getUserID(){ } - // new user + // register function addUser(){ $this->load->helper('url'); diff --git a/www/application/models/User_Tweets_Model.php b/www/application/models/User_Tweets_Model.php index 6292bf0..369f512 100644 --- a/www/application/models/User_Tweets_Model.php +++ b/www/application/models/User_Tweets_Model.php @@ -10,27 +10,16 @@ function getPosts(){ return $query->result_array(); } - function addTweet(){ - $this->load->helper('url'); + function addTweet(){ + $this->load->helper('url'); - $slug = url_title($this->input->post('title'), 'dash', TRUE); + $slug = url_title($this->input->post('title'), 'dash', TRUE); - $data = array( - 'tweet' => $this->input->post('tweet'), - 'date_time' => 10, - 'user_id' => 1 - ); - - return $this->db->insert('Tweets', $data); - - /* - $this->load->helper('url'); - $data = array( - 'tweet' => $this->input->post('tweet') - ); - - return $this->db->insert('tweets', $data); - */ - } + $data = array( + 'tweet' => $this->input->post('tweet'), + 'user_id' => 1 // UPDATE THIS WITH SESSION DATA + ); + return $this->db->insert('Tweets', $data); + } } diff --git a/www/application/views/home.php b/www/application/views/home.php index 7153591..e2d71ab 100644 --- a/www/application/views/home.php +++ b/www/application/views/home.php @@ -1,10 +1,44 @@ +Twitter Clone + + +

All Tweets

- + + load->library('form_validation'); ?> + + + + + + + +
+
+
+ " . $row['first_name'] . " " . $row['last_name'] . ""; ?> + " . "@" . $row['username'] . "";?> +
+
+ +
+
+
+
+ +
+
+
+ + +
diff --git a/www/application/views/templates/footer.php b/www/application/views/templates/footer.php index f9a1892..ada7589 100644 --- a/www/application/views/templates/footer.php +++ b/www/application/views/templates/footer.php @@ -1,4 +1,4 @@ - © 2017 Stumper and Singh Studios + © 2017 Singh and Stumper Studios