I have created a custom object which contains multiple fields that I want to be able to show on a Visualforce page. From the discussion I've had with another developer it was recommended that I use a utility class and just reference that from the standard class. Here's what I've got.
Utility class
public without sharing class pkb_content_Utility {
public PKB_Content__c pos{get;set;}
public pkb_Controller() {
pos = [SELECT Home_Forum__c FROM PKB_Content__c];
}
}
While I only reference Home_Forum__c, there are multiple other fields I need to reference as well but I am unsure of the best way to do this.
Main controller class
pos = pkb_content_Utility.pkb_Controller();
Visualforce code
<apex:page showHeader="false" standardController="KnowledgeArticle" extensions="pkb_Controller">
<apex:outputText value="{!pos.Home_Forum__c}"/>
</apex:page>
Best Answer
Adding
ApexPages.StandardController sc
as a constructor argument (that can be used to get a reference theKnowledgeArticle
if that is needed) makes the class fit the controller extension pattern that it looks like you are aiming for based on your page:This pattern "mixes in" the controller extension with the standard controller so your page can reference both; in your example you are only referencing the controller extension field:
See e.g. the Building a Controller Extension documentation for more information.