В этой статье посмотрим как выводятся комментарии и форма для комментирования.
Сначала посмотрим что пишется в функции вывода в контроллере
$idThis = $R[‘idAll’];
$D[‘commentAddUrl’] = site_url(“$this->ccnm/ajaxCommentAdd/$idThis”);
$onPage = safeInt($this->Sets->read(‘commentsOnPageUsr’));
$resultArray = $this->data->aGetComments($idThis, $onPage, $start);
if (!is_array($resultArray)) $D[‘comments’] = ‘no comments’;
else
{
$D[‘commentsCount’] = $resultArray[‘numRows’];
$D[‘begin’] = $resultArray[‘begin’];
$D[‘comments’] = $resultArray[‘comments’];
$this->load->library(‘pagination’);
$config[‘cur_page’] = $start;
$config[‘base_url’] = site_url(“$this->ccnm/”.__FUNCTION__.”/$category/$date/$huu”);
$config[‘total_rows’] = $resultArray[‘numRows’];
$config[‘per_page’] = $onPage;
$config[‘full_tag_open’] = ‘‘;
$config[‘full_tag_close’] = ‘‘;
$config[‘first_link’] = ‘ ‘;
$config[‘last_link’] = ‘ ‘;
$config[‘next_link’] = ‘ ‘;
$config[‘prev_link’] = ‘ ‘;
$config[‘cur_tag_open’] = ‘‘;
$config[‘cur_tag_close’] = ‘‘;
$config[‘first_tag_open’] = ‘‘;
$config[‘last_tag_open’] = ‘‘;
$config[‘next_tag_open’] = ‘‘;
$config[‘prev_tag_open’] = ‘‘;
$config[‘num_tag_open’] = ‘‘;
$config[‘num_tag_close’] = ‘‘;
$this->pagination->initialize($config);
$D[‘paging’] = $this->pagination->create_links();
}
if ($D[‘comment’]) $this->load->view(‘site/body-mater-form’,$D);
sa
Последняя строчка показывает, что нужно выводить форму комментирования только тогда, когда комментирование разрешено. Эту функциональность можно внести в файл вывода самого материала.
if (!is_string($comments))
{
$counter = 0;
for ($i=1; $i<15; $i++) $a14[] = $i; //vd($a14);
shuffle($a14);
echo “Комментарии к материалу ($commentsCount)
“;
foreach ($comments as $row)
{
$pattDow = ‘l’;
$pattMonth = ‘M’;
$pattDay = ‘j’;
$pattYear = ‘Y’;
$phpdate = strtotime($row->date);
$day = date($pattDay, $phpdate);
$mon = getRusDate(date($pattMonth, $phpdate));
$year = date($pattYear, $phpdate);
$time = substr($row->time, 0, 5);
$tdate = “$day $mon $year в $time “;
$hash = md5(strtolower(trim($row->email)));
$counter++;
if ($counter >= 14)
{
$counter = 0;
shuffle($a14);
}
$boo = site_url(“_/avatars/$a14[$counter].jpg”);
$grava = ‘http://www.gravatar.com/avatar/’.$hash.’/?d=’.$boo;
$text = $row->text;
$begin++;
echo’
‘.$row->name.’ комментирует материал ‘.$tdate.’‘.$text.’
‘;
}
echo ‘