We are using CakePHP's default search behavior with listing page and once I have selected some criteria for searching, it works fine..
Now, whenever I go on page no. 2 with searched criteria, the search parameters does not pass with the Paging and it becomes a normal listing.
Do anyone have some idea about searching and paging combination, with CakePHP 1.2 default search plug-in.
Let me know your responses ASAP.
Thanks !
Take a look at this tutorial. It looks vaguely like what I've done in the past.
http://mrphp.com.au/code/search-forms-cakephp
If you work with Sessions, then the search criteria could be stored in the session.
You just need to make sure that the user also can easily reset the stored search criteria.
$this->paginate = array(
'conditions' => array('Model.name LIKE' => '%'.$storedInTheSession.'%'),
'order' => array('Model.name ASC'),
);
Assuming that your form is created with 'type'=>'get'
echo $form->create('Content', array('action' => '/index', 'class' => 'forms','type'=>'get'));
you can do something like:
if(isset($_GET['some_criteria'])){ //if some of you fields is set
unset($_GET['url']); //this is set by CakePHP and we don't need it
$paginator->options = array('url'=> array('controller' => 'content', 'action' => 'index', '?' => http_build_query($_GET)));
}
Although it might suit your needs I warn you that it might not be the CakePHPiest way
Related
I am needing to make some sharable blog post URLs. To do that, the URL must be something like webpage.com/blog-post-title. It cannot be webpage.com/5GFd5GDSg2345WD.
Since I am using dynamic routing, I need to get a Contentful entry using nothing but what is on the URL. There should not be any queries because queries are ugly and reduce shareability, like webpage.com/blog-post-title?query=queriesAreUgly.
Unfortunately, I need the entryId to get the entry. Also unfortunately, the entryIds are all very ugly and therefore completely useless/unusable. I wish I could set my own entryId, but this does not appear to be possible for mysterious reasons.
I could make a lookup table that pairs URLs with entryIds, but I'm going to be handing this contentful project to someone who is not tech savy, and they should not have to manage a lookup table.
I could get all blog entries then filter by blog title, but, very obviously, this is inefficient, as I would be loading thousands of lines of text for no reason at all.
I could create my own backend API and doing all this myself, but this is also a bad solution because it would take too much time and I could not give it to my non-tech-savvy client.
There are seemingly no solutions to this problem which created by Contentful's inherent needless inflexibility.
The only efficient way to get this to work is to find the entry not by its ID but by one of its fields. Is there a performant/efficient way to do this, or am I just going to have to filter through every single blog post until I find the one with the correct title?
How about adding a 'slug' field to the blog post content type, which you can auto-generate from the title using the field settings (so you don't have to type it out manually?)
You can then filter on the slug field in the query.
If you're using the JavaScript SDK (which it sounds like you are), you can use getEntries() and filter by the slug field to get a single blog post. Like so:
import { createClient } from "contentful";
const client = createClient({
space: {SPACE_ID},
accessToken: {ACCESS_TOKEN},
});
const response = await client
.getEntries({
content_type: "blogPost",
limit: 1,
"fields.slug": "blog-post-title",
})
.then((entry) => entry)
.catch(console.error);
Hey guys I've developed a school database grouped by city and state but I put cities word before routes.
so now every url comes like x.com/cities/city_name/state_name/school_name
my routes are like
Route::get('cities/{cityName}')
But now I want to delete this cities word because of SEO. When I remove cities word from my routes.php my other pages are don't work (admin, about_us)
so I thought maybe I can hide cities word with htaccess is it possible ? if so how can i do it ?
I know this won't be an answer you like, but take it more as a warning for future projects: use named routes.
If you had your route, say:
Route::get('cities/{cityName}', array('as' => 'city', 'uses' => 'CityController#city'));
And you had created your routes in the views using any of the provided methods:
route('city', array('cityName' => 'New York'));
form_open(array('route' => array('city', 'New York'));
URL::route('city', array('cityName' => 'New York'));
Now you wouldn't need to change anything in your views, you could just change the route itself:
Route::get('cities', array('as' => 'city', 'uses' => 'CityController#city'));
And forget about the rest (even the now missing parameter. I know, it won't look perfect...)
If you still want to go the .htaccess route you could try:
^cities/(.+)/(.+)/(.+)$ /cities/$2/$3 [L]
Yii 1.1.13.
On /index.php/employee/admin (autogenerated by Gii and then modified by me) search boxes are shown by zii.widgets.grid.CGridView.
How to remove these search boxes altogether? I want the table without search.
(Note that I don't want search because it misbehaves with my composite models synthesizing data from several tables and transforming it into a different data format for UI than the data format in DB.)
When creating the zii.widgets.grid.CGridView set the property filter to null.
$this->widget('zii.widgets.grid.CGridView', array('filter' => null, /* etc */));
Also you can remove completely the 'filter' property.
The error was because of this line:
//'filterModel' => $searchModel,----this is what causes the boxes
I have basically commented this line out and the search boxes aren't shown.
I'd like to display some rows of data from a database table. I'm keen to get some advice on how to best achieve this.
Let me explain how I do it now and why this question has been raised: I currently have a scheme whereby the controller loads data into an array, and then passes this to the twig template. The twig template then calls a "utility" controller to display the array. The utility controller takes care of formatting the fields, etc. So, for example:
Controller:
$cols = array('1','2','3');
$rows = array();
for (...) {
$rows[] = ...
}
return array(
'cols' => $cols,
'rows' => $rows,
);
Twig:
{% render 'Bundle:Table:print' with { 'cols': cols, 'rows': rows } %}
However, when I tried to move to Symfony 2.2, I ran into a few problems because of the way that internal calls are now handled in 2.2. See http://symfony.com/blog/new-in-symfony-2-2-the-new-fragment-sub-framework
It looks like the arrays are converted to URL parameters, and then parsed out again (using parse_str). This lead to two distinct problems:
For larger tables, PHP was limited to 1000 items in the arrays. (Yes, I can increase the limit, but is that sensible?)
DateTime types seemed to lose their typing and were seen as just arrays.
So, is my original approach workable going forward? If not, what approach should be used?
Thanks.
A third party suggested "What about writing a Twig extension instead of using a Symfony controller?"
http://symfony.com/doc/current/cookbook/templating/twig_extension.html
Does anyone know of a plugin for modx that will show all the pages that link to each document ID or would I have to create my own?
You could write a snippet for yourself. Use the code
$weblinkArray = $modx->getCollection('modWeblink',$criteria);
where $criteria is the set of criteria, restrictions or constraints you want to set, like
$criteria = array(
'published' => 1,// this is optional, more parameters can be optionally added as well
)
This gives you an array of the documents that link. Further, you know how to access data of an array.