Main  /  Edit  /  History  /   /  Users Area

Migrating to CppCMS 1.x.x.

Introduction

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 migrate?

Many reasons:

How to migrate?

Main program

The main program changed completely. It is best to rewrite it according the first Tutorial.

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

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");

How to build CppCMS 1.x.x | Top | CppCMS 1.x.x Build Troubleshooting

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