Welcome Guest, Not a member yet? Register   Sign In
can't even get thru tutorial without errors
#21

[eluser]Cristian Gilè[/eluser]
Glad to know you solve it.

Cristian Gilè
#22

[eluser]terionm[/eluser]
thanks for all your help and input! I will undoubtedly be a regular in these forums until I get a grasp on this...so thank you thank you thank you!!
I deserve a beer!! it's been a frustrating day ..lol I hate not knowing how to do things.
#23

[eluser]swgj19[/eluser]
I am working on the same old video tutorials, please help me with my errors. There are two errors. Please use specific examples as I am new to PHP and frameworks. I will not give up though.


A PHP Error was encountered

Severity: Notice

Message: Undefined property: Site::$db

Filename: core/Model.php

Line Number: 50

Fatal error: Call to a member function get() on a non-object in C:\xampp\htdocs
\ci\application\models\site_model.php on line 6



Now, here is my model, view, and controller pages.


Model(site_model.php):

<?php

class Site_model extends CI_Model {

function getAll() { //can name method whatever
$q = $this->db->get('test'); //grab table name:test from database name: ci_series

if($q->num_rows() > 0) { //If # of rows return are > than 0, then do whats next.
foreach ($q->result() as $row)
{
$data[] = $row; //by setting $data as an array, we have a new instance in the data array.
}
return $data;
}
}

}

?>


View(home.php):

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;Untitled Document&lt;/title&gt;
&lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&gt;

&lt;/head&gt;

&lt;body&gt;
<div id="container">
<p>My view has been loaded</p>

&lt;?php foreach($records as $row) : ?&gt;
<h1>&lt;?php echo $row->username; ?&gt;</h1>
&lt;?php endforeach; ?&gt;

</div>

&lt;/body&gt;
&lt;/html&gt;


Controller(site.php):

&lt;?php

class Site extends CI_Controller {

function index() {

$this->load->model('site_model'); //This is where model is loaded, but nothing done with the model yet.
$data['records'] = $this->site_model->getAll();
$this->load->view('home', $data);

}
}
?&gt;
#24

[eluser]InsiteFX[/eluser]
Did you read the above?

InsiteFX
#25

[eluser]swgj19[/eluser]
I am almost sure everything is configured right. However, I am missing: parent::Controller(); or constructor. I don't even know what those are. Please give me some guidance.
#26

[eluser]InsiteFX[/eluser]
Controller:
Code:
class Site extends CI_Controller {

    function __construct()
    {
        parent::__construct();
    }

    function index()
    {
        $this->load->model(‘site_model’); //This is where model is loaded, but nothing done with the model yet.
        $data[‘records’] = $this->site_model->getAll();
        $this->load->view(‘home’, $data);

    }
}

InsiteFX
#27

[eluser]swgj19[/eluser]
I changed my controller script to yours above, and now I get these errors:


A PHP Error was encountered

Severity: Notice

Message: Use of undefined constant ‘site_model’ - assumed '‘site_model’'

Filename: controllers/site.php

Line Number: 12

A PHP Error was encountered

Severity: Warning

Message: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\ci\system\core\Exceptions.php:170)

Filename: core/Common.php

Line Number: 409

An Error Was Encountered
Unable to locate the model you have specified: ‘site_model’
#28

[eluser]swgj19[/eluser]
I then added 'database' in my autoload.php in libraries

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

and it changed all those errors to this error:


A Database Error Occurred
Unable to connect to your database server using the provided settings.

Filename: C:\xampp\htdocs\ci\system\database\DB_driver.php

Line Number: 124
#29

[eluser]InsiteFX[/eluser]
Did you set your application/config/database.php settings ?

InsiteFX
#30

[eluser]swgj19[/eluser]
Yes to all:
1. I configured the autoload.php:
Code:
$autoload['libraries'] = array('database');
and
Code:
$autoload['helper'] = array('url');
2. I configured the config.php:
Code:
$config['base_url'] = 'http://localhost/ci/index.php';
and
Code:
$config['index_page'] = 'index.php';
3. I configured routes.php:
Code:
$route['default_controller'] = "site";
Code:
$route['404_override'] = '';


database.php
Code:
$active_group = 'default';
$active_record = TRUE;

$db['default']['hostname'] = 'localhost';
$db['default']['username'] = 'root';
$db['default']['password'] = 'root';
$db['default']['database'] = 'ci_series';
$db['default']['dbdriver'] = 'mysql';
$db['default']['dbprefix'] = '';
$db['default']['pconnect'] = TRUE;
$db['default']['db_debug'] = TRUE;
$db['default']['cache_on'] = FALSE;
$db['default']['cachedir'] = '';
$db['default']['char_set'] = 'utf8';
$db['default']['dbcollat'] = 'utf8_general_ci';
$db['default']['swap_pre'] = '';
$db['default']['autoinit'] = TRUE;
$db['default']['stricton'] = FALSE;

Controller(site.php):

Code:
&lt;?php

class Site extends CI_Controller {

    function __construct()
    {
        parent::__construct();
    }

    function index()
    {
        $this->load->model('site_model'); //This is where model is loaded, but nothing done with the model yet.
        $data['records'] = $this->site_model->getAll();
        $this->load->view('home', $data);

    }
}  
?&gt;

Model(site_model.php)

Code:
&lt;?php

class Site_model extends CI_Model {
    
    function getAll() {                        //can name method whatever
        $q = $this->db->get('test');            //grab table name:test from database name: ci_series
        
        if($q->num_rows() > 0) {                //If # of rows return are > than 0, then do whats next.
        foreach ($q->result() as $row)
        {
            $data[] = $row;                    //by setting $data as an array, we have a new instance in the data array.
        }
        return $data;
        }
    }
    
}

?&gt;

Views(home.php)

Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
&lt;html&gt;
    &lt;head&gt;
        &lt;title&gt;Untitled Document&lt;/title&gt;
        &lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&gt;
    
    &lt;/head&gt;

    &lt;body&gt;
        <div id="container">
            <p>My view has been loaded</p>
            
            &lt;?php foreach($records as $row) : ?&gt;
                <h1>&lt;?php echo $row->username; ?&gt;</h1>
            &lt;?php endforeach; ?&gt;
            
        </div>
    
    &lt;/body&gt;
&lt;/html&gt;

I have done everything I know to do and researched google in and out and the codeignitor forums.




Theme © iAndrew 2016 - Forum software by © MyBB