CodeIgniter Forums
Teach me how to program - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: Teach me how to program (/showthread.php?tid=64373)

Pages: 1 2 3 4


Teach me how to program - davy_yg - 02-14-2016

A PHP Error was encountered
Severity: Notice
Message: Undefined property: Home::$page_model
Filename: controllers/home.php
Line Number: 14
Backtrace:
File: C:\xampp\htdocs\ci3\application\controllers\home.php
Line: 14
Function: _error_handler
File: C:\xampp\htdocs\ci3\index.php
Line: 292
Function: require_once


An uncaught Exception was encountered
Type: Error
Message: Call to a member function find_ID() on null
Filename: C:\xampp\htdocs\ci3\application\controllers\home.php
Line Number: 14
Backtrace:
File: C:\xampp\htdocs\ci3\index.php
Line: 292
Function: require_once


How to fix those error?

home.php

PHP Code:
$this->data['page_detail'] = $this->page_model->find_ID(); 

ci3/index.php

PHP Code:
require_once BASEPATH.'core/CodeIgniter.php'

Why the error appears?

models/page_model.php

PHP Code:
public function find_ID($post_ID false)
    {
        $this->db->select('post.*, template.*');
        $this->db->from('post');
        $this->db->join('template''template.template_ID = post.post_template_ID''left');
        if ($post_ID)
            $this->db->where(array('post.post_type' => 'page''post.post_ID' => $post_ID'post.post_status' => 1));
        else
        
{
            $this->db->where(array('post.post_type' => 'page''post.post_status' => 1));
            $this->db->order_by('post.post_position');
        }
        $this->db->limit(1);
        $q $this->db->get();
        
        if
($q->num_rows() > 0)
            return $q->row();
        
        return false
;
    



RE: CI3 - albertleao - 02-14-2016

Are you loading the page model?

$this->load->model('page_model')


RE: CI3 - davy_yg - 02-14-2016

Okay, here I have a new error that I am dealing with:


A PHP Error was encountered

Severity: Notice

Message: Undefined property: Home::$db

Filename: core/Model.php

Line Number: 77

Backtrace:

File: C:\xampp\htdocs\ci3\application\models\page_model.php
Line: 80
Function: __get

File: C:\xampp\htdocs\ci3\application\controllers\home.php
Line: 15
Function: find_ID

File: C:\xampp\htdocs\ci3\index.php
Line: 292
Function: require_once

-----------------------------------------

An uncaught Exception was encountered

Type: Error

Message: Call to a member function select() on null

Filename: C:\xampp\htdocs\ci3\application\models\page_model.php

Line Number: 80

Backtrace:

File: C:\xampp\htdocs\ci3\application\controllers\home.php
Line: 15
Function: find_ID

File: C:\xampp\htdocs\ci3\index.php
Line: 292
Function: require_once

--------------------------------


page_model.php


PHP Code:
public function find_ID($post_ID false)
    {
        $this->db->select('post.*, template.*');
        $this->db->from('post');
        $this->db->join('template''template.template_ID = post.post_template_ID''left');
        if ($post_ID)
            $this->db->where(array('post.post_type' => 'page''post.post_ID' => $post_ID'post.post_status' => 1));
        else
        
{
            $this->db->where(array('post.post_type' => 'page''post.post_status' => 1));
            $this->db->order_by('post.post_position');
        }
        $this->db->limit(1);
        $q $this->db->get();
        
        if
($q->num_rows() > 0)
            return $q->row();
        
        return false
;
    

line 80:  $this->db->select('post.*, template.*');

controllers/home.php


PHP Code:
public function index()
    {
        $this->load->model('page_model');
        $this->data['page_detail'] = $this->page_model->find_ID();
        
        $this
->page_model->counter($this->data['page_detail']->post_ID);
        
        $this
->data['post_list'] = $this->model->post($this->data['page_detail']->post_ID);
        $this->data['gallery_list'] = $this->model->post($this->data['page_detail']->post_IDtrue);
        
        $this
->load->view($this->data['page_detail']->template_name$this->data);
    


line 15:      $this->data['page_detail'] = $this->page_model->find_ID();

index.php

PHP Code:
require_once BASEPATH.'core/CodeIgniter.php'

Can you help me fix the error?


RE: CI3 - pdthinh - 02-14-2016

You should connect to the database http://www.codeigniter.com/user_guide/database/connecting.html#connecting-to-your-database


RE: CI3 - Narf - 02-14-2016

... and also learn that we're not your personal debugging tool.


RE: CI3 - davy_yg - 02-14-2016

How do I know if my CI already connected to the database or not?

database.php

PHP Code:
$db['default'] = array(
 
   'dsn'    => '',
 
   'hostname' => 'localhost',
 
   'username' => 'gsaconst_admin',
 
   'password' => 'spesialiskonstruksi1',
 
   'database' => 'gsaconst_database',
 
   'dbdriver' => 'mysqli_connect',
 
   'dbprefix' => 'pix_',
 
   'pconnect' => TRUE,
 
   'db_debug' => (ENVIRONMENT !== 'production'),
 
   'cache_on' => FALSE,
 
   'cachedir' => '',
 
   'char_set' => 'utf8',
 
   'dbcollat' => 'utf8_general_ci',
 
   'swap_pre' => '',
 
   'encrypt' => FALSE,
 
   'compress' => FALSE,
 
   'stricton' => FALSE,
 
   'failover' => array(),
 
   'save_queries' => TRUE
); 


oh well ... sorry.. I am considering myself a beginner in CI.  I need some help from experts.  Thanks in advance.


RE: CI3 - davy_yg - 02-14-2016

A PHP Error was encountered

Severity: Notice

Message: Undefined property: Home::$db

Filename: core/Model.php

Line Number: 77

-------------------------

core/Model.php

PHP Code:
public function __get($key)
    {
        
// Debugging note:
        //    If you're here because you're getting an error message
        //    saying 'Undefined Property: system/core/Model.php', it's
        //    most likely a typo in your model code.
        
return get_instance()->$key;
    } 


line 77:  return get_instance()->$key;


RE: CI3 - albertleao - 02-14-2016

I think you need make sure you are loading the DB library.

I would recommend you reading through all the CI documentation first. It's extremely well written, easy to follow, and will probably prevent the next few posts you were going to make.

If you follow the guide, you will be able to connect to the db, execute a sql query and parse the results.


RE: CI3 - cartalot - 02-14-2016

i have so much sympathy for people who try and build first without doing the tutorial because thats how i was.
but seriously -- do the tutorial. and don't just paste the code and get it working but really step through and learn each step.
you will save yourself so much time.


RE: CI3 - freddy - 02-14-2016

well all you need copy paste your error in google, you need to autoload database just goes to your config/autoload.php then add database, look at me here

Code:
$autoload['libraries'] = array('database'); //you need to autoload it !