Skip to content

Commit

Permalink
controller updates
Browse files Browse the repository at this point in the history
  • Loading branch information
cws13003 committed Dec 4, 2017
1 parent 54bade5 commit c796f73
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 92 deletions.
87 changes: 0 additions & 87 deletions db/lamp_2017-12-01.sql

This file was deleted.

19 changes: 17 additions & 2 deletions www/application/controllers/User_Tweets.php
Original file line number Diff line number Diff line change
@@ -1,17 +1,32 @@
<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Users_Tweets extends CI_Controller {
class User_Tweets extends CI_Controller {

function __Construct(){
parent::__Construct ();
$this->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
}
Expand Down
17 changes: 14 additions & 3 deletions www/application/models/Users_Tweets_Model.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
<?php
class User_Tweets_Model extends CI_Model {
class Users_Tweets_Model extends CI_Model {

public function __construct()
{
$this->load->database();
}
function getPosts(){
$_SESSION['user_id'] = $id;

//$_SESSION['user_id'] = $id;


$this->db->select("first_name, last_name, username, tweet, date_time");
Expand All @@ -14,5 +18,12 @@ function getPosts(){
return $query->result_array();
}

function addTweet(){
$this->load->helper('url');
$data = array(
'tweet' => $this->input->post('tweet')
);
}

}
?>
17 changes: 17 additions & 0 deletions www/application/views/user.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,23 @@
<body>

<h1>Tweets Feed</h1>
<?php
$this->load->library('form_validation');
echo validation_errors();
echo form_open('user_tweets'); ?>

<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>
</form>



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

0 comments on commit c796f73

Please sign in to comment.