M
M
masimka2017-09-12 10:03:00
Kohana
masimka, 2017-09-12 10:03:00

Can I prepare the template sections I need in a Kohana model method?

hello, almighty hive mind.
I don’t want to load the controller, I need to prepare template sections before inserting them into the view.
Can I do this using the method described in my model and then use them in the controller?
In other words, I can throw the view preparation into a method and then return the already prepared view blocks to the main view in the controller. Will it be right? And where can I read about correctness?
====

МОдель_Подготовка_блоков {
паблик_подготовка_одного_блока (ид_блока, еще_ид){
берем переменную = 
загоняем_в_нее_подготовленный_кусок_html;
импортируем_в+переменную_с_помощью_view (View::factory('public/landing/block'))
возврат переменной_с_уже_готовым_кодом_хтмл.
}
}

// Controller
Новый контроллекр _ наследник_Коммон {
вывод_контента_на_главной (){
полученые_блоки = ОРМ::получениевсех блоков();
 каждому_блоку(форич)  (полученые_блоки как каждый_блок){
массив_на_выход_с_контентом = ОРМ('Подготовка_блоков')->подготовка_одного_блока (каждый_блок)
}
вывод в гланый вью_уже_подготовленных блоков = view (View::factory('public/landing/all_block'))
}
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton October, 2017-09-12
@masimka

In my humble opinion, the idea is not good.
The bottom line is that html should be in view. Good code is understandable code, but your version will not be so. For example: I need to fix your footer, I climb into the view, but the footer is not there.
The MVC model is simple and well-known, you can read Kohana on it here .
In short: Controllers = the main application logic, Models = accessing the database, creating methods and classes in order to offload controllers, view = displaying all html and data to display.
Also, I think that various helpers that are often built into frameworks spoil readability for a wide range of developers. Pure html is known to everyone who is familiar with the web, what else do you need?
In order to unload your views, somehow structure them and avoid repeating large pieces of code (ala template), use template engines, for example twig

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question