Answer the question
In order to leave comments, you need to log in
How to display from the model to the page, what code to add for the output?
Hello. There are blocks that are displayed on any given page.
in base 2, the pages and blocks table, when choosing from the admin panel on which page to display the block, an entry is made in pages_blocks where only the id of the block and the page.
many_to_many model code
public function getRelatedBlocks($page_id)
{
//Выбираем id всех блоков, относящихся к данной странице
$blocks_ids = $this -> selectColumn(array("fields->" => "blocks_id",
"pages_id" => $page_id,
"table->" => "pages_blocks"));
//Если это не предусмотреть в оператор "id->in" пойдет пустая строка и возникнет SQL ошибка
if(!count($blocks_ids))
return;
$html = "";
//Извлекаем содержимое активных блоков
$rows = $this -> select(array("id->in" => implode(",", $blocks_ids), "active" => 1));
foreach($rows as $row)
{
$html .= "<h3>".$row["name"]."</h3>";
$html .= "<div>".$row["content"]."</div>";
}
return $html;
}
$content = $mv -> pages -> defineCurrentPage($mv -> router);
echo $content -> name;
echo $content -> title;
echo $content -> content;
there is a $content object with data for the current page. It has $content -> id is the id of this page from the pages table.
The pages_blocks table contains rows with links of pages and blocks by their id. It is necessary to extract from there all the lines with pages_id = $content -> id. And then from these lines take blocks_id which will be the blocks for the page.
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question