• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
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
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-09-2018, 12:34 AM)XtreemDeveloper Wrote:     function __construct() {
        Parent::__construct();        
    }

Don't do this, it's pointless.

(01-09-2018, 12:34 AM)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


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


Users browsing this thread:
1 Guest(s)


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2018 MyBB Group.