[SalesForce] Custom controller variable isn’t displaying in Visualforce page

I have a custom controller with a variable I'm assigning a value to and then trying to display that value on a VF page but the value is not displaying. It's a very simple case – what am I missing?


public with sharing class myController {
    public string pid {get;set;}

    public void myController() {
        pid = 'hard-coded value in controller';   

VF page:

<apex:page controller="myController"

<apex:PageBlock title="My title">
PID: {!pid}


Best Answer

You need to specify controller in apex:page

<apex:PageBlock title="My title" controller="myController">
PID: {!pid}

Refer Creating a Custom Controller Class