A
A
Anton2015-07-25 08:06:06
Kohana
Anton, 2015-07-25 08:06:06

Add values ​​from db to limit(10) kohana 3.1 framework?

Made an additional block for output.
Code in the template:

<?php foreach ($block_1 as $news_1):?>
тут новости со стилями и т.д
<?php endforeach?>

in the main controller application\classes\controller index.php
code for the block:
$this->template->categories = $data;
$this->template->block_1 = ORM::factory('news')->where('status', '=',
 1)->order_by('id', 'DESC')->and_where('block1', '=',
 1)->limit(10)->find_all();

How to display the value from the admin panel in limit(10) (the value of the number of news to show on the main page)?
In the "admin panel", in the settings, I made the per_page_block1 field, in the settings table.
I'm trying to set a limit on the output of news on the main page through the admin panel.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
I
Ivan GiBSON, 2015-07-25
@gibson_dev

$limit = DB::select('per_page_block1')->from('settings')->limit(1)->execute()->get('per_page_block1', 10);
$this->template->categories = $data;
$this->template->block_1 = ORM::factory('news')->where('status', '=',
 1)->order_by('id', 'DESC')->and_where('block1', '=',
 1)->limit($limit)->find_all();

I wrote from memory, but correct the request yourself as you need.
I generally made a static class for settings https://gist.github.com/gibson/1a54156c4e2faf83df8f
Where then
Settings::get('page_limit',10)

E
entermix, 2015-07-25
@entermix

For Kohana, there is a ready-made module for implementing pagination (does not come with the box)
https://github.com/shadowhand/pagination

A
Anton, 2015-07-25
Websaytovsky @ws17

Thank you very much for the answer , oh, but I saw similar examples, but I thought that this was not right, not what was needed, but it turned out that this was what was needed and it worked! how simple it is)))
as I understand it, if there is nothing in the settings in the setting, then it takes parameter 10 and displays 10 news, did I understand correctly? (that is, if it does not take a value from the database, if there is nothing there, then it substitutes the value 10.
get('per_page_block1', 10);
======== ==========================================
Is it possible to connect pagination to all this? In general, there is pagination on the site, but how to do it for this news output, for this block.
let's set let's display 10 news, and if there are more of them, then pagination would work. and pages appear.

$limit = DB::select('per_page_block1')->from('settings')->limit(1)->execute()->get('per_page_block1', 10);
$this->template->categories = $data;
$this->template->block_1 = ORM::factory('news')->where('status', '=',
 1)->order_by('id', 'DESC')->and_where('block1', '=',
 1)->limit($limit)->find_all();

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question