Yii2 pagination without pager - php

I'm trying to make a selection of records from the database by a certain number, for example, the first 5, when passing through the page number, get the other 5.
For example my current request:
/api/get-doctors?id=null&search=null&specification=null&price_min=null&price_max=null&experience_min=null&experience_max=null&location=null&clinic=null&filter=null&top=null&lang=en
I want to add a new parameter page=1
I usually get entries through the find
$all_doctors = Doctors::find()->localized($lang)->where(['status' => 1])->all();
The standard solution through the pager does not suit me because I do not use the url.How can i bypass implementation via pager?

Related

How to set default Data Table Page Length to 100 in complete project?

I have a large report section in my project and have 100's of report using data table,with some customize data table functionality. Now my client want :-
Default page length for all data table reports to be increased from 10 to 100 , which should apply by default to all existing data tables and new also.
Data table searching should also be cached (i,e if i filter a record with city name X, it returned 10 records , now i click details of any 1 of them which opens a new page. ) what he wants exactly lies here( if he goes back from details page , the previous search record list of 10 should come, despite of the full record list.)
Hope i was clear with my queries, any suggestion and help on this will be highly appreciated.
I'll answer to this questions when you are using Yajra Datatables.
For first question:
You can store page length number in your DB, in some 'settings' table, which can be managed from admins. And get that for all pages. Also you can get that using Laravel Caches, and with that you don't need to retrieve from DB for each time. Instead you will retrieve that from caches, which will speed up your app.
Now assume you alredy got that number like this, using off. doc.:
$page_length = Cache::get('page_length');
You can create some GeneralController which will extends from Controller, then in constructor you can write that and share that for all blades like this:
View::share('page_length', $page_length); // Illuminate Support Facade
Or you can pass that $page_length in some "protected $page_length = null;", init in constructor of GeneralController, and use that in your other controllers which extends from GeneralController.
So now you can get that in blades. You can use that like this
var YajraDataTable = $('#yajra_datatable').DataTable({
"pageLength": parseInt("{{ $page_length }}"),
Answer for second question I will write with real example little bit later.
I will suggest to use Yajra DataTable follow the link for understanding.
This is Demo link which will help.
Yajra DataTable is ajax datatable which offer number of record per page and searching.Even I am also using the same.

Zend paginator get all items per page using setItemCountPerPage() function

I am using SE4 application of Zend framework. After executing query with Paginator, I am setting items per page like 10, 20, 50, all etc. using function setItemCountPerPage() of zend.
It is working fine for number provided or for zero value. But I have thousands of records and want to show all on single page without pagination.
I am using following code after query-
$this->view->paginator = Zend_Paginator::factory($select);
$this->view->paginator->setItemCountPerPage($perPage, 10);
$this->view->paginator->setCurrentPageNumber($this->_getParam('page',1));
Please let me know what value should I provide for $perPage, so all items fetched by query will get display on page.
You can simply pass the size of your list (http://php.net/manual/de/function.sizeof.php), or deactivate the pagination. But if you have thousands of records, it would be a good idea to load them in sequence, not all at once :) Probably with ajax on scroll to bottom of page (Load ajax when scroll reaches 80%).

Linkable search in Laravel

I'm building a basically single page web application. In it's finished state, it will use AJAX where it's possible, but I'm working on it's static http fallback in the event if javascript is not available/turned off.
Anyway, there are multiple things that need to be in the url/uri in order to be linkable:
order by (first name, last name)
page number (if paginated)
search term (if selected)
state/county (if selected)
country (if selected)
order type (if selected)
This would look like something like this using only GET variables:
my.app?page=2&order=lastname&country=usa&state=colorado&searchterm=mysearchterms&ordertype=downloadable
But since if I'm right the convention in Laravel is to use named routes, so the URI above would look something like:
my.app/search/usa/colorado/mysearchterms/downloadable/page/2/lastname/
Also, since I'm developing this part without javascript, I need a form to submit the search+country+state+ordertype and links for the page and order, which means that when a user clicks a pagination link or order link, the URL would be overridden.
Is there a simple way to combine all of these into readable urls that don't override each other?
Why not still use GET query sting for search results as you indended?
Pass input from search form to Controller#method_A. Validate the input it and redirect to Controller#method_B - with additional GET params array:
return Redirect::route('search', array(
'order' => $order,
'country' => $contry,
'state' => $lastName
));
The method_B retrieves search results and returns the results page, which is linkable because of the query string in the URL.
You can get the query string params with standard Input::get('name').The pagination &page param should work with it with the GET string out of the box.

Preserve previous pagination and search filter after Add/Update of record

I have this scenario that I need to keep the current pagination and search filter on my employee list after I have added or updated an employee record. Since I am using GET method for pagination and search filter, I am planning to keep the URL after add/update action so that the user will be redirected to the employee list with current search filter and page number.
My question now is should I keep this URL in Session or better store it in a table? The URL will be removed once the user go to other modules (e.g. department, subject, etc).
I am using Laravel 4, maybe they have a function that I can use for this kind of scenario?
Flashing it to the session would probably be the easiest way to do this.
Session::flash('key', 'value');

Pulling multiples pages of search terms from Twitter

I'm trying to figure out a way to pull all tweets of a specific search term via PHP and the Twitter search api.
So functionality would include
1. Include a search term
2. Pull terms from each page.
3. Only pull new terms from last search
4. Export to a db or a flat file.
I'm pretty clear on all of these except for traversing across multiple pages
The twitter API takes a page number parameter. In the atom results, there are link elements, with rel attributes for next and previous. This will be your best indicator as to whether you should go looking for a 2nd page and so on. The href attribute of that tag will even tell you the URL you should request.
The query you create also takes a since_id parameter. You'll want to store the largest id number you see in your responses and use it in subsequent requests so that you don't have to filter duplicates.
As for data storage, your selection is probably best guided by what you plan to do with the results... if you're going to be doing any querying, you should probably file it away in a database, i.e. MySQL. If you're just logging, flat file should do you fine.
The search API has a page parameter:
page: Optional. The page number (starting at 1) to return, up to a max of roughly 1500 results (based on rpp * page. Note: there are pagination limits.
Example: http://search.twitter.com/search.atom?q=devo&rpp=15&page=2
Does that help?
The twitter search api takes a page parameter:
# page: Optional. The page number (starting at 1) to return, up to a max
of roughly 1500 results (based on rpp
* page. Note: there are pagination limits.
* Example: http://search.twitter.com/search.atom?q=devo&rpp=15&page=2

Categories