Jump to content

Create comment inside a module


Recommended Posts

I'm trying to create a comment inside a module function but I got error "Class 'Comment' not found"
 


public function postComment($pageid){
       $input      = wire('input');
       $user       = wire('user');
       $sanitizer  = wire('sanitizer');
       $pages      = wire('pages');
       if($input->post->rv_text && $user->isLoggedin() && $pageid != ''){
           $c     = new Comment();

          ...
        }
}

Link to comment
Share on other sites

Sorry. I was in a hurry when I first posted, and only glanced at the error message in your question. 

Try this to retrieve whatever the module name is (?) within quotes. I believe this also instantiates the class as well (but gladly defer to the knowledgeable members).

$this->modules->get('?');
Link to comment
Share on other sites

Then your path must be wrong. I tested and it works fine.

Normally, $this->config->paths->ModuleName should give you the path on disk to a module's folder but I've found out that for Fieldtypes that live inside their own folders (such as FieldtypeComments), it doesn't work. For those 'outside' such as FieldtypeDatetime, you will get the path on disk, e.g. F:/vhosts/k.dev/wire/modules/Fieldtype/

So, you need to try something like this (hard-coded, I know :-)):

public function init() {
   $path = $this->config->paths->modules . 'Fieldtype/FieldtypeComments';
   require_once($path . '/Comment.php');
}
  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...