Newbie, failed at the first hurdle!!! |
I'm following the tutorial and I have reached "Adding logic to the controller"
This says at the following code to load the page, but my question is, where do I add this code? Sorry if I am being a bit thick, but it doesn't say where to put it!! Thanks for your patience Ian PHP Code: public function view($page = 'home') PHP Code: <?php
You can use this code for adding this code for check view file
<?php defined('BASEPATH') OR exit('No direct script access allowed'); class Welcome extends CI_Controller { function __construct() { Parent::__construct(); } public function index($page = 'home') { echo APPPATH.'views/pages/'.$page.'.php'; die; if ( ! file_exists(APPPATH.'views/pages/'.$page.'.php')) { // Whoops, we don't have a page for that! show_404(); } $data['title'] = ucfirst($page); // Capitalize the first letter $this->load->view('templates/header', $data); $this->load->view('pages/'.$page, $data); $this->load->view('templates/footer', $data); } } But this is not correct way to handle view file. (01-08-2018, 11:34 PM)XtreemDeveloper Wrote: function __construct() { Don't do this, it's pointless. (01-08-2018, 11:34 PM)XtreemDeveloper Wrote: But this is not correct way to handle view file. So don't suggest it then. The thread is about the tutorial anyway, not asking for random code. |
Welcome Guest, Not a member yet? Register Sign In |