Re: symlink

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon, September 18, 2006 4:53 pm, Ross wrote:
> Can someone explain how and why you would use a symlink in php?

A symlink is the Un*x version of a Windows "shortcut" or the Mac's
"alias"

The difference being that a symlink actually *works* and a Windows
"shortcut" is useless for anything except their crappy desktop app...

As far as usefulness goes, it's pretty wide-open, and not at all tied
into PHP, per se, in a general sense...

I mean, any time you've got some long complicated
/path/to/somewhere/deep/in/your/system and you want to get there with
out typing all that you can do:
ln -s /path/to/somewhere/deep/in/your/system short
Now you can just use 'short' instead of all that other stuff.
[Assuming you start in the same dir where 'short' lives.]

There is *ONE* thing I've been doing that's very PHP specific that I
think is useful for a symlink...


cd public_html
ln -s . edit


Now, in the PHP code, I do like this:

<?php
  //Force administrators to authenticate
  if (strstr($PHP_SELF, '/edit/')) require 'authenticate';

  if (stristr($PHP_SELF, '/edit/') && isset($_POST['whatever'])){
    //do queries to update the content
  }

  //get the content:
  $query = "SELECT ... ";

  //Display content:
  if (strstr($PHP_SELF, '/edit/')) ?><form method="POST"><?php
  ...
  if (strstr($PHP_SELF, '/edit/')){
    ?>
       <input name="whatever" value="<?php echo $whatever?>" />
    <?php
  }
  else echo $whatever;
?>

What's the point, you ask?

Well, *NOW* instead of having an ugly non-intuitive layout for the CMS
for the site owner, they see the SAME layout, with everyting in the
SAME place, except they have INPUT boxes instead of just text.

This makes it MUCH more intuitive for them to edit their site, as they
just surf to /edit/ and then navigate to what they want to edit, the
same as it is on their site.

The whole thing looks exactly the same, except that they have bits
they can edit, that everybody else just sees as text.

I don't have duplicate code for layout for the site and the edit site,
so I've got very high code re-use, and don't have to make parallel
changes.

Combine this with some nice CSS and a clean layout, and it gets very
very nice.

It drastically cuts down (like, to zero) the confusion over how to
change what in the site -- and they never have to contact me to ask
how to change this or that, or what this little bit here over in
"admin" actually does.  They *see* what it does, because they see it
just like it is in their public site.

-- 
Like Music?
http://l-i-e.com/artists.htm

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux