View more context

 

MichalKleiner

nothing changed from 4.3 to 4.4 in terms of why it wouldn’t work

Karan Kumar

Hi Team, In SS3 we could do some thing like [in snippet below] and you could call $searchForm from page template but in SS4 we can't have two classes in one file, so when I separate out TestSearchPage and TestSearchPageController in two different files, page template can't call $searchForm. I tried adding getControllerName method in TestSearchPage class but that didn't help.

Karan Kumar

`<?php

class TestSearchPage extends Page {

}

class TestSearchPageController extends PageController { public function searchForm() {

}

public function index() {

}

}`

StefanO

@Karan Kumar have you enabled search in _config.php? e.g FulltextSearchable::enable(array(SiteTree::class));

StefanO

SearchForm is built in you shouldn't need to alter anything unless you want specific search behaviour

Karan Kumar

@StefanO Thanks for your help! sorry yes you're right my bad, I should have used something else. Actually I'm implementing Solr Search functionality and the true method name is SolrSearchForm(). But I haven't enabled search in _config.php. Just to keep things simple, if I change my method name from searchForm() -> toSomeRandomMethod(). Would I then be able to access $toSomeRandomMethod in TestSearchPage template in SS4 having two classes in two separate files?

Karan Kumar

<?php class TestPage extends Page { }

class TestPageController extends PageController{ public function someRandomMethod() { } public function index() { } }

theruss

@Karan Kumar I have come across a problem like this. If you separate your Page and Controller, and they exist under the same namespace, then things should work as expected.

StefanO

The two files shouldnt be an issue if they are under the same namespace