Welcome Guest, Not a member yet? Register   Sign In
HELP please :)
#1

[eluser]dadamssg[/eluser]
I'm trying to learn by going through the tutorial found on the site. Im on the second tutorial but i don't think im connecting to my database.

$data['query'] = $this->db->get('test');

this line throws an error. i set up a table with multiple rows and called it 'test'

this is the error im getting

Fatal error: Call to a member function get() on a non-object in /controllers/blog.php on line 16

*the autoload script in the tutorial wasn't the same one i got when i downloaded it. It talked about using the autoload to load the database connection. Well i didn't find that 'core' variable in the autoload file. I added it to mine though.

below is my whole blog.php file
Code:
<?php

class Blog extends Controller {

    function Blog()
    {
        parent::Controller();
        
        
    }

    function index()
    {
        $data['title'] = "My Blog Title";
        $data['heading'] = "My Blog Heading";
        $data['query'] = $this->db->get('test');
        
        $this->load->view('blog_view', $data);
    }
}

?>
#2

[eluser]jmbatty[/eluser]
is your config/database.php set correctly for your database ?
is your autoload.php saying something like
Code:
$autoload['libraries'] = array('database');

if not you could in your function index() add
Code:
$this->load->library('database');
#3

[eluser]dadamssg[/eluser]
thank you! i just changed it to say this like you said

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

and it worked! thank you! i couldn't figure out, this is all new and SUPER confusing for me.

PS: this doesn't have anything to do with autoload or anything but i noticed that you insert info into the database from forms from the a controller in the tutorial. Well where does the form validation go?

THANKS again!
#4

[eluser]jmbatty[/eluser]
i just started codeigniter myself, but in one week i made more progress than I ever made in years of lesser programming quality... if you hang on to the concepts and fully understand the MVC, you will do great things. the confusion goes away after a while.

to answer your question, post a link to the tutorial you're referring to, i don't know which one it is.
my first guess would be that if you use the form helper, they are validating some of the data, but then in your controller, you could use other methods if you want to validate before inserting in your db
(form_prep() just for example.)

in the database class the active record class is also doing some kind of validation, to some extent.

(all this being server side, of course)

the user guide is VERY WELL done to walk you through those concepts.
#5

[eluser]dadamssg[/eluser]
thanks again for the reply. But ive run into another problem on this tutorial

http://codeigniter.com/tutorials/watch/blog/

i have a website already and im trying to learn this on my hosting account. im trying to add the commenting section controller and have the blog links point to it. Well ive done exactly what the tutorial has done but when i try to go to my comment page it goes to my index.php page and pulls up the front page of my real website. Do i have to be developing this on a blank hosting account, one where i don't have an index.php page in my root?
#6

[eluser]jmbatty[/eluser]
and your codeigniter is in a different folder ?
make sure your config.php is set correctly, specifically

$config['base_url'] = base url for codeigniter, not base url for your site.
#7

[eluser]dadamssg[/eluser]
OOOH gotcha... its working now, THANK YOU!




Theme © iAndrew 2016 - Forum software by © MyBB