I apologize to the PHP Professionals. How best to implement the definition of the request and content upload. I now have it all works as follows.

Template:

<?php include('classes/content.php'); if(!isset($_GET['show'])){ $show = 'main'; } else { $show = addslashes(strip_tags(trim($_GET['show']))); } $data = new Content; $result = $data->get_content($show); ?> <!DOCTYPE html> <html> <head> <title><?=$result["title"]?></title> <link rel="shortcut icon" href="icons/favicon.ico" type="image/x-icon" /> <link href="http://yandex.st/bootstrap/3.0.3/css/bootstrap.min.css" rel="stylesheet"> <link href="css/style.css" rel="stylesheet"> </head> <body> <div class="panel panel-default islogged"> <div class="panel-body"> <div class="admin_menu"> <a href="/">Главная</a> <a href="/edit">Редактирование</a> <a href="/?logout" style="color: red">Выход</a> </div> <hr> <?=$result["text"]?> </div> </div> </body> </html> 

Class:

 <?php class Content { public $connection = null; public function get_content ($show) { //Connection $this->connection = new mysqli(host,login,password,name); $this->connection->set_charset('utf8'); //Check connection if(!$this->connection->connect_errno) { //Check page $query = $this->connection->query("SELECT title, text FROM content WHERE name = '$show'"); //Check exist page if($query->num_rows == 1) { return $query->fetch_array(MYSQLI_ASSOC); } else { return array( "title" => "Ошибка", "text" => "Такой страницы не существует", ); } } else { return array( "title" => "Ошибка", "text" => "Ошибка подключения к базе", ); } } } ?> 

    1 answer 1

    Transfer get get to class:

     public $render; public function __construct() { if(!isset($_GET['show'])){ $show = 'main'; } else { $show = addslashes(strip_tags(trim($_GET['show']))); } $data = $this->get_content ($show); $this->render = (object) $data; } 

    Conclusion:

     $content = new Content; $content->render->title; $content->render->text; 
    • 2
      Content should not check what is currently lying around in the environment (which, moreover, is easily changed). His only task is to display the content directly with the key that was indicated to him; he himself should not invent it. - etki
    • Is it possible to shove the returned data into an array? Well, that is, in order not to create a bunch of public variables, and in the array all this? - vladimir54
    • do a separate function and return to it what you need. And to transfer in public or in general a variable like array to make and in it to push from different necessary functions and to return already ready array. - thunder
    • You can make one public variable (public $ render;) Write $ this-> render = (object) $ data; the output will be as follows: $ content = new Content; $ content-> render-> title; - Valentin Zhukov