Welcome Guest, Not a member yet? Register   Sign In
Non-static method Pages::view() cannot be called statically
#1

Hello,

I'm developing a site and used the example provided in the documentation here:
http://www.codeigniter.com/user_guide/tu...pages.html to be able to have one controller for all my static pages.

It works fine on my localhost but when I push online this is what happens:

Code:
Severity: Runtime Notice

Message: Non-static method Pages::view() cannot be called statically

Filename: core/CodeIgniter.php

Line Number: 419

Backtrace:

File: /others/site/dev/index.php
Line: 315
Function: require_once

After searching online some people say adding 'static' to
PHP Code:
public static function view($page 'home'){ 
might fixed but it didn't.

Any ideas? Thank you
Reply
#2

(This post was last modified: 08-31-2016, 11:44 PM by orionstar.)

You can't use static for action functions! Static is a php keyword it's not related with static pages...
Without the "static" word, exactly what is the error message?
Reply
#3

(08-31-2016, 11:43 PM)orionstar Wrote: You can't use static for action functions! Static is a php keyword it's not related with static pages...
Without the "static" word, exactly what is the error message?

Without the static keyword that's my error message above "Non-static method Pages::view() cannot be called statically"
Reply
#4

This is what my code looks like
PHP Code:
class Pages extends CI_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);
 
       $data['description'] = "Description";
 
       $data['keywords'] = "Keywords";
 
       $data['page'] = 'pages/'.$page;
 
       $this->load->view('templates/template'$data);
 
   }

Reply
#5

(This post was last modified: 09-01-2016, 11:40 AM by InsiteFX.)

You need a __construct() method in your controller, if you are extending another class you always use a constructor to access the constructor of the other class.

Also make sure that you add the routes.

If that does not fix it then you have other problems.
What did you Try? What did you Get? What did you Expect?

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

(This post was last modified: 09-01-2016, 01:28 PM by orionstar.)

(09-01-2016, 11:40 AM)InsiteFX Wrote: You need a __construct() method in your controller, if you are extending another class you always use a constructor to access the constructor of the other class.

The constructor function can be omitted, then the parent's constructor will be executed.

@keld 
I think we need more info to help you:
Which PHP version do you use? (you can use phpinfo() to find it out...)
Which CodeIgniter version do you use? (you can find the version here: system/core/CodeIgniter.php line 58)

Please show us your routes from the routes.php!
Reply
#7

Sorry for all the trouble I updated my server to the latest version of PHP (5.6.24) available on my shared host and all the errors magically disappeared. I realized with horror that I was on PHP 5.2 (kill me).
Reply




Theme © iAndrew 2016 - Forum software by © MyBB