Hi Habr and everyone who uses PHP CodeIgniter framework!
In the process of creating a certain application on CI, I had a question about finding information in a database without using GET.
I did not find any ready-made solutions in the CI wiki, so I decided to make my own “bicycle”.
To begin with, let's look at examples of links that we can see when searching on different sites:
')
Sample parameter transfer links via GET
- sitename / search /? q = text
- sitename / index.php? do = search & p1 = value1 & p2 = value2 & uname = test
Another example:
- sitename / search / query / p1 : 0: p2: value: p3: text
If we look for one parameter, then the link looks more or less normal.
But if we need to look for something like 5 or more parameters?
That's when our link
becomes terrible and makes us look for another solution.
Example of parameter transfer links via POST (while only one =))
- sitename / search / query / unique_identifier / page_number
Actually in this link there are no parameters to search,
Only the identifier of the search result already stored in the cache.
If we pass parameters through the POST array, then our link will have
almost the same view with different incoming search parameters. It remains only to solve
"Problems and complexity" of a similar search method.
For the solution, we need CI + "any caching class" and a little time.
And so, how will our system work:
1. You need to create a unique key to save the search results in the cache.
(The link to view the search results will look something like this:
sitename / search / query / 7ad549053bf2be45f309920b7b6a24bf / 10 )
2. Make a request to the database.
3. Save the result in the cache.
4. Print the search result to the user.
I would like to give a couple of code examples here,
but a lot of code so I will provide a link for
Downloading a ready-made controller for searching users + own caching library and test database.
Download