Fatal error: Call to a member function get_where() on a non-object in C:\Program Files (x86)\EasyPHP-DevServer-14.1VC9\data\localweb\masterlinkci2\application\site\models\gallery_model.php on line 10

I try this :

Line 10: $query = $this->db->get_where('galleries_pictures',array('pic_id'=> $pic_unique_id));

class Gallery_model extends CI_Model {
    public function get_picture($pic_unique_id)
    {
        $query = $this->db->get_where('galleries_pictures',array('pic_id'=> $pic_unique_id));
        return $query->result();
    }
}

IN Controller:

public function index()
{
   $this->load->helper('url');
    $this->load->model('gallery_model');//loads model
    $data['pic']  = $this->gallery_model->get_picture($pic_unique_id);//calls to model function
    $this->load->view('index',$data);//loads view with data
}

IN view

<?php foreach($pic as $pic_item) { ?> <img src="<?php echo base_url(assets1/images/slider/).$pic_item->pic_item; ?>"> <?php } ?>

Hi,

are you loading the database library? You can do that in the application/config/autoload.php file, to make it available in all controllers and models:

$autoload['libraries'] = array('database');

Instead, if you do not want to load it for every resource, you can load it in the constructor of the model or in the specific method. For example:

<?php

class Gallery_model extends CI_Model
{

    public function __construct()
    {
        parent::__construct();
        $this->load->database();
    }

    public function get_picture($id) { /* ... */ }

}

It could go also in the controller (method or constructor), the library then would be used by the loaded models as well.

See:

I reduce the error message. Now, there is another error message that I have not mention:

Warning: include(C:\Program Files (x86)\EasyPHP-DevServer-14.1VC9\data\localweb\masterlinkci2\application\site\views\errors\html\error_php.php): failed to open stream: No such file or directory in C:\Program Files (x86)\EasyPHP-DevServer-14.1VC9\data\localweb\masterlinkci2\system\core\Exceptions.php on line 268

Warning: include(): Failed opening 'C:\Program Files (x86)\EasyPHP-DevServer-14.1VC9\data\localweb\masterlinkci2\application\site\views\errors\html\error_php.php' for inclusion (include_path='.;C:\php\pear') in C:\Program Files (x86)\EasyPHP-DevServer-14.1VC9\data\localweb\masterlinkci2\system\core\Exceptions.php on line 268

Warning: include(C:\Program Files (x86)\EasyPHP-DevServer-14.1VC9\data\localweb\masterlinkci2\application\site\views\errors\html\error_php.php): failed to open stream: No such file or directory in C:\Program Files (x86)\EasyPHP-DevServer-14.1VC9\data\localweb\masterlinkci2\system\core\Exceptions.php on line 268

Warning: include(): Failed opening 'C:\Program Files (x86)\EasyPHP-DevServer-14.1VC9\data\localweb\masterlinkci2\application\site\views\errors\html\error_php.php' for inclusion (include_path='.;C:\php\pear') in C:\Program Files (x86)\EasyPHP-DevServer-14.1VC9\data\localweb\masterlinkci2\system\core\Exceptions.php on line 268

Warning: include(C:\Program Files (x86)\EasyPHP-DevServer-14.1VC9\data\localweb\masterlinkci2\application\site\views\errors\html\error_php.php): failed to open stream: No such file or directory in C:\Program Files (x86)\EasyPHP-DevServer-14.1VC9\data\localweb\masterlinkci2\system\core\Exceptions.php on line 268

Warning: include(): Failed opening 'C:\Program Files (x86)\EasyPHP-DevServer-14.1VC9\data\localweb\masterlinkci2\application\site\views\errors\html\error_php.php' for inclusion (include_path='.;C:\php\pear') in C:\Program Files (x86)\EasyPHP-DevServer-14.1VC9\data\localweb\masterlinkci2\system\core\Exceptions.php on line 268

Ok, so you changed the $application_folder value to application/site, is this correct?

Are you creating an application folder named site inside the application folder? I mean, do you have something like the following:

application/
└── site
    ├── cache
    ├── config
    ├── controllers
    ├── core
    ├── helpers
    ├── hooks
    ├── index.html
    ├── language
    ├── libraries
    ├── logs
    ├── models
    ├── third_party
    └── views
        └── errors
            ├── cli
            └── html

Otherwise restore the $application_folder value to his default application and it should work fine.

See: https://www.codeigniter.com/user_guide/general/managing_apps.html

Well, I redirect application_folder value to application/site since I divided application folders into two folders admin and site. admin for backend and site for frontend.

Is there any other way to make this things work? I can see the admin page easily already. And still have error when viewing the site.

In this code:

class Gallery_model extends CI_Model {
    public function get_picture($pic_unique_id)
    {
        $query = $this->db->get_where('galleries_pictures',array('pic_id'=> $pic_unique_id));
        return $query->result();
    }
}

So, show where you are creating and initializing Gallery_model. Also show the full structure and definition of CI_Model and Gallery_model. Seems that you aren't initializing the db member variable properly.

How to inilialize db member variable properly ?

I already add this on top:

public function __construct()
    {
        parent::__construct();
        $this->load->database();

    }

and still receiving that same error:

Warning: include(C:\Program Files (x86)\EasyPHP-DevServer-14.1VC9\data\localweb\masterlinkci2\application\site\views\errors\html\error_php.php): failed to open stream: No such file or directory in C:\Program Files (x86)\EasyPHP-DevServer-14.1VC9\data\localweb\masterlinkci2\system\core\Exceptions.php on line 268

Well, I redirect application_folder value to application/site since I divided application folders into two folders admin and site. admin for backend and site for frontend.
[...]
and still receiving that same error:

To make it work, both applications must have the requested folders and files. In practice make a copy of what is inside application/ into application/admin/ and application/site/. I'm assuming your admin panel is inside the application/admin/ folder. So you end up with something like this:

.
├── .htaccess                        <-- 1st .htaccess
├── admin
│   ├── .htaccess                    <-- 2nd .htaccess
│   └── index.php
├── application
│   ├── admin
│   │   ├── cache
│   │   ├── config
│   │   ├── controllers
│   │   ├── core
│   │   ├── helpers
│   │   ├── hooks
│   │   ├── index.html
│   │   ├── language
│   │   ├── libraries
│   │   ├── logs
│   │   ├── models
│   │   ├── third_party
│   │   └── views
│   └── site
│       ├── cache
│       ├── config
│       ├── controllers
│       ├── core
│       ├── helpers
│       ├── hooks
│       ├── index.html
│       ├── language
│       ├── libraries
│       ├── logs
│       ├── models
│       ├── third_party
│       └── views
├── index.php
└── system

In the above structure there is an index.php file in the document root and another in the admin folder. The former will point to the site application, the latter to the admin application, by editing the $application_folder value for the former to:

$application_folder = 'application/site';

And the values of the $application_folder and $system_path variables, for the latter, to:

$system_path = '../system';
$application_folder = '../application/admin';

Then you need to instruct the web server with few rewrite rules:

  • match the /admin/ path with the /admin/index.php
  • and all other requests with /index.php

The first .htaccess file, in the document root, will have this rule:

<IfModule mod_rewrite.c>
    RewriteEngine On

    # start from the document root
    RewriteBase /

    # verify if request is for static files or directories
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . - [L]

    # point to the "site" application
    RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>

The second .htaccess, in the admin folder, is the same of the previous, except for the value of the RewriteBase:

<IfModule mod_rewrite.c>
    RewriteEngine On

    # start from the "/admin/" folder
    RewriteBase /admin/

    # verify if request is for static files or directories
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . - [L]

    # point to the "admin" application
    RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>

This allows to write URLs like this:

http://localhost/welcome
http://localhost/admin/welcome

An alternative approach is described here:

Instead of rewriting the URLs you create, in the document root, two copies of the index.php file: site.php and admin.php, modify the $application_folder value for both to point the matching applications and finally call the resources by pointing them to the scripts:

http://localhost/site.php/welcome
http://localhost/admin.php/welcome

Another alternative is the HMVC approach, but I haven't tested with CI 3.*, for more information see:

Thanks @cereal.

I did as what you recommend by configuring the .htaccess file.

Yet I still have this error message appearing:

Warning: include(C:\Program Files (x86)\EasyPHP-DevServer-14.1VC9\data\localweb\masterlinkci2\application\site\views\errors\html\error_php.php): failed to open stream: No such file or directory in C:\Program Files (x86)\EasyPHP-DevServer-14.1VC9\data\localweb\masterlinkci2\system\core\Exceptions.php on line 268

Warning: include(): Failed opening 'C:\Program Files (x86)\EasyPHP-DevServer-14.1VC9\data\localweb\masterlinkci2\application\site\views\errors\html\error_php.php' for inclusion (include_path='.;C:\php\pear') in C:\Program Files (x86)\EasyPHP-DevServer-14.1VC9\data\localweb\masterlinkci2\system\core\Exceptions.php on line 268

Warning: include(C:\Program Files (x86)\EasyPHP-DevServer-14.1VC9\data\localweb\masterlinkci2\application\site\views\errors\html\error_php.php): failed to open stream: No such file or directory in C:\Program Files (x86)\EasyPHP-DevServer-14.1VC9\data\localweb\masterlinkci2\system\core\Exceptions.php on line 268

Warning: include(): Failed opening 'C:\Program Files (x86)\EasyPHP-DevServer-14.1VC9\data\localweb\masterlinkci2\application\site\views\errors\html\error_php.php' for inclusion (include_path='.;C:\php\pear') in C:\Program Files (x86)\EasyPHP-DevServer-14.1VC9\data\localweb\masterlinkci2\system\core\Exceptions.php on line 268

Warning: include(C:\Program Files (x86)\EasyPHP-DevServer-14.1VC9\data\localweb\masterlinkci2\application\site\views\errors\html\error_php.php): failed to open stream: No such file or directory in C:\Program Files (x86)\EasyPHP-DevServer-14.1VC9\data\localweb\masterlinkci2\system\core\Exceptions.php on line 268

Warning: include(): Failed opening 'C:\Program Files (x86)\EasyPHP-DevServer-14.1VC9\data\localweb\masterlinkci2\application\site\views\errors\html\error_php.php' for inclusion (include_path='.;C:\php\pear') in C:\Program Files (x86)\EasyPHP-DevServer-14.1VC9\data\localweb\masterlinkci2\system\core\Exceptions.php on line 268

C:\Program Files (x86)\EasyPHP-DevServer-14.1VC9\data\localweb\masterlinkci2\application\site\views\errors\html\error_php.php

Can you reach the error_php.php file by following the path described in the warning?

I can only find this file: C:\Program Files (x86)\EasyPHP-DevServer-14.1VC9\data\localweb\masterlinkci2\application\site\views\

not this part: ..\errors\html\error_php.php

Then add all the tree from the official download.

like how?

like how?

Download this file:

or download the version you are using. Extract, browse up to application/views/ and copy the errors directory, with all the contents, into your application/site/views/ directory.

Parse error: syntax error, unexpected '<' in C:\Program Files (x86)\EasyPHP-DevServer-14.1VC9\data\localweb\masterlinkci2\application\site\views\index.php on line 214
A PHP Error was encountered

Severity: Parsing Error

Message: syntax error, unexpected '<'

Filename: views/index.php

Line Number: 214

Backtrace:

site/views/index.php

<?php foreach($pic as $pic_item) { 
                                <img src="<?php echo base_url(assets1/images/slider/)".$pic_item->pic_item;.">" ?>                  
                        } 
                        endforeach;
                        ?>

Davy, I think you are able to solve this error, look it carefully.

You need to keep track of when you're in HTML and when you're in PHP. I always only use only PHP short tags within my templates. Makes my life soooo much easier.

This is html blah blah
<?php foreach ($foo AS $bar): ?>
    Value of the element is <?= $bar ?>
<?php endforeach; ?>
More HTML blah blah

ok, I fix that part.

One other thing, I wonder if this css even works. Since my page seems like without style.css.

site/views/header.php

      <link rel='stylesheet' id='rs-plugin-inline-css'  href='<?php echo base_url(); ?>assets1/css/slider/settings-inline.css' type='text/css' media='all' />
      <!--style css-->
      <link rel='stylesheet' id='yith-wcwl-main-css'  href='<?php echo base_url(); ?>assets1/css/style.css' type='text/css' media='all' />

site/config/config.php

$config['base_url'] = 'http://localhost/masterlinkci2/';

I test this in the url: http://localhost/masterlinkci2/assets1/css/style.css

I wonder why: Object not found!

I have that file in: masterlinkci2/assets1/css/style.css

This does not works out either:

 <!--style css-->
      <link rel='stylesheet' id='yith-wcwl-main-css'  href="<?php echo base_url('assets1/css/style.css'); ?>" type='text/css' media='all' />

Do I need to configure the router also?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.