|
 Tom Loveric - 2008-09-17 00:48:17
When I try to generate a URL, ex(in .htaccess):
RewriteRule (.+?)/(.+?) ?page=$1&id=$2
and the example.php part to go with it:
echo '<a href="'.$c_relink->replaceLink('?page=tools&id=1').'">Tool #1</a> | '; # page: tools | id: 1
But it doesn't set the $_GET['id'] variable, which causes this error(with ERROR_REPORTING() set to E_ALL):
Notice: Undefined index: id in .../index.php on line 20
 Benjamin Falk - 2008-09-17 18:36:15 - In reply to message 1 from Tom Loveric
It seems, that this error doesn't come from reLink.
Can you show me more of your code?
Here is what I tested:
example2.php
------
<?php
error_reporting(E_ALL);
require_once 'class.relink.php';
$htaccessFile = './htaccess-example2';
$c_relink = new RELINK($htaccessFile);
echo '<a href="'.$c_relink->replaceLink('?page=tools&id=1').'">Tool #1</a> | '; # page: tools | id: 1
?>
------
and htaccess-example2
------
#SET LINK AUTO ON
RewriteEngine on
RewriteRule (.+?)/(.+?) ?page=$1&id=$2
------
 Tom Loveric - 2008-09-17 19:44:16 - In reply to message 2 from Benjamin Falk
It's just checking if the variable exists, and if it does - it loads the corresponding file from the tools, tools_view_$_GET['id'].tpl, from my template system that I did myself. Also, did you get a good result from what you tested?
 Benjamin Falk - 2008-09-17 20:29:44 - In reply to message 3 from Tom Loveric
Yes, it worked without any problems.
In your error stands your index.php, so I don't think it's from reLink.
Anyway, maybe I can help you better, if you give me some more code.
greetings :)
 Tom Loveric - 2008-09-17 21:45:06 - In reply to message 4 from Benjamin Falk
I'll have to try the code you supplied and get back to ya with more source of index.php if it doesn't work. Thanks for the help, mate.
 Tom Loveric - 2008-09-17 21:53:17 - In reply to message 5 from Tom Loveric
I tried the code you supplied and I am still getting the same error regarding the $_GET['id'] variable.
-- index.php: --
<?php
ERROR_REPORTING(E_ALL);
require_once("class_template.php");
$template = new Template;
$welcomeText = "to the new & improved <b>Elite-Area</b> website! For now, the site's pretty blank - but that will change very soon once we start uploading more of the content and updating the things that we use - for example, MyBB. Also, we plan to eventually incorperate a brand new theme for the whole site, including the forums - which will probably be the theme you see now:) But for now, enjoy the content we have!";
$servicesText = "Below is a list of services that we currently offer. Feel free to check them out and try some of them.";
$servicesText .= "<ul>";
$servicesText .= "<li><a href=hosting/>Hosting</a></li>";
$servicesText .= "<li><a href=leagues/>League Hosting</a></li>";
$servicesText .= "</ul>";
$template->tags = array
(
"{welcomeText}" => $welcomeText,
"{servicesText}" => $servicesText
);
$template->display("header.tpl");
if( isset($_GET['page']) && $_GET['page'] == "blog" )
{
if( $_GET['mode'] == "edit" )
{
$template->display("blog_edit.tpl");
}
else
{
$template->display("blog_index.tpl");
}
}
elseif( $_GET['page'] == "tools" )
{
$template->display("tools_view_{$_GET['id']}.tpl");
}
else
{
$template->display("index_body.tpl");
}
$template->display("footer.tpl");
?>
-- index.php --
The $template variables and the display() function are for my custom templating system - which in no way should mess with the $_GET['id'] variable, or any $_GET variables for that matter.
 Benjamin Falk - 2008-09-18 06:07:12 - In reply to message 6 from Tom Loveric
Hi,
your problem realy has nothing to do with the reLink class.
It's because of the not existing id-part of $_GET.
For example:
You go onto ?page=test
Where is the id? So $_GET['id'] is undefined and that causes your error.
You can fix that by using the following:
----
$id = 0;
if (isset($_GET['id']) $id = intval($_GET['id']);
//And now you have to use $id instead of $_GET['id']
----
For more help you can also go to www.phpfreaks.com/forums
 Tom Loveric - 2008-09-18 19:26:12 - In reply to message 7 from Benjamin Falk
That's a great fix, somewhat. That will only set it to one if it's not set - which it should be because I have the relink class link as
?page=tools&id=1
which takes me to
tools/1/
like I want it to, but it's not setting the ID to whatever's after the tools/
 Benjamin Falk - 2008-09-18 19:41:00 - In reply to message 8 from Tom Loveric
Hm... maybe you should try the following:
Try it without that many variables... just raw as
$c_relink->replaceLink('?page=tools&id=1');
And try to give me more code. I can't help you without ;)
 Tom Loveric - 2008-09-18 20:05:30 - In reply to message 9 from Benjamin Falk
That's what I have currently with nothing else in my 3rd example.php file(example-3.php), and it's not a problem with my end - but with the relink class. It's not setting the &id variable. I tried your solution, which fixes the error - but now it loads tools_view_0.tpl, which indicates that $_GET['id'] inside of the $id variable's not being set properly, which WOULD only be set by the relink class.
|