Welcome Guest, Not a member yet? Register   Sign In
Fatal error: Call to a member function on a non-object
#1

[eluser]neverstop[/eluser]
Hello i'm developing a site and choose CI to do it. I'm doing just fine and solved all problems i had except this one. I'll post the error:

Quote:A PHP Error was encountered
Severity: Notice
Message: Undefined property: Main::$Artigos
Filename: controllers/main.php
Line Number: 13

Fatal error: Call to a member function showArticles() on a non-object in C:\Wamp\www\system\application\controllers\main.php on line 13

My main.php is:
Code:
<?php
class Main extends Controller
{
    function Main()
    {
        parent::Controller();
    }
    
    function index()
    {        
        $this->load->library('Artigos');
        $val["title"] = "Altus :: Evoluçao em Automaçao";
        $val["articles"] = $this->Artigos->showArticles();
        $this->load->view('mainview', $val);
    }
}
?>
As you can see i created a new library and put it in the /libraries folder. Well it is working fine, at least CI load it with success ...and i'm sure about this because when i change its name i receive an error at the screen as expected.

My library file is:
Code:
<?php
if (!defined('BASEPATH'))
    exit('No direct script access allowed');
    
class Artigos
{
    function showArticles()
    {        
        $query = $this->db->query("SELECT * FROM artigos");
        $articles = "";
        foreach ($query->result() as $row)
        {
            $articles .= "<p><b>";
            $articles .= $row->date . "&nbsp;&middot;&nbsp;";
            $articles .= "<a href=\"#\">" . $row->name . "</a></b><br>";
            
            $content_complete = $row->content;
            $content_edited = html_entity_decode(substr($content_complete, 0, 120));
            $last_position = strrpos($content_edited, " ");
            
            $articles .= substr($content_edited, 0, $last_position) . "&nbsp;...</p>";
        }
        return($articles);
    }
    
    function _paginationArticles($num_rows)
    {
        $this->load->library("pagination");
        $config["full_tag_open"] = "<div id=\"article_pagination\">";
        $config["full_tag_close"] = "</div>";
        $config["total_rows"] = $num_rows;
        $config["first_link"] = "Inicial";
        $config['last_link'] = "Final";
        $config["per_page"] = 10;
        $config["num_links"] = 9;
        $this->pagination->initialize($config);
        return($this->pagination->create_links());
        
        //$pagination = $this->_paginationArticles($query->num_rows());
    }
}
?&gt;
I need to configure something on CI? I read the documentation to create my own libraries and everything seems to be correct. Help me please, i don't know what to do now =/


Messages In This Thread
Fatal error: Call to a member function on a non-object - by El Forum - 01-16-2008, 07:08 AM
Fatal error: Call to a member function on a non-object - by El Forum - 01-16-2008, 09:32 AM
Fatal error: Call to a member function on a non-object - by El Forum - 01-16-2008, 10:01 AM
Fatal error: Call to a member function on a non-object - by El Forum - 01-16-2008, 10:10 AM
Fatal error: Call to a member function on a non-object - by El Forum - 01-16-2008, 10:19 AM
Fatal error: Call to a member function on a non-object - by El Forum - 01-16-2008, 10:53 AM
Fatal error: Call to a member function on a non-object - by El Forum - 01-16-2008, 11:16 AM
Fatal error: Call to a member function on a non-object - by El Forum - 01-16-2008, 02:08 PM
Fatal error: Call to a member function on a non-object - by El Forum - 01-16-2008, 02:20 PM
Fatal error: Call to a member function on a non-object - by El Forum - 01-17-2008, 04:21 AM
Fatal error: Call to a member function on a non-object - by El Forum - 09-07-2012, 01:10 AM



Theme © iAndrew 2016 - Forum software by © MyBB