Frank Vèssia Posted January 18, 2016 Share Posted January 18, 2016 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 More sharing options...
rick Posted January 18, 2016 Share Posted January 18, 2016 Just off the top, I don't believe the comment module is autoloaded, so you'd have to reference it prior to instantiation. 1 Link to comment Share on other sites More sharing options...
Frank Vèssia Posted January 18, 2016 Author Share Posted January 18, 2016 mmm you are right... but how? Usually I use other module's methods but comment module doesn't have a "new()" like method so I'm not quite sure how to make this Link to comment Share on other sites More sharing options...
rick Posted January 18, 2016 Share Posted January 18, 2016 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 More sharing options...
DaveP Posted January 18, 2016 Share Posted January 18, 2016 (edited) I think $comments = wire(modules)->get("Comments"); should work. Probably. Edited January 18, 2016 by DaveP 1 Link to comment Share on other sites More sharing options...
Frank Vèssia Posted January 18, 2016 Author Share Posted January 18, 2016 it doesn't work, i tried wire('modules')->get('Comments') and wire('modules')->get('FieldtypeComments')I also tried $c = FieldtypeComments::Comment() Link to comment Share on other sites More sharing options...
kongondo Posted January 18, 2016 Share Posted January 18, 2016 The Comment Class is not a module. It is a PHP file. You would have to require/include it first in your module, e.g. init() or earlier before you can call on it 2 Link to comment Share on other sites More sharing options...
Frank Vèssia Posted January 18, 2016 Author Share Posted January 18, 2016 mmm, i tried to include those files (at least Comment.php) but still i got "Class 'Comment' not found"... Link to comment Share on other sites More sharing options...
kongondo Posted January 18, 2016 Share Posted January 18, 2016 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'); } 1 Link to comment Share on other sites More sharing options...
Frank Vèssia Posted January 18, 2016 Author Share Posted January 18, 2016 thanks, anyway the problem was related to the module itself, some init issue, I uninstalled the module and reinstalled and now it works Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now