7911 Posts in 1354 Topics by 930 members
DataObjectManager Module
SilverStripe Forums » DataObjectManager Module » Help with basic table - managed via modelAdmin - with display limit & multiple page results
Discuss the DataObjectManager module, and the related ImageGallery module.
Moderators: martimiz, UncleCheese, Howard, Sean, Ryan M., biapar, Willr, Ingo, swaiba, simon_w
| Go to End | Next > | |
| Author | Topic: | 1806 Views |
-
Re: Help with basic table - managed via modelAdmin - with display limit & multiple page results

28 August 2010 at 2:50am
this:
Director::set_environment_type('dev');goes in mysite>config right?
and yeah i noticed you used a generic term, but i wasnt sure what im supposed to replace it with??
i didn't realise that would throw up an error (d'oh!) -
Re: Help with basic table - managed via modelAdmin - with display limit & multiple page results

28 August 2010 at 3:17am
Yup, mysite/_config.php.
You can replace that filter clause with whatever database fields you want to search on..
-
Re: Help with basic table - managed via modelAdmin - with display limit & multiple page results

28 August 2010 at 3:18am
OK thanks, i'll have to see if i can work out what the fields are named!
-
Re: Help with basic table - managed via modelAdmin - with display limit & multiple page results

29 August 2010 at 2:43am
got it working!!
i added the column name "Title" and now it searches perfectly, and the results are pretty much EXACTLY how i was hoping!one last thing, how do i search more than one table column?
ideally, I'd like to search the whole table, is there a way i can name the table rather than every column?here's mu updated function:
public function doProductSearch($data, $form) {
if(isset($data['s'])) {
$filter = "Title LIKE '%".Convert::raw2sql($data['s'])."%'";
}the table itself is called Product, but when i tried that it threw up the same error as before.
-
Re: Help with basic table - managed via modelAdmin - with display limit & multiple page results

29 August 2010 at 3:10am
oh and also, when i try and view the 2nd page of results from this product search, i get this error:
SecurityID doesn't match, possible CSRF attack.i've had this before with a hard coded form and i had to switch off sitewide SecurityIDs, which isnt really ideal!
can you help me with fixing this problem? thanks! -
Re: Help with basic table - managed via modelAdmin - with display limit & multiple page results

29 August 2010 at 3:42am
Multiple filters:
I would first define an array $searchable_fields on your Product object. Then:
public function doProductSearch($data, $form) {
if(isset($data['s'])) {
$filters = array();
foreach(Product::$searchable_fields as $field) {
$filters[] = "$field LIKE '%".Convert::raw2sql($data['s'])."%'";
}
$filter = implode(" OR ", $filters);
// etc...
}For the security ID issue, that's going to be a problem. The pagination isn't posting the form params with each page, which creates more issues than just the security ID.. I think you can solve that by setting your form method to "get", so the params are posted for every page through the URL.
public function ProductSearchForm() {
$f = new Form (
$this,
"ProductSearchForm",
new FieldSet(new TextField('s','')),
new FieldSet(new FormAction('doProductSearch','Search'))
);
$f->setFormMethod('get');
reutrn $f;
} -
Re: Help with basic table - managed via modelAdmin - with display limit & multiple page results

29 August 2010 at 3:48am Last edited: 29 August 2010 3:49am
OK that code has confused me a little, and as is isnt that important, i'll leave that out!
the security ID resolution worked perfectly though! (except for a typo on the word "return")thanks for all your help!!
see it in action here:
http://www.worldaircraftsolutions.com.sg/catalogue/ -
Re: Help with basic table - managed via modelAdmin - with display limit & multiple page results

29 August 2010 at 4:05am
OK last question... i've set the field value to "Search by title"
but is there a way i can make that value become blank on focus?
usually i'd set these things in the form coding, but when forms are created via the .php files like this im not sure how to add variables like that!usually i'd use this:
onClick="this.value=''"but how do i implement that into a form when the form is generated by PHP like this? (amateur question im sure!)
| 1806 Views | ||
| Go to Top | Next > |

