Welcome Guest, Not a member yet? Register   Sign In
Creating own library
#1

[eluser]fuksito[/eluser]
Tell me where am I going wrong:

I`ve created file
<b><i>application/libraries/Comment.php</i></b>
with content:
Code:
&lt;?php  if (!defined('BASEPATH')) exit('No direct script access allowed');

class Comment {

  var $config;
  var $CI;


  function Comment()
  {
      $this->CI =& get_instance();
      $this->CI->load->model('Comment_model');
  }
  
  public function comments()
  {
      return 'ok';
  }
  
}

In my controller I load library and call it`s method
Code:
function index($id)
{
    $this->load->library('Comment');        
    $comments = $this->Comment->comments();
    parse_page('artist/page_tpl', array('comments'=>$comments));            
}

But I get an error:
Call to a member function comments() on a non-object
#2

[eluser]BeingDefined[/eluser]
A wild guess here but try removing the "public" keyword from the comments function. Also try changing "function index($id)" to "function index()"
#3

[eluser]fensen[/eluser]
Please try changing:
Code:
$this->Comment->comments();
to lowercase:
Code:
$this->comment->comments();

According to CI documentation:

Quote:Once loaded you can access your class using the lower case version

http://ellislab.com/codeigniter/user-gui...aries.html

Hope this helps.
#4

[eluser]fuksito[/eluser]
fabian_o using lowercase class name worked, thanks




Theme © iAndrew 2016 - Forum software by © MyBB