Re: [Cppcms-users] How to add second web page in CppCMS application?
Brought to you by:
artyom-beilis
From: Artyom B. <art...@ya...> - 2011-10-01 14:10:16
|
Take a look on: http://art-blog.no-ip.info/wikipp/en/page/cppcms_1x_config#views If you use more then one skin you need either: 1. To specify skin name explicitly render("myskin","message",content) 2. To specify the default skin in configuration file. Also I'd suggest following: 1. If you have pages that have same base view (like same "theme") then put them into same skin. Use some basic template that defines general appearance of the page and extend it with inheritance to specific purposes. 2. For totally different pages like "administrative interface" and "public interface" use different skins. See: http://art-blog.no-ip.info/wikipp/en/page/cppcms_1x_templates_gen Artyom Beilis -------------- CppCMS - C++ Web Framework: http://cppcms.sf.net/ CppDB - C++ SQL Connectivity: http://cppcms.sf.net/sql/cppdb/ ----- Original Message ----- > From: chenshu <csf...@gm...> > To: cpp...@li... > Cc: > Sent: Saturday, October 1, 2011 3:26 PM > Subject: [Cppcms-users] How to add second web page in CppCMS application? > > Hello, > I have set up one simple web application > here:http://www.cmlelectronics.com:8080/kaimei > It only has one page and works.Now I try to add another new page for > registering new user. > I create register_client.tmpl in src folder,configure my CMakeLists.txt > like so: > > //for my first page > add_custom_command( > OUTPUT ${CMAKE_SOURCE_DIR}/src/my_skin.cpp > COMMAND cppcms_tmpl_cc ${CMAKE_SOURCE_DIR}/src/welcome.tmpl -o > ${CMAKE_SOURCE_DIR}/src/my_skin.cpp > DEPENDS welcome.tmpl > ) > > //for my second page > add_custom_command( > OUTPUT ${CMAKE_SOURCE_DIR}/src/register_client.cpp > COMMAND cppcms_tmpl_cc ${CMAKE_SOURCE_DIR}/src/register_client.tmpl > -o ${CMAKE_SOURCE_DIR}/src/register_client.cpp > DEPENDS register_client.tmpl > ) > > AUX_SOURCE_DIRECTORY(${CMAKE_SOURCE_DIR}/src CPP_LIST) > add_executable(main ${CPP_LIST} my_skin.cpp register_client.cpp) > > The following is my config.js: > > { > "service" : { > "ip":"0.0.0.0", > "api" : "http", > "port" : 8080 > }, > "db" : { > "name" : "fucai", > "ip" : "myip", > "user": "myusr", > "password":"mypwd" > }, > "http" : { > "script_names" : ["/kaimei"] > }, > "uri_config":{ > "base":"http://www.cmlelectronics.com", > "jsonp":"http://localhost:8080" > } > } > > > I defined one class hello: > class hello : public cppcms::application { > public: > hello(cppcms::service &srv); > void save_email(std::string content); > void welcome(std::string url); > void register_client(std::string url); > > private: > content::message c_; > }; > > > > hello::hello(cppcms::service &srv):cppcms::application(srv){ > dispatcher().assign("/welcome" , &hello::welcome , this , 1); > dispatcher().assign("/register" , &hello::register_client , > this , 2); > dispatcher().assign("/save_email?(.+)" , &hello::save_email , > this , 3); > configuration& config = app_singleton_holder::Instance().config(); > c_.base_uri=config.base_uri; > c_.jsonp= config.jsonp; > } > > void hello::welcome(std::string url){ > render("message",c_); > } > > > void hello::register_client(std::string url){ > render("message2",c_); > } > > > > > But always get the following error message when I want to open my pages > via http://localhost:8080/kaimei/welcome or > http://localhost:8080/kaimei/register > > 2011-10-01 12:22:14 GMT; cppcms, error: Caught exception [There is no > such skin:] > 0x7fa68cc3b434: cppcms::cppcms_error::cppcms_error(std::string const&) + > 0x64 in /usr/lib/libcppcms.so.1 > 0x7fa68cc7e907: cppcms::views_pool::render(std::string, std::string, > std::ostream&, cppcms::base_content&) + 0x12e7 in > /usr/lib/libcppcms.so.1 > 0x7fa68cc65875: cppcms::application::render(std::string, > cppcms::base_content&) + 0x85 in /usr/lib/libcppcms.so.1 > 0x40d866: hello::welcome(std::string) + 0x50 in ./main > 0x40ef55: > cppcms::url_dispatcher::binder1<hello>::operator()(std::string) const + > 0x9b in ./main > 0x40ede5: booster::function<void (std::string)>::callable_impl<void, > cppcms::url_dispatcher::binder1<hello> >::call(std::string) + 0x3b in > ./main > 0x7fa68cc6b579: ??? + 0x8cc6b579 in /usr/lib/libcppcms.so.1 > 0x7fa68cc68a6d: cppcms::url_dispatcher::dispatch(std::string) + 0x8d in > /usr/lib/libcppcms.so.1 > 0x7fa68cc30884: cppcms::application::main(std::string) + 0x24 in > /usr/lib/libcppcms.so.1 > 0x7fa68cc5e12e: > cppcms::http::context::dispatch(booster::intrusive_ptr<cppcms::application>, > > std::string, bool) + 0x6e in /usr/lib/libcppcms.so.1 > 0x7fa68cc5ffec: booster::function<void ()>::callable_impl<void, > cppcms_boost::_bi::bind_t<void, void > (*)(booster::intrusive_ptr<cppcms::application>, std::string, bool), > cppcms_boost::_bi::list3<cppcms_boost::_bi::value<booster::intrusive_ptr<cppcms::application> > >> , cppcms_boost::_bi::value<std::string>, > cppcms_boost::_bi::value<bool> > > >::call() + 0x4c in > /usr/lib/libcppcms.so.1 > 0x7fa68cc61112: cppcms::impl::thread_pool::worker() + 0x82 in > /usr/lib/libcppcms.so.1 > 0x7fa68b256d2e: booster_thread_func + 0x1e in /usr/local/lib/libbooster.so.0 > 0x7fa68b696d8c: ??? + 0x8b696d8c in /lib/x86_64-linux-gnu/libpthread.so.0 > 0x7fa68b99404d: clone + 0x6d in /lib/x86_64-linux-gnu/libc.so.6 > (http_context.cpp:150) > > > welcome.tmpl file's content: > > <% c++ #include "content.h" %> > <% skin my_skin %> > <% view message uses content::message %> > <% template render() %> > <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" > "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> > <html xmlns="http://www.w3.org/1999/xhtml"> > <head> > <meta http-equiv="Content-Type" content="text/html; > charset=utf-8" /> > > ... > > > register.tmpl file's content: > > <% c++ #include "content.h" %> > <% skin client %> > <% view message2 uses content::message %> > <% template render() %> > <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" > "http://www.w3.org/TR/html4/loose.dtd"> > <html> > <head> > <script src="http://c > > ...... > > > > > > > > > > ------------------------------------------------------------------------------ > All of the data generated in your IT infrastructure is seriously valuable. > Why? It contains a definitive record of application performance, security > threats, fraudulent activity, and more. Splunk takes this data and makes > sense of it. IT sense. And common sense. > http://p.sf.net/sfu/splunk-d2dcopy2 > _______________________________________________ > Cppcms-users mailing list > Cpp...@li... > https://lists.sourceforge.net/lists/listinfo/cppcms-users > |