Main  /  Edit version 1  /  Edit version 2  /   /  Users Area

Difference "Customize your "Page not found | 404" page" ver. 1 versus ver. 2

Content:

By default application::main() returns a 404 page if it does not find any dispatcher for a given url:
void application::main(std::string url) {
if(!dispatcher().dispatch(url)) {
response().make_error_response(http::response::not_found);
}
}
To create your own 404 page, you must override the default application::main().
void myApplication::main(std::string url) {
if (!dispatcher().dispatch(url)) {
response().status(http::response::not_found); // Set the 404 status.
// Set the 404 status.
response().status(http::response::not_found);
response().out() << "Page not found";
}
}
Or you can use your own templates:
Or you can use your own [template](/wikipp/en/page/cppcms_1x_templates):
void myApplication::main(std::string url) {
if (!dispatcher().dispatch(url)) {
response().status(http::response::not_found); // Set the 404 status.
// Set the 404 status.
response().status(http::response::not_found);
content::main c; // Your main template.
// c.content and c.title are defined in your template.
c.content = "Use the search box.";
c.title = "Page not found";
render("main", c);
}
}

About

CppCMS is a web development framework for performance demanding applications.

Support This Project

SourceForge.net Logo

Поддержать проект

CppCMS needs You


Navigation

Main Page


Valid CSS | Valid XHTML 1.0