Gagal menambahkan data judul,isi,dan foto. malah di lempar ke tambah_pendidikan_aksi.

<--! controler -->


<!-- pendidikan form -->

<div class="container-fluid">

	<div class="alert alert-success" role="alert">
		<i class="fas fa-university"></i> FORM INPUT DATA SAMBUTAN REKTOR
	</div>

	<?php echo form_open_multipart('administrator/sambutan_rektor/tambah_sambutan_rektor_aksi') ?>

	    <div class="form-grup">
			<label>JUDUL</label>
			<input type="text" name="judul" class="form-control">
			<?php echo form_error('judul','<div class="text-danger small ml-3">','</div>') ?>
	    </div>

	    <div class="form-grup">
			<label>ISI</label>
			<textarea type="text" name="isi" class="form-control" rows="5" close="250"></textarea>
			<?php echo form_error('isi','<div class="text-danger small ml-3">','</div>') ?>
	    </div>

	    <div class="form-grup">
	    	<label>PHOTO</label><br>
	    	<input type="file" name="photo">
	    </div>

	    <button type="submit" class="btn btn-primary md-5 mt-3"> Simpan</button>

	<?php form_close(); ?>
</div>
<!-- pendidikan view -->

<div class="container-fluid">

	<div class="alert alert-succes" role="alert">
		<i class="fas fa-university"></i> PENDIDIKAN
	</div>

	<?php echo $this->session->flashdata('pesan') ?>

	<?php echo anchor('administrator/pendidikan/tambah_pendidikan','<button class="btn btn-sm btn-primary mb-3"><i class="fas fa-plus fa-sm"></i> Tambah Pendidikan</button>') ?>

	<table class="table table-striped table-hover table-bordered">
		<tr>
			<th>NO</th>
			<th>JUDUL</th>
			<th>ISI</th>
			<th colspan="3">AKSI</th>
		</tr>

		<?php

		$no=1;
		foreach($pendidikan as $pnd) : ?>

			<tr>
				<td><?php echo $no++ ?></td>
				<td><?php echo $pnd->judul ?></td>
				<td><?php echo $pnd->isi ?></td>

				<td width="20px"><?php echo anchor('administrator/pendidikan/detail/'.$pnd->id_pendidikan,'<div class="btn btn-sm btn-info"><i class="fa fa-eye"></i></div>') ?></td>
				<td width="20px"><?php echo anchor('administrator/pendidikan/update/'.$pnd->id_pendidikan,'<div class="btn btn-sm btn-primary"><i class="fa fa-edit"></i></div>') ?></td>
				<td width="20px"><?php echo anchor('administrator/pendidikan/delete/'.$pnd->id_pendidikan,'<div class="btn btn-sm btn-danger"><i class="fa fa-trash"></i></div>') ?></td>
			</tr>

		<?php endforeach; ?>
	</table>
</div>

<?php

class Pendidikan extends CI_Controller{

	function __construct() {
		parent::__construct();

		if (!isset($this->session->userdata['username'])) {
			$this->session->set_flashdata('pesan','<div class="alert alert-denger aler-dismissible fade show" role="alter">Anda Belum Login!<button type="button" class="close"
						  data-dismiss="alert" aria-lable="close">
						 <span aria-hidden="true">×</span>
					   </button>
					  </div>');
			redirect('administrator/auth');
		}
	}

	public function index()
	{
		$data['pendidikan'] = $this->pendidikan_model->tampil_data('pendidikan')->result();
		$this->load->view('templates_administrator/header');
		$this->load->view('templates_administrator/sidebar');
		$this->load->view('administrator/pendidikan',$data);
		$this->load->view('templates_administrator/footer');
	}

	public function detail($id)
	{
		$data['detail'] = $this->pendidikan_model->ambil_id_pendidikan($id);
		$this->load->view('templates_administrator/header');
		$this->load->view('templates_administrator/sidebar');
		$this->load->view('administrator/pendidikan_detail',$data);
		$this->load->view('templates_administrator/footer');
	}

	public function tambah_pendidikan()
	{
		$this->load->view('templates_administrator/header');
		$this->load->view('templates_administrator/sidebar');
		$this->load->view('administrator/pendidikan_form');
		$this->load->view('templates_administrator/footer');
	}

	public function tambah_pendidikan_aksi()
	{
		$this->_rules();

		if($this->form_validation->run() == FALSE) {
			$this->tambah_pendidikan();
		}else{
			$id_pendidikan 				= $this->input->post('id_pendidikan');
			$judul 				= $this->input->post('judul');
			$isi 				= $this->input->post('isi');
			$photo							= $_FILES['photo'];
			if ($photo=''){}else{
				$config['upload_path'] = './assets/uploads';
				$config['allowed_types'] = 'jpg|png|gif|tiff|jpeg';

				$this->load->library('upload',$config);
				if(!$this->upload->do_upload('photo')){
					echo "Gagal Upload"; die();
				}else{
					$photo=$this->upload->data('file_name');
				}
			}

			$data = array(
				'judul'			=> $judul,
				'isi'			=> $isi,
				'photo'					=> $photo,
			);

			$this->pendidikan_model->insert_data($data,'pendidikan');
			$this->session->set_flashdata('pesan','<div class="alert alert-success alert-dismissible fade show" role="alert"> Data pendidikan Berhasil di Tambahkan!
						<button type="button" class="close" data-dismiss="alert"
						     ari-label="close"><span aria-hidden="true">×</span>
						</button>
			  		</div>');
			redirect('administrator/pendidikan');
		}

	}





	public function update($id)
	{
		$where = array('id_pendidikan' => $id);
		$data['pendidikan'] = $this->pendidikan_model->edit_data($where,'pendidikan')->result();
		$this->load->view('templates_administrator/header');
		$this->load->view('templates_administrator/sidebar');
		$this->load->view('administrator/pendidikan_update',$data);
		$this->load->view('templates_administrator/footer');
	}

	public function update_pendidikan_aksi()
	{
		$this->_rules();

		if($this->form_validation->run() == FALSE)
		{
			$this->update();
		}else{
			$id 						= $this->input->post('id_pendidikan');
			$judul 			= $this->input->post('judul');
			$isi 			= $this->input->post('isi');
			$photo						= $_FILES['userfile']['name'];

			if ($photo){
				$config['upload_path'] = './assets/uploads';
				$config['allowed_types'] = 'jpg|png|gif|tiff';

				$this->load->library('upload',$config);

				if($this->upload->do_upload('userfile')){
					$userfile = $this->upload->data('file_name');
					$this->db->set('photo', $userfile);
				}else{
					echo "Galal Upload";
				}
			}

			$data = array (
				'judul'			=> $judul,
				'isi'			=> $isi,
			);

			$where = array('id_pendidikan' => $id);

			$this->pendidikan_model->update_data($where,$data,'pendidikan');
			$this->session->set_flashdata('pesan','<div class="alert alert-success alert-dismissible fade show" role="alert"> Data pendidikan Berhasil Diupdate!
						<button type="button" class="close" data-dismiss="alert" aria-label="close"><span aria-hidden="true">×</span>
						</button>
				  	</div>');
			redirect('administrator/pendidikan');


		}
	}


	public function delete ($id)
	{
		$where = array('id_pendidikan' => $id);
		$this->pendidikan_model->hapus_data($where,'pendidikan');
		$this->session->set_flashdata('pesan','<div class="alert alert-danger alert-dismissible fade show" role="alert"> Data pendidikan Berhasil Dihapus!
					<button type="button" class="close" data-dismiss="alert" aria-label="close"><span aria-hidden="true">×</span>
				</button>
		  	</div>');
		redirect('administrator/pendidikan');
	}

	public function _rules()
	{

		$this->form_validation->set_rules('judul','Judul','required',[
			'required' => 'Judul wajib diisi'
		]);

		$this->form_validation->set_rules('isi','Isi','required',[
			'required' => 'Isi wajib diisi'
		]);

		$this->form_validation->set_rules('photo','Photo','required',[
			'required' =>  'Photo wajib diisi'
		]);

	}
}

avatar regasatya
@regasatya

1 Kontribusi 0 Poin

Diperbarui 4 tahun yang lalu

Tanggapan

bertanya dengan jelas, jangan cuma paste kode begitu saja "baca aturan main"

1 Jawaban:

ini layaknya nyari jarum dalam jerami...

avatar asruldev
@asruldev

17 Kontribusi 10 Poin

Dipost 4 tahun yang lalu

Login untuk ikut Jawaban