Skip to content

Commit

Permalink
search
Browse files Browse the repository at this point in the history
  • Loading branch information
cws13003 committed Dec 4, 2017
1 parent b69d77a commit 72e12bc
Show file tree
Hide file tree
Showing 10 changed files with 98 additions and 25 deletions.
10 changes: 10 additions & 0 deletions www/application/controllers/All_Tweets.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}

}
2 changes: 1 addition & 1 deletion www/application/controllers/Login.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
}
}
2 changes: 1 addition & 1 deletion www/application/controllers/Register.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
}
}
14 changes: 14 additions & 0 deletions www/application/controllers/Search.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php
Class Search Extends CI_Controller
{
function __construct()
{
parent::__construct();
$this->load->model('Search_Model');
}
function index(){
$this->load->view('search', NULL);
}


}
10 changes: 10 additions & 0 deletions www/application/models/All_Tweets_Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

}
?>
16 changes: 16 additions & 0 deletions www/application/models/Search_Model.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php
Class Search_Model Extends CI_Model
{
function __construct()
{
parent::__construct();
$this->load->database(); // load database
}

function search($keyword)
{
$this->db->like('tweet', $keyword);
$query = $this->db->get('Tweets');
return $query->result();
}
}
2 changes: 1 addition & 1 deletion www/application/models/User_Info_Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class User_Info_Model extends CI_Model {
function getUserID(){

}
// new user
// register
function addUser(){
$this->load->helper('url');

Expand Down
29 changes: 9 additions & 20 deletions www/application/models/User_Tweets_Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
36 changes: 35 additions & 1 deletion www/application/views/home.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,44 @@
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
error_reporting(0);

// shouldn't need the title and links below
?>

<title>Twitter Clone</title>
<link type="text/css" rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="/css/styles.css">

<div class="home container">
<h1>All Tweets</h1>
<?php foreach($posts as $post){?>

<?php $this->load->library('form_validation'); ?>
<?php echo validation_errors(); ?>
<?php echo form_open('all_tweets/search_keyword'); ?>
<input type="text" name = "keyword" />
<input type="submit" value = "Search" />
</form>

<?php foreach($results as $row){ ?>
<div class="tweet-container">
<div class="row">
<div class="col-md-6">
<?php echo "<h3>" . $row['first_name'] . " " . $row['last_name'] . "</h3>"; ?>
<?php echo "<h4>" . "@" . $row['username'] . "</h4>";?>
</div>
<div class="col-md-3 date">
<?php echo $row['date_time'];?>
</div>
</div>
<div class="row tweet italic">
<div class="col-md-12">
<?php echo "\"" . $row['tweet'] . "\"";?>
</div>
</div>
</div>
<?php } ?>

<?php foreach($posts as $post){ ?>
<div class="tweet-container">
<div class="row">
<div class="col-md-6">
Expand Down
2 changes: 1 addition & 1 deletion www/application/views/templates/footer.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<em>&copy; 2017 Stumper and Singh Studios</em>
<em>&copy; 2017 Singh and Stumper Studios</em>
<script type="text/javascript" src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
</body>
Expand Down

0 comments on commit 72e12bc

Please sign in to comment.