Moorcam Posted January 4, 2023 Share Posted January 4, 2023 Hi all, Hope you are all well and Happy New Year. Now, I have pulled hair out with this since last night. When I click on Add Testimonial it should open traveller/testimonial/add, which has a file name of view_traveller_testimonial_add.php But, when I click on the button to add a new Testimonial, it doesn't work. Just refreshed the page. Any ideas? Here is this file: <section class="content-header"> <div class="content-header-left"> <h1>Add Testimonial</h1> </div> <div class="content-header-right"> <a href="<?php echo base_url(); ?>traveller/testimonial" class="btn btn-primary btn-sm">View All</a> </div> </section> <section class="content"> <div class="row"> <div class="col-md-12"> <?php if($this->session->flashdata('error')) { ?> <div class="callout callout-danger"> <p><?php echo $this->session->flashdata('error'); ?></p> </div> <?php } if($this->session->flashdata('success')) { ?> <div class="callout callout-success"> <p><?php echo $this->session->flashdata('success'); ?></p> </div> <?php } ?> <?php echo form_open_multipart(base_url().'traveller/testimonial/add',array('class' => 'form-horizontal')); ?> <div class="box box-info"> <div class="box-body"> <div class="form-group"> <label for="" class="col-sm-2 control-label">Name <span>*</span></label> <div class="col-sm-6"> <input type="text" class="form-control" name="name" value="<?php echo $d_arr['traveller_name']; ?>"> </div> </div> <div class="form-group"> <label for="" class="col-sm-2 control-label">Website</label> <div class="col-sm-6"> <input type="url" autocomplete="off" class="form-control" name="url" value=""> </div> </div> <div class="form-group"> <label for="" class="col-sm-2 control-label">Comment <span>*</span></label> <div class="col-sm-6"> <textarea class="form-control" name="comment" style="height:200px;"></textarea> </div> </div> <div class="col-sm-6" hidden> <label for="" class="col-sm-2 control-label">Status</label> <input type="text" autocomplete="off" class="form-control" name="status" value="Pending"> </div> </div> <div class="form-group"> <label for="" class="col-sm-2 control-label"></label> <div class="col-sm-6"> <button type="submit" class="btn btn-success pull-left" name="form1">Submit</button> </div> </div> </div> </div> <?php echo form_close(); ?> </div> </div> </section> Here is the file that has the button to open the above page: <div class="dashboard-area bg-area pt_50 pb_80"> <div class="container wow fadeIn"> <div class="row"> <div class="col-md-3 col-sm-12 wow fadeIn" data-wow-delay="0.1s"> <div class="option-board mt_30"> <ul> <?php $this->view('view_traveller_sidebar'); ?> </ul> </div> </div> <div class="col-md-9 col-sm-12 wow fadeIn" data-wow-delay="0.2s"> <div class="box-body table-responsive"> <h1>My Testimonials</h1> <table id="example1" class="table table-bordered table-striped"> <thead> <tr> <th>Serial</th> <th>Name</th> <th>Comment</th> </tr> </thead> <tbody> <?php $i=0; foreach ($my_testimonial as $row) { $i++; $CI =& get_instance(); $CI->load->model('Model_testimonial'); $CI->load->model('Model_traveller'); $d_arr = $CI->Model_traveller->get_traveller_name_by_id($row['traveller_id']); ?> <tr> <td><?php echo $i; ?></td> <td><?php echo $d_arr['traveller_name']; ?></td> <td><?php echo $row['comment']; ?></td> </tr> <?php } ?> </tbody> </table> <div class="box-body"> <a href="<?php echo base_url(); ?>traveller/testimonial/add" class="btn btn-primary btn-sm">Add Testimonial</a> </div> </div> </div> </div> </div> </div> Here is my Controller: <?php defined('BASEPATH') OR exit('No direct script access allowed'); class Testimonial extends CI_Controller { function __construct() { parent::__construct(); $this->load->model('traveller/Model_common'); $this->load->model('traveller/Model_testimonial'); } public function index() { $data['setting'] = $this->Model_common->get_setting_data(); $data['testimonial'] = $this->Model_testimonial->show(); $this->load->view('traveller/view_header',$data); $this->load->view('traveller/view_testimonial',$data); $this->load->view('traveller/view_footer'); } public function add() { $data['setting'] = $this->Model_common->get_setting_data(); $error = ''; $success = ''; if(isset($_POST['form1'])) { $valid = 1; $this->form_validation->set_rules('name', 'Name', 'trim|required'); $this->form_validation->set_rules('comment', 'Comment', 'trim|required'); if($this->form_validation->run() == FALSE) { $valid = 0; $error .= validation_errors(); } if($valid == 1) { $next_id = $this->Model_testimonial->get_auto_increment_id(); foreach ($next_id as $row) { $ai_id = $row['Auto_increment']; } $form_data = array( 'name' => $_POST['name'], 'url' => $_POST['url'], 'status' => $_POST['status'], 'comment' => $_POST['comment'] ); $this->Model_testimonial->add($form_data); $success = 'Testimonial is added successfully!'; $this->session->set_flashdata('success',$success); redirect(base_url().'traveller/testimonial'); } else { $this->session->set_flashdata('error',$error); redirect(base_url().'traveller/testimonial/add'); } } else { $this->load->view('traveller/view_header',$data); $this->load->view('traveller/view_testimonial_add',$data); $this->load->view('traveller/view_footer'); } } public function edit($id) { // If there is no testimonial in this id, then redirect $tot = $this->Model_testimonial->testimonial_check($id); if(!$tot) { redirect(base_url().'traveller/testimonial'); exit; } $data['setting'] = $this->Model_common->get_setting_data(); $error = ''; $success = ''; if(isset($_POST['form1'])) { $valid = 1; $this->form_validation->set_rules('name', 'Name', 'trim|required'); $this->form_validation->set_rules('comment', 'Comment', 'trim|required'); if($this->form_validation->run() == FALSE) { $valid = 0; $error .= validation_errors(); } if($valid == 1) { $data['testimonial'] = $this->Model_testimonial->get_testimonial($id); $form_data = array( 'name' => $_POST['name'], 'url' => $_POST['url'], 'status' => $_POST['status'], 'comment' => $_POST['comment'] ); $this->Model_testimonial->update($id,$form_data); $success = 'Testimonial is updated successfully'; $this->session->set_flashdata('success',$success); redirect(base_url().'traveller/testimonial'); } else { $this->session->set_flashdata('error',$error); redirect(base_url().'traveller/testimonial/edit'.$id); } } else { $data['testimonial'] = $this->Model_testimonial->get_testimonial($id); $this->load->view('traveller/view_header',$data); $this->load->view('traveller/view_testimonial_edit',$data); $this->load->view('traveller/view_footer'); } } public function delete($id) { // If there is no testimonial in this id, then redirect $tot = $this->Model_testimonial->testimonial_check($id); if(!$tot) { redirect(base_url().'traveller/testimonial'); exit; } $data['testimonial'] = $this->Model_testimonial->get_testimonial($id); if($data['testimonial']) { unlink('./public/uploads/'.$data['testimonial']['photo']); } $this->Model_testimonial->delete($id); $success = 'Testimonial is deleted successfully'; $this->session->set_flashdata('success',$success); redirect(base_url().'traveller/testimonial'); } } And my Model: <?php defined('BASEPATH') OR exit('No direct script access allowed'); class Model_testimonial extends CI_Model { function get_auto_increment_id() { $sql = "SHOW TABLE STATUS LIKE 'tbl_testimonial'"; $query = $this->db->query($sql); return $query->result_array(); } function show() { $sql = "SELECT * FROM tbl_testimonial ORDER BY id ASC"; $query = $this->db->query($sql); return $query->result_array(); } function add($data) { $this->db->insert('tbl_testimonial',$data); return $this->db->insert_id(); } function update($id,$data) { $this->db->where('id',$id); $this->db->update('tbl_testimonial',$data); } function delete($id) { $this->db->where('id',$id); $this->db->delete('tbl_testimonial'); } function get_testimonial($id) { $sql = 'SELECT * FROM tbl_testimonial WHERE id=?'; $query = $this->db->query($sql,array($id)); return $query->first_row('array'); } function testimonial_check($id) { $sql = 'SELECT * FROM tbl_testimonial WHERE id=?'; $query = $this->db->query($sql,array($id)); return $query->first_row('array'); } } Really appreciate the help guys. Thanks in advance. Quote Link to comment https://forums.phpfreaks.com/topic/315757-page-not-loading-in-codeigniter/ Share on other sites More sharing options...
Solution maxxd Posted January 4, 2023 Solution Share Posted January 4, 2023 It's been a while since I've used CodeIgniter - especially an older version - but I don't see where you've loaded the URL helper. Check here for more information. Quote Link to comment https://forums.phpfreaks.com/topic/315757-page-not-loading-in-codeigniter/#findComment-1604197 Share on other sites More sharing options...
Moorcam Posted January 4, 2023 Author Share Posted January 4, 2023 38 minutes ago, maxxd said: It's been a while since I've used CodeIgniter - especially an older version - but I don't see where you've loaded the URL helper. Check here for more information. Hey man, Yeah it's in the Controller: $this->load->view('traveller/view_testimonial_add',$data); Yeah I'm still learning it. Went for an older version because I was told it's easier. It is but this has me stumped. Quote Link to comment https://forums.phpfreaks.com/topic/315757-page-not-loading-in-codeigniter/#findComment-1604199 Share on other sites More sharing options...
maxxd Posted January 4, 2023 Share Posted January 4, 2023 Loading the URL helper is not the same as loading the view. Follow the link in my post. To be honest, it's not going to be easier. CI4 uses more modern techniques and coding practices so you'll have an easier time not only getting answers to specific questions (the CI4 boards on the forum as active), but you'll be able to google the techniques more generally. Quote Link to comment https://forums.phpfreaks.com/topic/315757-page-not-loading-in-codeigniter/#findComment-1604210 Share on other sites More sharing options...
Moorcam Posted January 18, 2023 Author Share Posted January 18, 2023 You were correct. I was loading the URL wrong. Don't ask me now what I did because I can't remember lol but your advice led to the solution. Quote Link to comment https://forums.phpfreaks.com/topic/315757-page-not-loading-in-codeigniter/#findComment-1604814 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.