public function showPage(Request $request) { $page = $request->input('page'); if($page == 'home') { return view('home'); } elseif($page == 'profile') { return view('profile'); } else { return view('404'); } }
public function showProduct($id) { $product = $this->product_model->getById($id); if($product->category == 'books') { $this->load->view('books_view'); } elseif($product->category == 'electronics') { $this->load->view('electronics_view'); } else { $this->load->view('default_view'); } }In this example, we are querying the database to get information about a specific product. Based on the product's category, we use the setView method to load the appropriate view template. Package library: CodeIgniter