Created
December 8, 2016 13:46
-
-
Save anonymous/45cd44af1976fa9fcb2b4e0ac6a93fc1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class BlogPost_Controller extends Page_Controller | |
{ | |
private static $allowed_actions = array ( | |
'FilterOnTags' | |
); | |
public function init(){ | |
parent::init(); | |
} | |
public function FilterOnTags() { | |
$tagFilter = new DropdownField( | |
'TagFilter', | |
"So what'll it be, yes or no?", | |
array( "N"=>"No", "Y"=>"Yes") | |
); | |
$fields = new FieldList($tagFilter); | |
$actions = new FieldList('FilterFormTags', 'Post'); | |
return new Form($this, 'FilterOnTags', $fields); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If you ever come back to view this gist again...
Form
constructor:Form::create($this, __FUNCTION__, $fields, $actions)
, but it should still render without actions I think.BlogPost_Controller
which could be causing a conflict for the auto-loader, resulting in your method simply not existing.Expanding on that last point, you're declaring this on
BlogPost_Controller
, and thus is only in scope when you're rendering aBlogPost
(directly, as a page) in your template. At a guess I'd say you're probably trying to render this on aBlog
scope, which is fine, but you should define the method onBlog_Controller
instead. You should be access it in a template on aBlogPost
context with$Parent.FilterOnTags
.Furthermore (on the central point), if this isn't a pseudo-code snippit, and you're using the blog module, and you're not editing the module core code (which one shouldn't do), then you need to change your classname & inheritance. The manifest (for the autoloader) will choose one of the two declarations, it's possible this isn't working because this method simply doesn't exist in the included class.
To this end, you should look at the documentation for
Extension
(andDataExtension
) and apply this method through their use. In that case it's a trivial change to change the class definition toclass FilterTagExtension extends Extension
and the form declaration toForm::create($this, $this->owner, $fields, $actions)
. Then applying with the config system (yml) to bothBlog
andBlogPost
.