Skip to content

Commit

Permalink
compose tweet now on profile
Browse files Browse the repository at this point in the history
  • Loading branch information
cws13003 committed Dec 5, 2017
1 parent e24dfbd commit 98dc136
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 33 deletions.
14 changes: 0 additions & 14 deletions www/application/controllers/Search.php

This file was deleted.

20 changes: 20 additions & 0 deletions www/application/controllers/User_Tweets.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,24 @@ public function index() {
$this->load->view('templates/footer', NULL);
}

public function create(){
$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->data['posts'] = $this->User_Tweets_Model->getPosts(); // calling Post model method getPosts()
$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);
}
else
{
$this->User_Tweets_Model->addTweet();
redirect("/user_tweets");
}

}

}
7 changes: 2 additions & 5 deletions www/application/models/User_Tweets_Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,10 @@ function getPosts(){
}

function addTweet(){
$this->load->helper('url');

$slug = url_title($this->input->post('title'), 'dash', TRUE);

$this->load->helper('url');
$data = array(
'tweet' => $this->input->post('tweet'),
'user_id' => 1 // UPDATE THIS WITH SESSION DATA
'user_id' => 2 // UPDATE THIS WITH SESSION DATA
);

return $this->db->insert('Tweets', $data);
Expand Down
19 changes: 5 additions & 14 deletions www/application/views/tweet.php
Original file line number Diff line number Diff line change
@@ -1,18 +1,9 @@
<?php $this->load->library('form_validation'); ?>
<?php echo validation_errors(); ?>
<?php echo form_open('tweet'); ?>

<h2><?php echo $title; ?></h2>

<div class="container">
<div class="row">
<div class="col-md-2 col-md-offset-5">
<h5>Tweet</h5>
<input type="text" name="tweet" value="<?php echo set_value('tweet'); ?>" size="50" />
<?php echo form_error('tweet'); ?>
<!--<input type="hidden" name="user_id" value="<?php echo 'id' // USER ID HERE for tweet creation ?>"/>-->
<div><input class="btn" type="submit" value="Submit"/></div>
</div>
</div>
</div>
<h5>Tweet</h5>
<input type="text" name="tweet" value="<?php echo set_value('tweet'); ?>" size="50" />
<?php echo form_error('tweet'); ?>
<!--<input type="hidden" name="user_id" value="<?php echo 'id' // USER ID HERE for tweet creation ?>"/>-->
<div><input type="submit" value="Submit"/></div>
</form>
11 changes: 11 additions & 0 deletions www/application/views/user.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
<?php defined('BASEPATH') OR exit('No direct script access allowed'); ?>
<div class="home container">
<h1>My Tweets</h1>

<?php $this->load->library('form_validation'); ?>
<?php echo validation_errors(); ?>
<?php echo form_open('user_tweets/create'); ?>
<input type="text" name="tweet" value="<?php echo set_value('tweet'); ?>" size="50"/>
<?php echo form_error('tweet'); ?>
<!--<input type="hidden" name="user_id" value="<?php echo 'id' // USER ID HERE for tweet creation ?>"/>-->
<div><input type="submit" value="Tweet"/></div>
</form>


<?php foreach($posts as $post){ ?>
<div class="tweet-container">
<div class="row">
Expand Down

0 comments on commit 98dc136

Please sign in to comment.