Main  /  Edit version 7  /  Edit version 8  /   /  Users Area

Difference "Migrating to CppCMS 1.x.x." ver. 7 versus ver. 8

Content:

## Introduction
In this article we would describe the process of migration of the code-base to new CppCMS version. How to do it in painless way? What should you care of and so on.
In this article we'll describe the process of migration of the code-base to a new CppCMS version. How to do it in a painless way? What should you care of and so on.
## Why to migrate?
## Why migrate?
Many reasons:
- CppCMS 1.x.x release expects much longer life-time support, providing binary backward compatibility.
- Localization in CppCMS make significant step forward, including decent support based on ICU library.
- Localization in CppCMS has made significant steps forward, including decent support based on ICU library.
- New version provides support of Comet applications and event driven programming support.
- Simplifies development providing internal HTTP server.
- Provides full Win32 support.
- Provides great range of supported compilers: Gnu Compilers Collection, Microsoft Visual C++ 2008, Intel Compiler and Sun Studio 12.
- It removes dependencies on low quality CgiCC library that makes CppCMS interfaces inconsistent and removes dependency on specific Boost version.
## How to migrate?
### Main program
The main program changed completely.
It is best to rewrite it according the first [Tutorial](/wikipp/en/page/cppcms_1x_tut_hello).
### Templates
Namespaces or now called skins. So change
<% namespace view %>
<% end namespace %>
to something like
<% skin my_skin %>
<% end skin %>
Classes are now called views. So change
<% class master uses data::message %>
<% end class %>
to something like
<% view master uses content::message %>
<% end view %>
To output content, the syntax now changed from
<% foo %>
to
<%= foo %>
### Includes
The data (content) holder now needs to be changed to include
#include <cppcms/view.h>
instead of
#include <cppcms/base_view.h>
The applications now have as constructor
my_app (cppcms::service &srv);
instead of
my_app (cppcms::worker_thread &worker);
You need to include:
#include <cppcms/applications_pool.h>
#include <cppcms/service.h>
#include <cppcms/http_response.h>
instead of the cgicc headers:
#include <cgicc/HTTPHeader.h>
#include <cgicc/HTTPStatusHeader.h>
### Configuration
To access configuration you now use:
settings().get("").
instead of:
app.config.sval("")
Unfortunately settings() is not const, so you need to unconst your methods or use an ugly const_cast like:
cppcms::json::value config =
const_cast<my_app*>(this)->settings();
The configuration file format also has completely changed.
So you may want to start with a new configuration file.
### Cgicc
CppCMS 1.0.0 does not use CgiCC any more (CgiCC allows to start CppCMS easily but it wasn't really good library in long term).
Now you use [cppcms::http::request](http://cppcms.com/cppcms_ref/latest/classcppcms_1_1http_1_1request.html)
To access the query string you now can use:
request().query_string()
instead of:
env->getQueryString()
To decode URLs you can use
#include <cppcms/util.h>
cppcms::util::urldecode(url)
instead of:
cgicc::form_urldecode(url)
To set an http content header you can use:
response().set_content_header("text/xml");
instead of:
cgicc::HTTPHeader* hdr = new cgicc::HTTPContentHeader("text/xml");
set_header(hdr);
To add some other kind of header (e.g. for redirection) you can use (nginx):
response().set_header("X-Accel-Redirect", file);
instead of
add_header("X-Accel-Redirect: " + file);
### URL Remapping
To bind urls to a method, you now include:
#include <cppcms/url_dispatcher.h>
#include <cppcms/url_mapper.h>
and then you can use:
dispatcher().assign("^/?(.*?)/?$",&hello::execute,this,1);
mapper().assign("{1}");
instead of
url.add("^/?(.*?)/?$", boost::bind(&hello::execute, this, _1));
To change the default skin for a specific context in cppcms 1.0 you can now use:
context().skin("my_skin")
instead of the previous application-global setting:
use_template("view");

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