Am 04.10.2013 22:49, schrieb Olaf Radicke:

Olaf Radicke <[email protected]> hat am 4. Oktober 2013 um 19:20
geschrieben:



Hi Tommi!

Tommi Mäkitalo <[email protected]> hat am 4. Oktober 2013 um 18:39
geschrieben:
Why not just use constants?

In a include:

      namespace url
      {
           static const char SwitchToHandheldVersion[] =
      "/SwitchToHandheldVersion";
           static const char RSSfeedView[] = "/rss.xml";
           ...
      }

Then in the ecpp:

|     <a href="<$ url::SwitchToHandheldVersion $>">|

If you want to change the url, just change it in the header and
recompile. It is much less overhead and not need for a lookup table.
Yes, that is a very good idea. That is the better way. Thanks for
you feedback.
But now, I see it is the old problem:

<a href="<$ url::RSSfeedView $>">

is effective:

<a href="/rss.xml">

And this is not a absolute URL. was we need is:

<a href="http[s]://[mydomain]:[80]/rss.xml">

If I us <a href="<$ url::RSSfeedView $>"> in a Page with url
/example_dir/example_site.html than switch with this link to
/example_dir/rss.xml but if I stand
/example_dir/example_subdir/example_site.html
than I switch to /example_dir/example_subdir/rss.xml

If I set the domain, protocol ant port fix in the include or in the ecpp
than I get same problem as before.  Hmm....

We can do this...

     namespace url
     {
         static const char protocol[] = "http";
         static const char domain[] = "mydomain.de";
         static const char port[] = "80";
         static const char RSSfeedView[] = "/rss.xml";
         ...
     }


     <a href="<$ url::protocol $>://<$ url::domain $>:<$ url::domain $><$
url::RSSfeedView $>">

Or a little bit better...


     namespace url
     {
         static const char urlPrefix[] = "http://mydomain.de:80";;
         static const char RSSfeedView[] = "/rss.xml";
         ...
     }


     <a href="<$ url::urlPrefix $><$ url::RSSfeedView $>">

But domain, protocol ant port is not hard coded. Is is normally in the config.

Gratings,

Olaf
Please explain, why you really need full paths in your links? If you just change the domain name, the application have to behave differently. If I link to a page in my application, it must always point to the same protocol, same host and same port. There is no need to specify the full path. It even makes it difficult to test your application since you may test the application on a different host than it runs on.

It is even better to use relative paths. The application may run behind a proxy, which adds a subdirectory. But that is another case.

But what I always expect is to have as less C++ code as possible in the view. You may want to change the href to:

   <a href="<$ url::RSSfeedview() $>">

Then you can write a function "RSSfeedview", which does whatever you want. The function can either just return a string or something like:
    std::string RSSfeedview()
    {
        cxxtools::net::Uri uri;  // there is a nice Uri-classin cxxtools
        uri.host("www.somewhere.else");
        uri.protocol("http");
        uri.port(80);
        uri.path("/rss.xml");
        return uri.str();
    }

Tommi
------------------------------------------------------------------------------
October Webinars: Code for Performance
Free Intel webinars can help you accelerate application performance.
Explore tips for MPI, OpenMP, advanced profiling, and more. Get the most from 
the latest Intel processors and coprocessors. See abstracts and register >
http://pubads.g.doubleclick.net/gampad/clk?id=60134791&iu=/4140/ostg.clktrk
_______________________________________________
Tntnet-general mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tntnet-general

Reply via email to