Change page based on $iPageIndex variable
QuoteFeb 02, 2012 22:580 likesLike
 

I have a module that has page_500.html template as the default home or main page.  I created page_501.html.

I would like to make it such that if a member is logged in (not a guest), it shows page_501.html (instead of 500).

Within the Bx<module>Template.php class file of the module, the following is set:

var $_iPageIndex = 500

Unfortunately, I tried but cannot use the if(isLogged()) function to change the var.

So I found in /inc/classes/BxDolTemplate.php where $iPageIndex is considered.  I added

if($iPageIndex == 500){

check_logged();

if(isLogged()){

$iPageIndex = 501;

}

}

However, that does not work.  No matter what, it is showing page 500.

Anyone know how to make is show a different default page?

QuoteFeb 02, 2012 23:490 likesLike
 

i can't understand what are you trying but try isMember() instead

if($iPageIndex == 500){

check_logged();

if(isMember()){

$iPageIndex = 501;

}

}

This is forum signature. Not your answer...:)
QuoteFeb 03, 2012 06:320 likesLike
 

 

i can't understand what are you trying but try isMember() instead

if($iPageIndex == 500){

check_logged();

if(isMember()){

$iPageIndex = 501;

}

}

 I tried that...still no success.  To ensure the If-statement works, I echo the $iPageIndex and I see that it works perfectly depending on if it is a member or not.

The problem is that it is still showing page_500.html even if the page index is 501 (in other words, it's not showing page_501.html at all).

Anyone know how to show a different page depending on if one is a member or not?

QuoteFeb 03, 2012 08:110 likesLike
 

i don't know what are you trying to accomplish but you can redirect you visitors to a different page.

This is forum signature. Not your answer...:)
QuoteFeb 03, 2012 08:250 likesLike
 

This should be done within the modules template class. The very first thing you were trying to do should be the proper way. You have only posted 1 line from the modules template class.

var $_iPageIndex = 500

I would need to see more of that code above and below that line to figure out a solution.

The only reason it would not work is if the page index is getting changed back further in code, or if page 501 is the same as page 500.

This should easily be able to be done.

Dolphin Mods - http://www.boonex.com/market/posts/deano92964
QuoteFeb 03, 2012 08:290 likesLike
 

There is also a debugging process you should use. You should edit page 500 to add something to it just to verify that page is actually being used for display rather than the default template.

501 should be edited to. Something added like <div>Hey! i am page 500</div> to uniquely identify the page.

Dolphin Mods - http://www.boonex.com/market/posts/deano92964
QuoteFeb 03, 2012 17:340 likesLike
 

 

This should be done within the modules template class. The very first thing you were trying to do should be the proper way. You have only posted 1 line from the modules template class.

var $_iPageIndex = 500

I would need to see more of that code above and below that line to figure out a solution.

Attached is the original BxTravelerTemplate.php file, however I have quoted the pertinent below in blue where I have made my mods in red text.

class BxTravelerTemplate extends BxDolTwigTemplate {

check_logged();

if (isLogged(){

var $_iPageIndex = 500;

}else{

var $_iPageIndex = 501;

}

var $oDb;

function BxTravelerTemplate(&$oConfig, &$oDb) {

...

}

Please note that when I place the if-then-else statement for the "var" statement (see above in red), I get the following error message.  This happens whether I have isLogged or isMember.

Parse error: syntax error, unexpected T_STRING, expecting T_FUNCTION in /home/user/public_html/modules/modder/traveler/classes/BxTravelerTemplate.php on line 32

It's as though it won't accept any "if" statements between the "class" and "function" statements.  So I removed the mod, and I instead went to /inc/classes/BxDolTemplate.php where $iPageIndex is considered. and I added the following below "function processInjection".

function processInjection($iPageIndex, $sKey, $sValue = "") {

if($iPageIndex == 500){

check_logged();

if(!isLogged()){

$iPageIndex = 501; }

}

if($iPageIndex != 0 && ...

Still no success! This time, although I echo the $iPageIndex and verify that it is 500 or 501 depending on when I am logged in or not, it still shows the default 500 page!

The only reason it would not work is if the page index is getting changed back further in code, or if page 501 is the same as page 500.

This should easily be able to be done.

 Yes, somehow the page index is getting changed or something. No, page 500 is not the same as 501 page...guaranteed.

Please help if you can.

BxTravelerTemplate (orig).php • 22.5K • 2 downloads

QuoteFeb 03, 2012 17:350 likesLike
 

 

There is also a debugging process you should use. You should edit page 500 to add something to it just to verify that page is actually being used for display rather than the default template.

501 should be edited to. Something added like <div>Hey! i am page 500</div> to uniquely identify the page.

 Yes...I've done all of that.  No success.

QuoteFeb 03, 2012 18:070 likesLike
 

Two things.
1. check_logged is a function specific to admin. If you must use it, you need to add the resource for it in your file.
2. isLogged() function that you are using to check the condition is not a static function and requires that you instantiate the BxDolModule if you are to use it.

If it's just a matter of checking is someone is logged in or not, try this:

$iMemID = (int)$_COOKIE['memberID']; //this gets the memberid

//now test it
if($iMemID > 0) {

        echo "hello member!";
   
    }else{
   
        echo "Y U no sign up to be a member?";

}

I hope it helps.

...sip...
QuoteFeb 03, 2012 18:300 likesLike
 

jtadeo is correct about the use of those functions.

However i noticed you were missing a ) on your if statement. So that may explain your systax error.


Also the var $_iPageIndex was already assigned a value, so the easiest thing to do is change the value if a certain condition is met. So try this instead.

class BxTravelerTemplate extends BxDolTwigTemplate {

var $_iPageIndex = 500;
var $oDb;

$iMemID = (int)$_COOKIE['memberID']; //this gets the memberid
if($iMemID == 0) $_iPageIndex = 501;

function BxTravelerTemplate(&$oConfig, &$oDb) {

...

}


But this may not work. The var $_iPageIndex is being assigned as a global within the class. So it must be referenced somewhere else in this same file. Most likey as $this -> _iPageIndex

That is where the reassignment should take place. Look through the rest of this file for the use of _iPageIndex

Dolphin Mods - http://www.boonex.com/market/posts/deano92964