Welcome Guest, Not a member yet? Register   Sign In
Newbie, failed at the first hurdle!!!
#1

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')
{
 
       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);

Reply
#2

(This post was last modified: 01-08-2018, 04:07 PM by InsiteFX.)

In the Page Controller that was created in the beggining of the tutorial.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#3

PHP Code:
<?php

// Page Controller class 

class Pages extends CodeIgniter\Controller {

 
      public function view($page 'home')
        {
         
      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);
        } 

Reply
#4

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.
Reply
#5

(01-08-2018, 11:34 PM)XtreemDeveloper Wrote:     function __construct() {
        Parent::__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.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB