简体   繁体   中英

How to add comments to each forum post in yii, using bbii forum module and comments-module

I am using Yii bbii forum module and it works fine. But now I want to add comments-module so every forum post could be seperately commented.

At the begining it might look: 在此处输入图片说明

I followed instruction what is here , but I can't make it work :(

在此处输入图片说明在此处输入图片说明

And why I even need to include this file, if I want to add just comment?

在此处输入图片说明

When I added the same widget to user page (just for testing) - I got "This item cann't be commentable" and it's fine because probably I don't have correct configuration in main.php. 在此处输入图片说明

Difference between widget in user model view and forum view is data passed in it. Here:

   public function actionPostComment()
        {
            if(isset($_POST['Comment']) && Yii::app()->request->isAjaxRequest)
            {
                $comment = new Comment();
                $comment->attributes = $_POST['Comment'];
                var_dump($comment);

var_dump returned this when tried to submit comment in forum, and here in user view page.

And probably it is not even possible to combine these to modules? I'm really new in Yii.

Updated:

Basically what I have done is:

  • exstracted comment module (under protected->modules)
  • in main.php (under protected->config) added all cofiguration in modules array:
  •   'comments'=>array( //you may override default config for all connecting models 'defaultModelConfig' => array( //only registered users can post comments 'registeredOnly' => false, 'useCaptcha' => false, ....... 
  • and in view file _post.php added following:

      <?php $this->widget('comments.widgets.ECommentsListWidget', array( 'model' => $data, )); 
  • and var_dump($data) gives this (when this is called in controller where post is reseaved).

An error message was given here:

include(BbiiPost.php): failed to open stream: No such file or directory

You said that the Bbii was working with Yii and it broke when you tried to add comments. The links to your var_dump files are broken, but I did try to read them ;)

It looks like the comments module is interfering with the POST path so that when the form submission comes in it is in a different path from the root which is confusing the YiiBase's autoloader.

You could try explicitly adding the path to BbiiPost.php to the autoloader's search path, or finding where the include("BbiiPost.php") line is and changing it to an absolute path.

Another possibility is that the forum page you are on has links to add comments but the page routing has not been taken from the route. So it might be that the POST link to the comments is actually at /forum/123/comment/add instead of just /comment/add. So when the form is submitted it is trying to the comments/add controller/action but finding that it is in /forum/view and getting confused about the paths to the include files.

I have generally found that the instructions on the Yii (v1) [v2 docs are much better] site for these modules is flaky at best. Quite often the source download link on the page points to an old buggy version of the code as the project has usually moved somewhere else. You generally need to have a pretty good PHP/Yii knowledge to debug these user-submitted modules and get them working.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM