<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Home extends CI_Controller {
public function __construct()
{
parent::__construct();
$this->load->database();
$this->load->library('session');
$this->load->helper(['url', 'text']);
}
// ===============================================================
// 1. HALAMAN UTAMA (LANDING PAGE)
// ===============================================================
public function index() {
// 1. Ambil data Landing Page (Hero, About, Kontak Footer, dll)
$data['landing'] = $this->db->get_where('tb_landing_page', ['id' => 1])->row_array();
// 2. Ambil Menu Dinamis untuk Navbar
$data['menus'] = $this->db->order_by('urutan', 'ASC')
->get_where('tb_menus_frontend', ['is_active' => 1])
->result_array();
// 3. [PENTING] AMBIL DATA SECTIONS (KONTEN YANG DIBUAT ADMIN)
// Tanpa ini, konten yang Anda buat di Admin tidak akan muncul
$data['sections'] = $this->db->order_by('urutan', 'ASC')
->get_where('tb_landing_sections', ['is_active' => 1])
->result_array();
$data['title'] = 'Home - PT. Matsuoka Industries Indonesia';
// 4. Load View (Menampilkan Halaman)
$this->load->view('v_landing_page', $data);
}
// ===============================================================
// 2. HALAMAN DINAMIS (CUSTOM PAGES)
// ===============================================================
public function view_page($slug = null)
{
if (!$slug) { show_404(); }
// A. Cari halaman
$page = $this->db->get_where('tb_pages', ['slug' => $slug, 'is_active' => 1])->row_array();
if (!$page) { show_404(); }
// B. Ambil Data Footer & Menu (Agar navbar & footer tetap muncul)
$data['landing'] = $this->db->get_where('tb_landing_page', ['id' => 1])->row_array();
$data['menus'] = $this->db->order_by('urutan', 'ASC')
->get_where('tb_menus_frontend', ['is_active' => 1])
->result_array();
// C. Logika Bahasa
$lang_sfx = ($this->session->userdata('site_lang') == 'english') ? '_en' : '_id';
$content = $page['content' . $lang_sfx];
if (empty($content)) { $content = $page['content_id']; }
// D. Kirim ke View
$data['title'] = $page['title'];
$data['page_content'] = $content;
$this->load->view('frontend/v_dynamic_page', $data);
}
}