i am working on view and i want to print task id from database in my view
following is my Controller function
Controller :-
function editMilestone($editid){
//, $taskid) {
if ($this->session->userdata('logged_in')) {
$session_data = $this->session->userdata('logged_in');
$id = $session_data['id'];
$username = $session_data['username'];
$is_master_admin = $session_data['master'];
$imagethumb = $session_data['imagethumb'];
$status_result = $this->getstatus->getEnumValues(MILESTONE, 'status');
$result = $this->milestonemodel->getEditMilestone($editid , $taskid);
$pendingbug = $this->bugmodel->getBug($id, $is_master_admin);
$pendingtask = $this->taskmodel->getTask($id, $is_master_admin);
if ($result == true) {
$session_msg_data = $this->session->userdata('msg');
if (isset($session_msg_data) && !empty($session_msg_data)) {
$milestonemsg = isset($session_msg_data['milestonemsg']) ? $session_msg_data['milestonemsg'] : '';
$milestoneopt = isset($session_msg_data['milestoneopt']) ? $session_msg_data['milestoneopt'] : '';
$this->session->unset_userdata('msg');
} else {
$milestonemsg = '';
$milestoneopt = '';
}
$data = '';
$data = array('username' => $username,
'is_master_admin' => $is_master_admin,
'imagethumb' => $imagethumb,
'result' => $result,
'taskid' => $taskid,
//'editid'=>$editid,
'status_result' => $status_result,
'profileopt' => $milestoneopt,
'profilemsg' => $milestonemsg,
'pendingtask' => $pendingtask,
'pendingbug' => $pendingbug
);
$this->load->view('milestone/edit_milestone', $data);
} else {
redirect('task', 'refresh');
}
} else {
//If no session, redirect to login page
redirect('home/logout', 'refresh');
}
}
Model :-
function getEditMilestone($id){
//, $taskid) {
$status = array(PUBLISH, UNPUBLISH, BLOCK);
$this->db->select('*');
$this->db->from(MILESTONE);
$this->db->where('id', $id);
//$this->db->where('taskid', $taskid);
$this->db->where_in('status', $status);
$this->db->limit(1);
//echo $this->db-last_query();
$query = $this->db->get();
if ($query->num_rows() == 1) {
return $query->result();
} else {
return false;
}
}
VIEW :- Milestone View
<div class="message">
<span class="arrow"></span>
<span class="body">
<?php
echo '<b> <U> Task Title </U>:- </b>  ';
echo $milestone_row->tasktitle;
echo '<br/>';
echo '<b> <U> Workspace Title </U>:- </b>  ';
echo $milestone_row->workspacetitle;
echo '<br/>';
echo '<b> <U> Description </U>:- </b>  ';
echo $milestone_row->description;
echo '<br/>';
echo '<b> <U> Hours </U>:- </b>  ';
echo $milestone_row->esthours;
echo 'hrs';
echo '<br/>';
echo '<b> <U> Minutes </U>:- </b>  ';
echo $milestone_row->estmin;
echo'mins';
echo '<br/>';
?>
Edit
</div>
When i click on edit link from above view it will transfer to editMilestone from controller and it wil transfer to to another view that is edit_milestone
View :- edit_milestone
<?php
$attributes = array('class' => 'form-horizontal', 'id' => 'form_add_milestone');
echo form_open('milestone/validateEditMilestone/'.$result[0]->id.'/'.$taskid, $attributes);
?>
<input type="text" readonly="readonly" value="<?php echo $taskid; ?>" name="taskid" />
I would like to print my taskid here from database
The problem is with the code. you are using $taskid when its not initialized in following line,
$result = $this->milestonemodel->getEditMilestone($editid , $taskid);
and when you put that value in $data it does not work because there is no value in $taskid
you should pass $taskid as parameter in Milestone View or create another query to fetch it from db.
Related
I am getting the following error when trying to add a new function to my existing product. I am new to php codeIgniter and have been stuck on this for a while. Any help will be appreciated and thanks in advance. If any further file is needed, let me know and I will update the post. When I try to submit the search_add_view form, I get the following error:
Error Was Encountered The action you have requested is not allowed.
my profile controller profile.php is:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Profile extends CI_Controller {
public function __construct()
{
parent::__construct();
$this->load->helper('url');
$this->load->helper('download');
$this->load->library('form_validation');
$this->load->library('table');
$this->load->model('searches_model');
$this->searches = $this->searches_model->get_searches();
$this->sites = $this->searches_model->get_sites();
$this->load->driver('scraper', array_column($this->sites, 'driver'));
//check auth
if (!is_admin() && !is_user()) {
redirect(base_url());
}
}
public function index()
{
if (user()->qr_code == '') {
$this->generate_qucode(user()->slug);
}
$data = array();
$data['page_title'] = 'Profile';
$data['user'] = $this->admin_model->get_user_info();
$data['payment'] = $this->admin_model->get_my_payment();
$data['features'] = $this->admin_model->active_features($data['payment']->package_id);
$data['fonts'] = $this->admin_model->select('google_fonts');
$data['countries'] = $this->admin_model->select('country');
$data['main_content'] = $this->load->view('admin/user/profile', $data, TRUE);
$this->load->view('admin/index', $data);
}
public function search_index()
{
$this->form_validation->set_rules('search[name]', 'Search Name', 'required');
$this->form_validation->set_rules('search[site_id]', 'Site', 'required');
$this->form_validation->set_rules('search[url]', 'Search URL', 'required');
if ($this->form_validation->run())
{
$data = $this->input->post('search', TRUE);
$search_id = $this->searches_model->add_search($data);
redirect();
}
$data = array(
'subview' => 'search_add_view',
'sites' => $this->sites,
'searches' => $this->searches
);
$data['page_title'] = 'Search View';
$data['subview'] = $this->load->view('admin/scraper/search_add_view', $data, TRUE);
$data['sites'] = $this->sites;
$data['searches'] = $this->searches;
$data['main_content'] = $this->load->view('admin/scraper/searches_view', $data, TRUE);
$this->load->view('admin/index', $data);
}
public function edit($search_id)
{
$search = $this->searches_model->get_search($search_id);
$this->form_validation->set_rules('search[name]', 'Search Name', 'required');
$this->form_validation->set_rules('search[site_id]', 'Site', 'required');
$this->form_validation->set_rules('search[url]', 'Search URL', 'required');
if ($this->form_validation->run())
{
$data = $this->input->post('search', TRUE);
$this->searches_model->update_search($search_id, $data);
redirect();
}
$data = array(
'subview' => 'search_edit_view',
'sites' => $this->sites,
'searches' => $this->searches,
'search' => $search
);
$data['main_content'] = $this->load->view('admin/scraper/search_edit_view', $data, TRUE);
$this->load->view('admin/index', $data);
}
/**
* Delete a search
*
* #param integer search id to delete
* #return none
*/
public function delete($search_id)
{
$search = $this->searches_model->get_search($search_id);
$search['id'] = $search_id;
if ($this->input->server('REQUEST_METHOD') == 'POST')
{
$data = array('id' => $search_id);
$this->searches_model->delete_search($data);
redirect();
}
$data = array(
'subview' => 'search_delete_view',
'sites' => $this->sites,
'searches' => $this->searches,
'search' => $search
);
$data['main_content'] = $this->load->view('admin/scraper/search_delete_view', $data, TRUE);
$this->load->view('admin/index', $data);
}
public function execute($search_id)
{
$search = $this->searches_model->get_search($search_id);
$this->form_validation->set_rules('search[url]', 'Search URL', 'required');
if ($this->form_validation->run())
{
$search['url'] = $this->input->post('search[url]', true);
$output = $this->scraper->scrape($search['url'], $search['driver']);
force_download($search['name'] . '.csv', $output);
}
$data = array(
'subview' => 'search_execute_view',
'sites' => $this->sites,
'searches' => $this->searches,
'search' => $search
);
$data['main_content'] = $this->load->view('admin/scraper/search_execute_view', $data, TRUE);
$this->load->view('admin/index', $data);
}
}
my routes.php is:
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
$route['default_controller'] = 'home/index';
$route['404_override'] = 'home/error_404';
$route['translate_uri_dashes'] = FALSE;
$route['index'] = 'home/index';
$route['error-404'] = 'home/error_404';
$uri = $this->uri->segment(1);
if ( $uri == 'searches_view' || $uri == 'search_add_view' || $uri == 'search_execute_view' || $uri == 'search_delete_view' || $uri == 'search_edit_view') {
$route['search_add_view/(:any)'] = 'admin/profile/search_add_view/$1';
$route['searches_view'] = 'admin/profile/search_index';
$route['search_execute_view'] = 'admin/profile/search_execute_view';
$route['search_delete_view'] = 'admin/profile/search_delete_view';
$route['search_edit_view'] = 'admin/profile/search_edit_view';
}
search_view.php is:
<?php include'include/header.php';?>
<?php include'include/left_sideber.php';?>
<div style="height:100vh; margin-left: 230px;" class="content">
<?php echo $subview;?>
<h2>Saved Searches</h2>
<?php
if (count($searches) == 0)
{
echo '<p>There are no saved searches.</p>';
}
else
{
$this->table->set_heading('Search Name', 'Site', 'Search URL', 'Edit', 'Delete', 'Execute');
foreach ($searches as $search)
{
$this->table->add_row(
$search['name'], $search['site_name'], $search['url'],
anchor('searches/edit/' . $search['id'], 'Edit'),
anchor('searches/delete/' . $search['id'], 'Delete'),
anchor('searches/execute/' . $search['id'], 'Execute')
);
}
echo $this->table->generate();
}
?>
<?php echo $main_content;?>
<?php include'include/footer.php';?>
search_add_view.php:
<div class="content">
<form method="post">
<fieldset>
<legend>Add a New Search</legend>
<p class="space">
<label for="name">Search Name</label>
<input type="text" id="name" name="search[name]" value="<?php echo set_value('search[name]', ''); ?>" size="32" maxlength="32" autofocus>
<?php echo form_error('search[name]', ' <br>', '<br>' . PHP_EOL); ?>
</p>
<p>
<label for="sites">Site</label>
<select id="sites" name="search[site_id]">
<option value="" selected>Select one</option>
<?php foreach ($sites as $row):?>
<option value="<?=$row['id']?>" <?php echo set_select('search[site_id]', $row['id']); ?>><?=$row['name']?></option>
<?php endforeach;?>
</select>
<?php echo form_error('search[site_id]', ' <br>', '<br>' . PHP_EOL); ?>
</p>
<p>
<label for="url">Search URL</label>
<input type="text" id="url" name="search[url]" value="<?php echo set_value('search[url]', ''); ?>" size="105" maxlength="254">
<?php echo form_error('search[url]', ' <br>', '<br>' . PHP_EOL); ?>
</p>
<p><input type="submit" name="submit" value="Ok"></p>
</fieldset>
</form>
<p> </p>
</div>
search_model.php:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
Class Searches_model extends CI_Model {
public function __construct()
{
parent::__construct();
$this->load->database();
}
public function get_searches()
{
return $this->db->query(
'SELECT
searches.id AS id,
searches.name AS name,
searches.url AS url,
sites.id AS site_id,
sites.name AS site_name,
sites.driver AS driver
FROM searches
INNER JOIN sites ON
searches.site_id = sites.id
;'
)->result_array();
}
public function get_search($search_id)
{
$query = $this->db->query(
'SELECT
searches.name AS name,
searches.url AS url,
sites.id AS site_id,
sites.name AS site_name,
sites.driver AS driver
FROM searches
INNER JOIN sites ON
searches.site_id = sites.id
WHERE searches.id = ' . $search_id . '
;'
)->result_array();
return $query[0];
}
public function add_search($data)
{
$this->db->insert('searches', $data);
return $this->db->insert_id();
}
public function update_search($id, $data)
{
$this->db->update('searches', $data, array('id' => $id));
}
public function delete_search($data)
{
$this->db->delete('searches', $data);
}
public function get_sites()
{
return $this->db->query(
'SELECT
sites.id AS id,
sites.name AS name,
sites.driver AS driver
FROM sites
;'
)->result_array();
}
}
my file structure is:
I managed to solve this issue with two steps:
First, I confirmed the config.json contains the following property:
$config['csrf_protection'] = TRUE;
Second, I had to add the following code to the html after form declaration:
<input type="hidden" name="<?php echo $this->security->get_csrf_token_name(); ?>" value="<?php echo $this->security->get_csrf_hash(); ?>">
I've just started to learning about CodeIgniter. But I stuck some point. After 7+ hours work and googling I decided to ask here. I am trying to update the database but I couldn't get out of it. After I enter data my data don't update. Here's my code ;
Takvim_Model.php
function __construct() {
parent::__construct();
}
public function insert($data) {
if ($this->db->insert('takvim', $data)) {
return true;
}
}
public function delete($roll_no) {
if ($this->db->delete('takvim', 'roll_no = '.$roll_no)) {
return true;
}
}
public function update($data,$old_roll_no) {
$this->db->set($data);
$this->db->where('roll_no', $old_roll_no);
$this->db->update('takvim', $data);
}
}
?>
Takvim_View.php
<!DOCTYPE html> <html lang = "en"> <head>
<meta charset = "utf-8">
<title>Takvim Example</title> </head> <body>
Add
<table border = "1">
<?php
$i = 1;
echo "<tr>";
echo "<td>Sr#</td>";
echo "<td>Roll No.</td>";
echo "<td>Name</td>";
echo "<td>Start Time</td>";
echo "<td>Stop Time</td>";
echo "<td>Update</td>";
echo "<td>Delete</td>";
echo "<tr>";
foreach($records as $r) {
echo "<tr>";
echo "<td>".$i++."</td>";
echo "<td>".$r->roll_no."</td>";
echo "<td>".$r->name."</td>";
echo "<td>".$r->start_time."</td>";
echo "<td>".$r->stop_time."</td>";
echo "<td><a href = '".base_url()."index.php/takvim/update/"
.$r->roll_no."'>Update</a></td>";
echo "<td><a href = '".base_url()."index.php/takvim/delete/"
.$r->roll_no."'>Delete</a></td>";
echo "<tr>";
}
?>
</table>
Takvim_Controller.php
<?php
class Takvim_controller extends CI_Controller {
function __construct() {
parent::__construct();
$this->load->helper('url');
$this->load->database();
}
public function index() {
$query = $this->db->get("takvim");
$data['records'] = $query->result();
$this->load->helper('url');
$this->load->view('Takvim_view', $data);
}
public function add_event_view() {
$this->load->helper('form');
$this->load->view('Takvim_add');
}
public function add_event() {
$this->load->model('Takvim_model');
$data = array (
'roll_no' => $this->input->post('roll_no'),
'name' => $this->input->post('name'),
'start_time' => $this->input->post('start_time')
);
$this->Takvim_model->insert($data);
$query = $this->db->get("takvim");
$data['records'] = $query->result();
$this->load->view('Takvim_view',$data);
}
public function update_event_view() {
$this->load->helper('form');
$roll_no = $this->uri->segment('3');
$query = $this->db->get_where("takvim",array("roll_no"=>$roll_no));
$data['records'] = $query->result();
$data = array('records' => $data['records']);
$this->load->view('Takvim_update',$data);
}
public function update_event(){
$this->load->model('Takvim_Model');
$data = array (
'roll_no' => $this->input->post('roll_no'),
'name' => $this->input->post('name'),
'start_time' => $this->input->post('start_time'),
'stop_time' => $this->input->post('stop_time')
);
$old_roll_no = $this->input->post('old_roll_no');
$this->Takvim_Model->update($data,$old_roll_no);
$query = $this->db->get("takvim");
$data['records'] = $query->result();
$this->load->view('Takvim_view',$data);
}
public function delete_event() {
$this->load->model('Takvim_Model');
$roll_no = $this->uri->segment('3');
$this->Takvim_Model->delete($roll_no);
$query = $this->db->get("takvim");
$data['records'] = $query->result();
$this->load->view('Takvim_view',$data);
}
} ?>
Takvim_Update.php
<!DOCTYPE html><html lang = "en"> <head> <meta charset = "utf-8">
<title>Takvim Example</title> </head> <body>
<form method = "" action = "">
<?php
echo form_open('Takvim_controller/update');
echo form_hidden('old_roll_no',$records[0]->roll_no);
echo form_label('Roll No.');
echo form_input(array('id'=>'roll_no',
'name'=>'roll_no','value'=>$records[0]->roll_no));
echo "
";
echo form_label('Name');
echo form_input(array('id'=>'name','name'=>'name',
'value'=>$records[0]->name));
echo "
";
echo form_label('Start Time');
echo form_input(array('id'=>'name','name'=>'name',
'value'=>$records[0]->start_time));
echo "
";
echo form_label('Stop Time');
echo form_input(array('id'=>'name','name'=>'name',
'value'=>$records[0]->stop_time));
echo "
";
echo form_submit(array('id'=>'submit','value'=>'Edit'));
echo form_close();
?>
</form>
Routes.php
$route['takvim'] = "Takvim_controller";
$route['takvim/add'] = 'Takvim_controller/add_event';
$route['takvim/add_view'] = 'Takvim_controller/add_event_view';
$route['takvim/update/(\d+)'] = 'Takvim_controller/update_event_view/$1';
$route['takvim/delete/(\d+)'] = 'Takvim_controller/delete_event/$1';
The name of model is not recomanded for Codeigniter
When you name a model use _model not _Model (This create conflit in your code)
In Takvim_Update.php you are submitting the form to 'Takvim_controller/update' and I can't see the update method in your Takvim_controller or the Takvim_controller/update route in your routes.php file.
First edit your Routes.php and add new route to your update method in Takvim_controller.
$route['takvim/update'] = 'Takvim_controller/update_event';
Then in Takvim_Update.php file submit your from to takvim/update url.
echo form_open('takvim/update');
try this:i hope it will help.
define routes.
$route['takvim/update/(:any)'] = 'Takvim_controller/update_event_view/$1';
//controller
first get data from table.and then update by whatever paramete's you want to update. for example i am giving primary key id of table.
$data=array(
'roll_no' => $this->input->post('roll_no'),
'name' => $this->input->post('name'),
'start_time' => $this->input->post('start_time'),
'stop_time' => $this->input->post('stop_time')
);
$this->Takvim_Model->update($id);
//model
function update($id){
return $this->db->where('id',$id)->update('table_name',$data);
}
my problem is a want to insert multiple check box on my web application.
error Message
Array to string conversion
please help....
Controller :
public function add_overview_product($type)
{
if ($this->input->post('submit')) {
$type = $type;
$id_overview = $this->input->post('id_overview');
$records = array();
for ($i=0; $i < count($id_overview) ; $i++) {
$records[] = array(
'type' => $type,
'id_overview' => $id_overview[$i]
);
}
$check_idoverview = $this->Biostar->check_idoverview($type,$id_overview);
if ($check_idoverview > 0) {
$message = 'Sorry, The Product can not input twice with the same "TYPE" ';
} else {
foreach ($records as $key => $value) {
$datafield = array(
'type' => $type,
'id_overview' => $id_overview
);
$this->Biostar->saveoverviewproduct($datafield);
}
$data['type'] = $type;
$data['content'] = 'biostar/add_specification';
$this->load->view('dashboard/index', $data);
}
}
$data['diy'] = $diy;
$data['content'] = 'biostar/add_overview_product';
$this->load->view('dashboard/index', $data);
}
My : Model
public function saveoverviewproduct($datafield){
$sql = $this->db->insert('overview_biostar',$datafield);
return $sql;
}
public function check_idoverview($type,$id_overview){
$this->db->select('type');
$this->db->where('type',$type);
$this->db->where('id_overview',$id_overview);
$query = $this->db->get('overview_biostar')->rows();
return $query;
}
View:
<form method="post"action="<?php echo base_url(); ?>biostar/add_overview_product/<?php echo $type; ?>" >
<div class="box-body">
<?php foreach ($audio as $row){ ?>
<div class="checkbox">
<label>
<input type="checkbox" name="id_overview[]" value="<?php echo $row['title']; ?>"><?php echo $row['title']; ?>
</label>
</div>
<?php } ?>
</div>
$check_idoverview = $this->Biostar->check_idoverview($type,$id_overview);
$id_overview is an array. It should be a string.
I've got a really weird issue that I can't seem to figure out or understand. So essentially I have a to grab the ID passed through the Codeigniter URI, have it populate a hidden form, and then submitted. However when I submit the form as hidden, it comes back saying the data is NULL. I have tried and changed it to form_input and it works fine. Can anyone help me or explain to me why this is the case?
I have tried the following solutions.
URL
http://localhost/list/players/add/1/
where I want URI 3 ('1') to pass on to the form and submitted.
Solution 1 - Having the URI pass straight to data array
Controller
function add() {
if($this->form_validation->run() == FALSE) {
$data['view_file'] = 'add';
$this->load->module('template');
$this->template->cmslayout($data);
} else {
$league_id = $this->uri->segment(3);
$data = array(
'leagues_id' => $league_id,
);
if($this->_insert($data)){
return $query;
}
redirect ('/players/');
}
}
Solution 2 - Grabbing the URI and fill a hidden form
Controller
function add() {
$league_id = $this->uri->segment(3);
$this->load->module('leagues');
$data['leagues_list'] = $this->leagues->get_where($league_id);
if($this->form_validation->run() == FALSE) {
$data['view_file'] = 'add';
$this->load->module('template');
$this->template->cmslayout($data);
} else {
$data = array(
'leagues_id' => $this->input->post('leagues_id'),
);
if($this->_insert($data)){
return $query;
}
redirect ('/players/');
}
}
View
<?php
echo form_open('players/add/');
?>
<?php
echo "<br>";
echo "<br>";
echo "League Name";
echo "<br>";
foreach ($leagues_list->result() as $row) {
$league_id = $row->id;
$league_name = $row->league_name;
echo $league_name;
$data = array( 'name' => 'leagues_id',
'value' => $league_id,
);
echo form_hidden($data);
}
echo "<br>";
echo "<br>";
$data = array( 'value' => 'Set Player',
'name' => 'submit',
'class' => 'submit-btn',
);
echo form_submit($data);
echo form_close();
?>
In both scenarios, on submit it comes back with an error saying leagues_id is NULL. Now I have tried in Solution 2 to change from 'form_hidden' to 'form_input' and straight away clicking submit and it works fine.
Can anyone help me or advise why this is the case?
Many thanks.
If you want to add a parameter to your controller's function, you have to add it to: function func($parameter = 0) (= 0 is optional for default value).
In this case you can access the parameter by $parameter.
In your View file, you can open your form to post to the current url. For this you need to load the url helper in your controller: $this->load->helper('url'); (or you can autoload it in application/autoload.php).
Your form_hidden declaration was bad too. If you want to declare it with array(), then you have to use this syntax:
$data = array(
'name' => 'John Doe',
'email' => 'john#example.com'
);
echo form_hidden($data);
// Would produce:
<input type="hidden" name="name" value="John Doe" />
<input type="hidden" name="email" value="john#example.com" />
More information on Form helper: https://ellislab.com/codeigniter/user-guide/helpers/form_helper.html
For the right solution, try this:
Controller
function add($league_id = 0)
{
if($league_id != 0)
{
$this->load->module('leagues');
$data['leagues_list'] = $this->leagues->get_where($league_id);
if($this->form_validation->run() == FALSE)
{
$data['view_file'] = 'add';
$this->load->module('template');
$this->template->cmslayout($data);
}
else
{
$data = array(
'leagues_id' => $this->input->post('leagues_id'),
);
if($this->_insert($data))
{
return $query;
}
redirect ('/players/');
}
}
View
<?php
echo form_open(current_url());
echo "<br /><br />";
echo "League Name <br />";
foreach ($leagues_list->result() as $row)
{
$league_id = $row->id;
$league_name = $row->league_name;
echo $league_name;
echo form_hidden('leagues_id', $league_id);
}
echo "<br /><br />";
$data = array(
'value' => 'Set Player',
'name' => 'submit',
'class' => 'submit-btn'
);
echo form_submit($data);
echo form_close();
?>
There is an error message when my view is being loaded. "Call to a member function result() on a non-object"
How do I fix this?
This is the loop in my View: discussion/view.php
<?php foreach ($query->result() as $result) : ?>
<tr>
<td>
<?php echo anchor('comments/index/'.$result->ds_id,$result->ds_title) . ' '
. $this->lang->line('comments_created_by') . $result->usr_name; ?>
<?php echo anchor('discussions/flag/'.$result->ds_id,
$this->lang->line('discussion_flag')) ; ?>
<br />
<?php echo $result->ds_body ; ?>
</td>
</tr>
<?php endforeach ; ?>
and this is the function index in my Comments Controller:
public function index() {
if ($this->input->post()) {
$ds_id = $this->input->post('ds_id');
} else {
$ds_id = $this->uri->segment(3);
}
$page_data['discussion_query'] = $this->Discussions_model->fetch_discussion($ds_id);
$page_data['comment_query'] = $this->Comments_model->fetch_comments($ds_id);
$page_data['ds_id'] = $ds_id;
$this->form_validation->set_rules('ds_id', $this->lang->line('comments_comment_hidden_id'), 'required|min_length[1]|max_length[11]');
$this->form_validation->set_rules('comment_name', $this->lang->line('comments_comment_name'), 'required|min_length[1]|max_length[25]');
$this->form_validation->set_rules('comment_email', $this->lang->line('comments_comment_email'), 'required|min_length[1]|max_length[255]');
$this->form_validation->set_rules('comment_body', $this->lang->line('comments_comment_body'), 'required|min_length[1]|max_length[5000]');
if ($this->form_validation->run() == FALSE) {
$this->load->view('common/header');
$this->load->view('nav/top_nav');
$this->load->view('comments/view', $page_data);
$this->load->view('common/footer');
} else {
$data = array('cm_body' => $this->input->post('comment_body'),
'usr_email' => $this->input->post('comment_email'),
'usr_name' => $this->input->post('comment_name'),
'ds_id' => $this->input->post('ds_id')
);
if ($this->Comments_model->new_comment($data)) {
redirect('comments/index/'.$ds_id);
} else {
// error
$this->data['message'] = 'Error!';
}
}
}