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

[eluser]neverstop[/eluser]
Now i'm not understanding anything =/.

Doesn't CI create its own constructor when i instanciate a class without one? As java does? O read the documentation of how create my own library and there's no constructor on the examples.

Well i still fighting here to understand the CI and changed my code and it worked! Take a look:
Code:
<?php
class Main extends Controller
{
    function __construct()
    {
        parent::Controller();
    }
    
    function index()
    {        
        $this->load->library("Artigos");
        $val["title"] = "Altus :: Evoluçao em Automaçao";
        $val["articles"] = Artigos::showArticles();
        $this->load->view("mainview", $val);
    }
}
?>
and
Code:
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);
    }
Now my BIG question, my class Artigos doesn't need to extend another class right? I dont need to create a constructor to my class but i could if necessary right?
In my code above i called the funcion showArticles() as a static function ok? I know it worked but i'm confuse...because the documentation explain in a different way =/


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