Forum Moderators: coopster

Message Too Old, No Replies

Integrating PHP Calendar to Website

Should be a simple question

         

kriskd

9:28 pm on Sep 3, 2005 (gmt 0)

10+ Year Member



Hi again.

First thanks for helping me with my PHP/SSI question from an earlier thread. Allow me to throw another question at the group which should be real simple.

I have my PHP calendar script that I uploaded to the server and viewing the calendar directly, it works great. The calendar is located at:

mydomain.com/calendar/index.php

I want to integrate this on my website, so I added this line to where I want it to appear on the appropriate page:

<?php require("calendar/index.php");?>

It displays great. Trouble is, the css file and advancing to the next month are not working, because the relative links aren't pointing to the calendar folder, but instead are pointing to the root of mydomain.com.

How do I get the links to point to the calendar folder?

nickdgd

9:58 am on Sep 4, 2005 (gmt 0)

10+ Year Member



Suppose your website's page is /index.php
your calendar's page is /calendar/index.php

In file /index.php, above the line of requiring the calendar, add another line:

define("IN_WEB", 1);

Then in the head of /calendar/index.php, add such lines:

if (defined("IN_WEB")) define("PATH_CALENDAR", "calendar/");
else define("PATH_CALENDAR", "./");

And then prefix the constant PATH_CALENDAR to all your links including css files on the page /index.php

kriskd

12:22 pm on Sep 4, 2005 (gmt 0)

10+ Year Member



Nick,

Thanks for your help.

That all makes sense to me except the "prefix the constant" part. In the example of the css file, I did this which just doesn't "feel" right (and it didn't work!):

<link href="PATH_CALENDAR/images/cal.css" rel="stylesheet" type="text/css">

I'm sure I'm missing something real basic here.

nickdgd

1:06 pm on Sep 4, 2005 (gmt 0)

10+ Year Member



It should be like this:

<link href="<?php echo PATH_CALENDAR;?>/images/cal.css" rel="stylesheet" type="text/css">

In this case it seems that the codes becomes ugly, but if you use templates such as the Template class in PHPLIB or Smarty, the codes will be very nice.

kriskd

4:13 pm on Sep 4, 2005 (gmt 0)

10+ Year Member



The CSS sheet now links properly, but I am unable to get regular links to work. I realize this message forum is not a place to get other people to write your code and one way or another, I really need to learn this stuff. So, if someone can point me to a good tutorial, that would be appreciated as well.

Here's one of my links that I need to set the constant in.

<a href="<? echo "index.php?month=$prev_month&amp;year=$prev_year";?>"

This calendar is a small program, but there are several places where I would need to do this making the template option appealing. However, I am lost on where to start with that as well. Again, a recommendation to a good tutorital would be appreciated.

Thank you for your patience with me.

nickdgd

5:34 am on Sep 5, 2005 (gmt 0)

10+ Year Member



It should be

<a href="<? echo PATH_CALENDAR . "index.php?month=$prev_month&amp;year=$prev_year";?>">

since the dot "." is an operator that joins strings together.
PATH_CALENDAR is a constant, which is similar to a variable except that its value can't be changed in the whole page once it's defined.

PHP Manual is a good tutorial. Details about constants and variables are described in the Language Reference part.

You will find everything about how to use PHP in PHP Manual, but if you want to ask how to use PHP well, I'd like to say Practice Makes Perfect. Additionally, learning new technologies and nice methods on the Web to solve problems more efficiently and communicating with others are indispensable.