Ссылки go на неправильный URL - PullRequest
0 голосов
/ 20 апреля 2020

У меня есть многоязычный веб-сайт, когда я меняю язык на kz и нажимаю на ссылку новостей, URL-адрес переходит на mysite.com/ru/news, как я могу сделать ссылки на kz go на mysite. com / kz / news?

ссылки формируются в model_press. php файл

<?php

class Model_press extends Model
{  var $content;

function get_pages($offset, $limit){ 
 $offset = intval($offset);
    $limit = intval($limit); 
if($this->raz_pages['year_raz'] == false){

}
    if ($this->raz_pages['year_raz']>0){
     $Qstr=" razid ='".$this->raz_pages['year_raz']."'";
 }
 else {
     $stmt1 = Model::$db->prepare("select * from menu where level =22  order by id ");


$stmt1->execute();
$history_raz=array();
$history_names=array();
 while($links= $stmt1->fetch(PDO::FETCH_ASSOC)){
$history_raz[$links['link']]="'".$links['id']."'";
$history_names[$links['link']]=$this->utils->translate_tex(array('name_ru'=>$links['name_ru'], 'name_kz'=>$links['name_kz'], 'name_en'=>$links['name_en']));
 }
 $Qstr=" razid in(".implode(",", $history_raz)." )";}

$this->years=$history_names;
$stmt2 = Model::$db->prepare("select * from articles where ".$Qstr." order by id desc LIMIT ".$limit." OFFSET ".$offset);
$stmt2->execute();

while($con= $stmt2->fetch(PDO::FETCH_ASSOC)){
$cont=$this->utils->translate_tex($con);
$cont['id'] = $con['id']; 
$cont['razname']=$history_names[$con['raz']]['name'];
     $this->content[$con['razid']][]=$cont;

 }



}

function get_pages1(){ 

     $stmt1 = Model::$db->prepare("select * from menu where level='22' order by  name_ru");

$stmt1->execute();

 while($con= $stmt1->fetch(PDO::FETCH_ASSOC)){



     $this->npages[]=$con['name_ru'];

     if($con['name_ru']==$this->raz_pages['year']){$this->raz_pages['year_raz']=$con['id'];}


         }
}
function getcurentnews($id){
         $stmt1 = Model::$db->prepare("select * from articles where id =".$id);

$stmt1->execute();

 while($con= $stmt1->fetch(PDO::FETCH_ASSOC)){
$cont=$this->utils->prerare_tex($con);


     $this->content[]=$cont;
 }
    //print_r($content);
}

function get_shownew(){ 
    if ($this->model->raz_pages);
}



function get_othernews($id){
     $stmt = Model::$db->prepare("select * from menu where level =22 order by id desc");

$stmt->execute();
$history_raz=array();
$history_names=array();
 while($links= $stmt->fetch(PDO::FETCH_ASSOC)){

$history_raz[$links['link']]="'".$links['id']."'";
$history_names[$links['link']]=$this->utils->translate_tex(array('name_ru'=>$links['name_ru'], 'name_kz'=>$links['name_kz'], 'name_en'=>$links['name_en']));

 }
    $stmt1 = Model::$db->prepare("select * from articles where razid in(".implode(",", $history_raz).") and id <> ".$id." order by id desc limit 2");   
$stmt1->execute();

 while($con= $stmt1->fetch(PDO::FETCH_ASSOC)){
$cont=$this->utils->translate_tex($con);
$cont['razname']=$history_names[$con['raz']]['name'];
     $this->contentother[$con['raz']][]=$cont;
 }  
 return $this->contentother;
 // print_r($this->content);
}


function get_pressCount(){  
     $stmt = Model::$db->prepare("select * from articles where razid in(23, 32)");

$stmt->execute();
 return $stmt->rowCount();
}

function set_pages(){
 $this->raz_pages=array();
 if (intval(Route::$routes[1])>0){
$this->raz_pages['year']=Route::$routes[1]; 

 }


 if (intval(Route::$routes[2])>0 and Route::$routes[1]=='page'){ // press/page/2
 $this->raz_pages['page']=Route::$routes[2];
 }


 if (intval(Route::$routes[1])>0 and intval(Route::$routes[3])>0 and Route::$routes[2]=='page'){ // press/2019/page/2
 $this->raz_pages['page']=Route::$routes[3];


 }
 if (intval(Route::$routes[1])>0 and isset(Route::$routes[2])){// press/2910/111-newname



 $this->raz_pages['year']=Route::$routes[1]; 
 $newar=explode("-",Route::$routes[2]);
 if (isset($newar[0]) and intval($newar[0])>0){
 $this->raz_pages['id']=$newar[0];

 }

 }


}

// function eror_page(){

//  if ($this->raz_pages['year'] > 0 and !isset($this->raz_pages['year']) ){

//      Route::ErrorPage_404();
//  }
// }
}

controller_press. php файл

<?php

class Controller_press extends Controller
{

            function __construct()
    {
        $this->model = new Model_press();
        $this->view = new View();

    }


    function action_index()
    {
$this->model->html_headers();

$this->model->set_pages();

        $this->model->get_pages1();


        if (isset($this->model->raz_pages['id']) and $this->model->raz_pages['id']>0){$this->shownew($this->model->raz_pages);}
        else {$this->news_list();}
        $image = "<img>";
if($image > 0) {

}
    $this->model->eror_page();
    $this->right_news();
    }

function shownew($arr){
    //print_r($arr);

$this->model->getcurentnews($arr['id']);
    $this->model->html_headers();

        $this->view->ar['routes']=Route::$routes[1];
        $this->model->removecss('my.css');
        $this->model->addcss('front.css');  
        $this->model->addcss('animate.css');
        $this->model->addsript('viewportchecker.js');
        $this->model->addsript('front.js');



        $this->model->loadscripts();
    $data = $this->model->content;
    //print_r($data);

    if($data[0]['img'] != ''){
        $image ='<figure class="card__image">
                        <img src="'.$data[0]['img'].'" alt="упс картинка пропал НАчальника" >
              </figure>';
    }else {
        $image = null;
    }

$this->model->get_othernews($arr['id']);
$dataother = $this->model->contentother;
    $out='';
    foreach ($dataother as $key => $value) {
        foreach ($value as $key1 => $value1) {
            $card_border = '';
            $card_image = '';
            $bottom_text = '<div class="card__desc destroy_text">'.$value1['tex'].'</div>';
            $im = '';
            if(trim($value1['img']) != '' and file_exists($_SERVER['DOCUMENT_ROOT'].''.$value1['img']))
                {
                    $card_border= null;
                        $img='<a href="/press/'.$value1['razname'].'/'.$value1['id'].'-'.$this->model->utils->str2url($value1['name']).'" >
                            <figure class="card__image">
                                <img src="'.$value1['img'].'" alt="" >
                            </figure></a>';
                }   else {
                    $card_border = 'card--border';
                    $card_image = null;
                    $img = null;
                }
                if(trim($value1['head']) == '' and trim($value1['img']) != ''){
                    $card_image = 'card--image';
                    $card_border = null;
                    $bottom_text = '';
                }
            $head_text='';
                if ($value1['pubdat'] != ''){
                    $head_text.= '<div class="card__period"><span class="period">'.$value1['pubdat'].'</span></div>';
                        } else {
                    $head_text.= '';
                }

            $out.= '<div class=" blockblock '.$card_border.''.$card_image.'">
        '.$img.'
          <div class="card__body">
         '.$head_text.'
            <h4 class="card__title">
                    <a href="/press/'.$value1['razname'].'/'.$value1['id'].'-'.$this->model->utils->str2url($value1['name']).'" class="link" style="font-size: 27px;">'.$value1['name'].'</a>
            </h4>
           '.$bottom_text.'    </div>  
         </div>';


        }
    }

    $out.='';
        $this->view->ar['pubdat']=$data[0]['pubdat'];
        $this->view->ar['img']=$data[0]['img'];
        $this->view->ar['tex']=$data[0]['tex'];
        $this->view->ar['name']=$data[0]['name'];
        $this->view->ar['head']=$data[0]['head'];
        $this->view->ar['image'] = $image;
        $this->view->ar['context']= $out;
        $this->view->ar['getPage'] = null;
        $this->view->ar['year'] = null;
        $fils=array( 'front/top.tpl',  'front/press_underblock.tpl',  'front/bottom.tpl');
        $this->view->SendFiles($fils);


    $this->view->Parse();
    $this->view->Show();
}



function news_list(){

    $this->model->html_headers();

    $this->view->ar['routes']=Route::$routes[1];
        $this->model->removecss('my.css');
        $this->model->addcss('front.css');
        $this->model->addcss('animate.css');
        $this->model->addsript('viewportchecker.js');
        $this->model->addsript('front.js');

        $this->model->loadscripts();

$page = $page === false ? 1 : $page;
        $this->pressPage(Route::$page);  
       $data = $this->model->get_pages($this->offset, $this->limit);

        $data=$this->model->content;
        arsort($data);  



        $year='<ul class="pagination__list">';
        foreach ($this->model->years as $key => $value) {$year.='<li><a href="/press/'.$value['name'].'/" class="link pagination__link" >'.$value['name'].'</a></li>';}
        $year.=' </ul>';

    $out='';
    foreach ($data as $key => $value) {


        foreach ($value as $key1 => $value1) {
            $card_border = '';
            $card_image = '';
            $text='<div class="card__desc destroy_text">'.$value1['tex'].'</div>';
            $im = '';
            if(trim($value1['img']) != '' and file_exists($_SERVER['DOCUMENT_ROOT'].''.$value1['img']))
                {
                    $card_border= null;
                    $info = getimagesize($_SERVER['DOCUMENT_ROOT'].''.$value1['img']);
                    $im=$this->model->image->GetThumb(''.$value1['img'], 1, 500, 500);
                        $img='<a href="/press/'.$value1['razname'].'/'.$value1['id'].'-'.$this->model->utils->str2url($value1['name']).'" >
                            <figure class="card__image">
                                <img src="'.$im.'" alt="" >
                            </figure></a>';
                }   else {
                    $card_border = 'card--border';
                    $card_image = null;
                    $img = null;
                }
                if(trim($value1['head']) == '' and trim($value1['img']) != ''){
                    $card_image = 'card--image';
                    $card_border = null;
                    $text='';
                }

            $head_text='';
                if ($value1['pubdat'] != ''){
                    $head_text='<div class="card__period"><span class="period">'.$value1['pubdat'].'</span></div>';
                        } else {
                    $head_text.= '';
                }

            $out.= '<div class="tiles__card card card--promo '.$card_border.' '.$card_image.'">
        '.$img.'
          <div class="card__body">
         '.$head_text.'
            <h4 class="card__title">
                    <a href="/press/'.$value1['razname'].'/'.$value1['id'].'-'.$this->model->utils->str2url($value1['name']).'" class="link" style="font-size: 27px;">'.$value1['name'].'</a>
            </h4>
           <em> '.$value1['head'].' </em>'.$text.'
            </div>        
         </div>';
        }
    }
    $out.='';




        // Добавил дату чекай 
        $this->view->ar['pubdat']=$data['pubdat'];
        $this->view->ar['tex1']=$data['tex'];
        $this->view->ar['name1']=$data['name'];
        $this->view->ar['head']=$data['head'];
        $this->view->ar['img']=$data['img'];
        $this->view->ar['context']=$out;
        $this->view->ar['year'] = $year;
            $this->view->ar['news_block'] = null;
        $yearses = $this->model->years;
          if($this->model->raz_pages['year'] > 0 ){
          $press = 'press/page/';
         }  else {
              $press = 'press/page/';

         }    




             $this->view->ar['getPage'] = $this->model->utils->paginationPress($press, $this->totalPages, $page);
        $fils=array( 'front/top.tpl',  'front/press.tpl',  'front/bottom.tpl');
        $this->view->SendFiles($fils);


    $this->view->Parse();
    $this->view->Show();

}


function pressPage($page) {

                               if($page == false)
                                            $page = 1;

                               $this->limit = 10;
                               $this->counts = $this->model->get_pressCount();
                                $this->totalPages = ceil($this->counts / $this->limit);
                               $this->offset = ($page - 1) * $this->limit;
                }


}

некоторые ссылки работают правильно, например, когда я нажимаю на History link, переход осуществляется по адресу URL website.com/kz/history

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...