Jump to content


makeURL()


1 reply to this topic

#1 Cris D.

    Loves Etomite Forums!

  • Developers
  • PipPipPipPip
  • 1,104 posts
  • Gender:Male

Posted 20 February 2009 - 12:30 PM

This function creates a fully qualified url
ie http://www.mysite.com/index.php for an internal page for an etomite site.

From the miscellaneous API documentation.

Quote

makeUrl($id, $alias=0, $args='')
// Modified by mikef
// returns a properly formatted URL as of 0.6.1 Final
// $id is a valid document id
// $alias is now an unused parameter because it is now calculated based on $id
// $args is a URL compliant text string of $_GET key=value pairs
// Example: makeURL(45,'','?cms=Etomite')

$id can be passed by using $etomite->documentIdentifier, by passing a numeric value for a page id, or by passing an alias for the page by using [~alias~].

$args will accept key=>value pairs to pass in the URL as GET values eg:
$etomite->makeURL(12,'','?param1=one&param2=two');
will result in:

Quote


Things to notice...The $args are prefixed by a "?", now if a "?" already exists (like in the example above), the API is smart enough to work out that another "?" will break the URL, so it adds an amperstand "&" instead.

Another implementation is:
$etomite->makeURL($etomite->documentIdentifier,'','');

This will create a URL to the page where it was generated.

You could also use it like this with the sendRedirect() function:

return $etomite->sendRedirect($etomite->makeURL($etomite->documentIdentifier,'',''),
$count_attempts=3, $type='');

Or with templated variables like this:

$etomite->makeURL([~sitemap~],'','');

or with internal snippet variables like this:

$etomite->makeURL($page,'',"?var1=".$varOne."&var2=".$varTwo);

makeURL also works well with javascript implementations, and is also my perferred method of creating a form action:
 
$output="<form id=\"myform\" 
  action=\"".$etomite->makeURL($etomite->documentIdentifier,'','')."\" 
  method=\"get / post\"  >
<<<SNIP>>>> 
</form>";
This method is much more reliable than form action="" (especially for many localhosts or when the form submits to an error 404 (page not found).

makeURL also handles friendly aliases and FURL (Friendly URLs). That means that if your site is using these options, you can pass a page number or alias and the FURL will be returned.
ie $etomite->makeURL('12','',''); will return
http://yoursite.com/yourpage.html depending on the settings you have chosen to use in your site configuration settings.

Edited by Cris D., 03 March 2009 - 06:09 PM.


#2 PaulD

    Likes Etomite Forums!

  • Developers
  • PipPip
  • 389 posts
  • Gender:Male

Posted 03 March 2009 - 11:22 AM

I have recently started using this layout and find it quite accessible. Easy to cut and paste when needed too.

// Make Url Params
   $urlPageID = $my_page_id;
   $urlParams = '?my_parameter='.$my_variable;

// Make Url
   $url=$etomite->makeURL($urlPageID,'',$urlParams);

Paul.

PS I cut and paste these things all the time, perhaps the snippet editor should have an 'add function template' for eto functions. When I have time I may see if I can do that.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users