Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Own #8

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions application/config/config.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
defined('BASEPATH') or exit('No direct script access allowed');

/*
|--------------------------------------------------------------------------
Expand All @@ -23,7 +23,9 @@
| a PHP script and you can easily do that on your own.
|
*/
$config['base_url'] = 'http://localhost/DailyPosts-CI';
$config['base_url'] = ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == "on") ? "https" : "http");
$config['base_url'] .= "://" . $_SERVER['HTTP_HOST'];
$config['base_url'] .= str_replace(basename($_SERVER['SCRIPT_NAME']), "", $_SERVER['SCRIPT_NAME']);

/*
|--------------------------------------------------------------------------
Expand Down Expand Up @@ -52,7 +54,7 @@
|
| WARNING: If you set this to 'PATH_INFO', URIs will always be URL-decoded!
*/
$config['uri_protocol'] = 'REQUEST_URI';
$config['uri_protocol'] = 'REQUEST_URI';

/*
|--------------------------------------------------------------------------
Expand All @@ -76,7 +78,7 @@
| than english.
|
*/
$config['language'] = 'english';
$config['language'] = 'english';

/*
|--------------------------------------------------------------------------
Expand Down Expand Up @@ -400,11 +402,11 @@
| 'cookie_httponly') will also affect sessions.
|
*/
$config['cookie_prefix'] = '';
$config['cookie_domain'] = '';
$config['cookie_path'] = '/';
$config['cookie_secure'] = FALSE;
$config['cookie_httponly'] = FALSE;
$config['cookie_prefix'] = '';
$config['cookie_domain'] = '';
$config['cookie_path'] = '/';
$config['cookie_secure'] = FALSE;
$config['cookie_httponly'] = FALSE;

/*
|--------------------------------------------------------------------------
Expand Down
76 changes: 40 additions & 36 deletions application/controllers/Welcome.php
Original file line number Diff line number Diff line change
@@ -1,93 +1,97 @@
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
defined('BASEPATH') or exit('No direct script access allowed');

class Welcome extends CI_Controller
{

public function __construct()
{
parent::__construct();
$this->load->model(['queries']);
}

class Welcome extends CI_Controller {
public function index()
{
// 1. fetch from db via model
// 2. store returned data(array) in var
// 3. pass the stored data with view
$this->load->model('queries');
$posts = $this->queries->getPosts();
$this->load->view('welcome_message',['posts'=>$posts]);
$this->load->view('welcome_message', ['posts' => $posts]);
}


public function create(){
public function create()
{
$this->load->view('create');
}

public function update($id){
$this->load->model('queries');
public function update($id)
{
$post = $this->queries->getThisPost($id);
$this->load->view('update', ['post'=>$post]);
$this->load->view('update', ['post' => $post]);
}

public function view($id){
$this->load->model('queries');
public function view($id)
{
$post = $this->queries->getThisPost($id);
$this->load->view('view', ['post'=>$post]);
$this->load->view('view', ['post' => $post]);
}


public function delete($id){
$this->load->model('queries');
if($this->queries->deleteThisPost($id)){
$this->session->set_flashdata('msg', 'Post deleted successfully');
}else{
$this->session->set_flashdata('msg', 'failed to delete post');
}
redirect('welcome');
public function delete($id)
{
if ($this->queries->deleteThisPost($id)) {
$this->session->set_flashdata('msg', 'Post deleted successfully');
} else {
$this->session->set_flashdata('msg', 'failed to delete post');
}
redirect('welcome');
}


public function addPost(){
public function addPost()
{

$this->form_validation->set_rules('title', 'Title', 'trim|required|min_length[1]|max_length[50]');
$this->form_validation->set_rules('description', 'Description', 'trim|required|min_length[10]|max_length[1000]');

if($this->form_validation->run()){
if ($this->form_validation->run()) {
$data = $this->input->post();
$data['date_created'] = date('Y-m-d');
// rid of entra submit:submit b4 passing $data
unset($data['submit']);
$this->load->model('queries');
if($this->queries->add_post($data)){
if ($this->queries->add_post($data)) {
$this->session->set_flashdata('msg', 'Post uploaded successfully');
}else{
} else {
$this->session->set_flashdata('msg', 'failed to upload post');
}
redirect('welcome');


}else{
} else {
// redirect to same page
$this->load->view('create');
}
}

public function updatePost($id){
public function updatePost($id)
{

$this->form_validation->set_rules('title', 'Title', 'trim|required|min_length[1]|max_length[50]');
$this->form_validation->set_rules('description', 'Description', 'trim|required|min_length[10]|max_length[1000]');

if($this->form_validation->run()){
if ($this->form_validation->run()) {
$data = $this->input->post();
$data['date_created'] = date('Y-m-d');
// rid of entra submit:submit b4 passing $data
unset($data['submit']);
$this->load->model('queries');
if($this->queries->update_post($id, $data)){
if ($this->queries->update_post($id, $data)) {
$this->session->set_flashdata('msg', 'Post updated successfully');
}else{
} else {
$this->session->set_flashdata('msg', 'failed to update post');
}
redirect('welcome');


}else{
} else {
// redirect to same page
$this->load->view('update');
}
}
}
}