before sending any thing to view (text in the browser).
check if your model that if id is valid or not .
if id is not valid redirect to your error page
header("HTTP/1.1 301 Moved Permanently");
header( 'Location: http://examplesite.domain/errorpage' ) ;