Closed dacom-dark-sun closed 8 years ago
Hi, how we can reproduce your issue? Can you add your code here?
Firstly controller is index, just upload main view.
public function actionIndex()
{
$query = new Art;
$raw = $query->find()->asArray()->select('country, city, category, sub_category')->all();
$data_full = Art::create_array_categories($raw);
$searchModel = new ArtSearch();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
$dataProvider->sort = [
'defaultOrder' => ['date' => SORT_DESC]
];
return $this->render('index', ['dataProvider'=>$dataProvider,
'data' => $data_full,
]);
}
Main view is
<?php
webtoucher\cookie\AssetBundle::register($this);
use yii\helpers\Html;
use yii2mod\comments\CommentAsset;
CommentAsset::register($this);
?>
<?php if (Yii::$app->session->hasFlash('success')): ?>
<div class="alert alert-success alert-dismissable">
<button aria-hidden="true" data-dismiss="alert" class="close" type="button">×</button>
<h4><i class="icon fa fa-check"></i>Saved!</h4>
<?= Yii::$app->session->getFlash('success') ?>
</div>
<?php endif; ?>
<?= yii\jui\menu::widget([]) ?>
<div class="site-index">
<div class="body-content">
<div class="row">
<div class="col-lg-11">
<div id="article-index">
<?php echo \yii\widgets\ListView::widget([
'dataProvider'=>$dataProvider,
'pager' => ['class' => kop\y2sp\ScrollPager::className(), 'item' => '.article-item'],
'itemView'=>'_item',
'summary'=>'',
])?>
</div>
</div>
<div class="col-lg-1">
<div class = "category_panel">
<div class ="addbutton">
<?= Html::a('Пополнить базу', ['/site/add'], ['class'=>'btn btn-success']) ?>
</div
<?= $this->render('_categories',['data'=>$data]) ?>
</div>
</div>
</div>
</div>
</div>
<script>
function function_a(data){
y_pos = $('#article-index').scrollTop();
$.ajax({
method: "POST",
data: {data: data,
y_pos:y_pos,
},
url: '<?php echo Yii::$app->request->baseUrl . '/ajax/show_by_category' ?>',
success: function(data2) {
$('#article-index').html(data2);
}
});
}
function render_single_art(id){
$.ajax({
method: "POST",
data: {id : id
},
url: '<?php echo Yii::$app->request->baseUrl . '/ajax/show_one_art' ?>',
success: function(render_answer) {
$('#article-index').html(render_answer);
}
});
}
</script>
By click to any caption with article, i do partial render new view and replace #article-index class in main view. It is a controller: ajax/show_one_art
public function actionShow_one_art(){
$id = Yii::$app->request->post('id');
$model = Art::find()->where(['id'=> $id])->one();
return $this->renderPartial('_oneart', ['model'=>$model,
]);
And this is view _oneart:
<?php
use yii2mod\comments\CommentAsset;
CommentAsset::register($this);
/**
* @var $this yii\web\View
* @var $model common\models\Article
*/
use yii\helpers\Html;
?>
<button type="button" class="btn btn-default previous" onclick = "back()">Назад</button>
<hr/>
<div class="article-full row">
<div class="col-xs-12">
<h2 class="article-title">
<?php echo Html::label($model->title, "" ,['class' => 'onepage_link']) ?>
</h2>
<div class="article-content">
<div class="article-text">
<?php echo $model->body?>
</div>
</div>
<div class="article-metainfo">
<span class="article-total_payot_value">
<?php echo $model->total_payot_value?>
RUB
</span>
<span>|</span>
<span class="article-date left_margin">
<?php echo Yii::$app->formatter->asDatetime($model->date) ?>
</span>
<span>|</span>
<span class="article-category">
<?php echo Html::a(
$model->category,
['index', 'ArtSearch[category_id]' => $model->category]
)?>
</span>
<span>|</span>
<span class="Icon voters">
<svg id="Capa_1" version="1.1" viewBox="0 0 100 88" xml:space="preserve" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"><g><path d="M100,88c0,0-0.197-18.934-1.354-20.896c-1.721-2.923-5.729-4.932-13.17-8.041c-7.416-3.101-9.787-5.716-9.787-11.316 c0-3.364,2.264-2.264,3.26-8.419c0.412-2.555,2.412-0.043,2.795-5.872c0-2.324-1.092-2.903-1.092-2.903s0.555-3.437,0.771-6.084 c0.27-3.298-1.662-11.815-11.955-11.815c-10.295,0-12.225,8.518-11.955,11.815c0.217,2.647,0.77,6.084,0.77,6.084 s-1.09,0.579-1.09,2.903c0.383,5.829,2.381,3.317,2.795,5.872c0.994,6.155,3.26,5.056,3.26,8.419c0,3.807-1.102,6.235-4.137,8.375 c16.203,8.111,18.375,9.764,18.375,17.015V88H100z M51.117,61.877c-9.891-4.134-13.051-7.621-13.051-15.086 c0-4.483,3.02-3.019,4.346-11.228c0.549-3.404,3.217-0.056,3.727-7.829c0-3.098-1.455-3.868-1.455-3.868s0.74-4.583,1.029-8.112 C46.072,11.357,43.498,0,29.771,0C16.047,0,13.471,11.357,13.832,15.754c0.289,3.529,1.027,8.112,1.027,8.112 s-1.455,0.77-1.455,3.868c0.512,7.773,3.178,4.425,3.729,7.829c1.326,8.208,4.346,6.744,4.346,11.228 c0,7.465-3.162,10.952-13.051,15.086C5.414,63.137,0,65.088,0,69.783V88h69.469c0,0,0-10.776,0-13.659 C69.469,70.059,61.037,66.025,51.117,61.877z"></path></g></svg>
</span>
<span class="article-votes">
<?php echo $model->votes?>
</span>
<span>|</span>
<span class="Icon chatbox">
<svg version="1.1" style="margin-top: 1px" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 512 512" xml:space="preserve"><path d="M124.3,400H277c14.4,0,14.4,0.1,21.3,5.2S384,464,384,464v-64h3.7c42.2,0,76.3-31.8,76.3-71.4V119.7 c0-39.6-34.2-71.7-76.3-71.7H124.3C82.2,48,48,80.1,48,119.7v208.9C48,368.2,82.2,400,124.3,400z"></path></svg>
</span>
<span class="article-comments">
<?php echo $model->replies?>
</span>
<span>|</span>
<span class="article-vote-up">
<?php echo Html::a(
Html::img('\storage\web\source\up.png',[
'style'=> 'height: 25px'
]),
['index', 'votes' => $model->votes]
)?>
</div>
</div>
</div>
<div class ="comments">
<?php echo \yii2mod\comments\widgets\Comment::widget(['model' => $model,
])?>
</div>
<script>
function back(){
$.ajax({
method: "POST",
data: {},
url: '<?php echo Yii::$app->request->baseUrl . '/ajax/back' ?>',
success: function(view) {
if (view != 'null')
$('#article-index').html(view);
else alert('undefined');
}
});
}
</script>
All works clearly, if i install comments module to index, but after replace class #article-index, i can see module, can comment, but scripts reply and in-window replace not works.
Can you try change the renderPartial
to renderAjax
function, and test again your code?
I think this issue very similar to #24
Yes, problems very same, but change to renderAjax not helps. How i can re-init module in ajax step? I think problem here..
Actually, styles not enabled too.. http://joxi.ru/ZrJpxvzf1qpGy2
You can try to replace your ajax link to simple link without js but inside pjax container. Maybe via pjax request with renderAjax
you fix this issue.
Try the following code for remote loading the comments widget.
1) Define action in your controller
public function actionComments() {
$model = CmsModel::findOne(1); // just for example
return $this->renderAjax('comments', [
'model' => $model
]);
}
2) create view file comments.php
with the following content:
<?php echo \yii2mod\comments\widgets\Comment::widget([
'model' => $model,
'clientOptions' => [
'pjaxSettings' => [
'url' => \yii\helpers\Url::to(['comments', 'id' => $model->id]),
'timeout' => 10000,
'scrollTo' => false,
'enablePushState' => false
]
]
]); ?>
3) Create simple link anywhere on your site
<?php
Pjax::begin([ 'timeout'=> 10000, 'enablePushState' => false]);
echo Html::a('Loading comments', \yii\helpers\Url::to(['comments']));
Pjax::end();
?>
Yes, fixed! Thank you for help)
And few questions more about module:
how i can install permissions for users, what better way?
You can use our extension yii2mod/rbac Also you can install our yii2mod/base template for testing this(and other) our extensions.
in module implemented functional for in-line edit comments from users?
For implement this functionality you need to override our base functionality with your own. We don't have this functionality by default.
and last.. I see in screenshot here video full-size, not link. This is some additional plugin, or this is included in module, but not works now?
User can add iframe (from youtube) as comment. For example, create comment with the following content and save it.
<iframe width="560" height="315" src="https://www.youtube.com/embed/w-Mm7cG2gvI" frameborder="0" allowfullscreen></iframe>
Здравствуйте, господа разработчики! Проблема при использовании вашего чудесного модуля у меня возникает следующая:
Провел расследование, нашел проблему. Она заключается в том, что я обновляю класс вида по ajax, и вот в этом новом виде и есть комментарии, которые не работают. Если же я вывожу комментарии на Главную, т.е. сразу после загрузки site/index, все отрабатывает великолепно.
Как я могу поправить это, перерегистрируя виджет заново? В файле вида:
Не помогает..