Jump to content

Including TPL files


CedGauche

Recommended Posts

Hi,

I want to include some sub tpl files, these tpl files are in the same directory as the index file (poker.tpl):

post-45014-0-60662600-1452933949_thumb.jpg

This is the module:

post-45014-0-71393000-1452934046_thumb.jpg

When I start the game it works fine, but when the game wants to start it's included tpl, I get an error:

post-45014-0-25157600-1452934212_thumb.jpg

This is the code inside the poker.tpl for the include:

session_start();

include "card_results.tpl";

$_SESSION['counter'] = 1;

?>

<head>

<title>Poker</title>

</head>

<div id="outcome" style="color:red"><?= $msg ?></div>

<form name="form1" id="form1" method="post" action="card_results.tpl">

I am working on this for hours now..thx for help

Link to comment
Share on other sites

  • Moderators

Basically what you are trying to do will not give any result. You have already created an index function in your module. For the results page, you will have to create a second function and include the tpl file in the function. After that, the action of the form should be something like this:

action="<?php echo SITE_URL; ?>/index.php/spiel4/results"

Link to comment
Share on other sites

Okay, this is my module now:

class spiel4 extends CodonModule

{

public function index()

{

Template::Show('/spiel4/poker.tpl');

}

public function pageone()

{

Template::Show('/spiel4/card_results.tpl');

}

public function pagetwo()

{

Template::Show('/spiel4/card_new_game.tpl');

}

}

And this is the function:

session_start();

include "card_results.tpl";

$_SESSION['counter'] = 1;

?>

<head>

<title>5 card</title>

</head>

<div id="outcome" style="color:red"><?= $msg ?></div>

<form name="form1" id="form1" method="post" action="<?php echo SITE_URL; ?>/index.php/spiel4/card_results.tpl">

But the error is the same again:

Warning: call_user_func_array() expects parameter 1 to be a valid callback, class 'spiel4' does not have a method 'card_results.tpl' in /var/www/web1112/html/va/core/classes/MainController.class.php on line 218

Sorry for my questions, this is complete new for me and I am not an native english speaker

Link to comment
Share on other sites

Try removing the / from Template::show('/');

class spiel4 extends CodonModule
{
public function index()
{
Template::Show('spiel4/poker.tpl');
}
public function pageone()
{
Template::Show('spiel4/card_results.tpl');
}
public function pagetwo()
{
Template::Show('spiel4/card_new_game.tpl');
}
}

--> Just realised,try changing your form action to this in your case <?php echo SITE_URL; ?>/index.php/spiel4/page_one">

Link to comment
Share on other sites

  • Moderators

Basically, I do not know why do you place the following in your template files:

session_start();
include "card_results.tpl";
$_SESSION['counter'] = 1;
?>

What are you willing to do with them? Bare in mind that you have forgotten to add the open php tag in the very beginning:

<?php

Link to comment
Share on other sites

Try removing the / from Template::show('/');

class spiel4 extends CodonModule
{
public function index()
{
Template::Show('spiel4/poker.tpl');
}
public function pageone()
{
Template::Show('spiel4/card_results.tpl');
}
public function pagetwo()
{
Template::Show('spiel4/card_new_game.tpl');
}
}

--> Just realised,try changing your form action to this in your case <?php echo SITE_URL; ?>/index.php/spiel4/page_one">

Ok thx, that worked for me...but I think it's to complex to add external scripts or modules to phpvms.

Now the error is:

Fatal error: Cannot redeclare checkWinner() (previously declared in /var/www/web1112/html/va/core/templates/spiel4/card_results.tpl:59) in/var/www/web1112/html/va/core/templates/spiel4/card_results.tpl on line 95

The code from card_results.tpl:

session_start();

<?php

/* Poker Ranks

1 = Royal Straight Flush

2 = Straight Flush

3 = 4 Of A Kind

4 = Full House

5 = Flush

6 = Straight

7 = 3 Of A Kind

8 = 2 Pair

9 = 1 Pair

10 = High Card

*/

/*

displayCards() Results:

1 = Win

2 = Loss

3 = Tie

*/

if(isset($_POST['swap']) && $_SESSION['state'] == 1)

{

checkWinner();

}

elseif(isset($_POST['new_game']))

{

session_destroy();

session_start();

include "poker.tpl";

}

elseif(isset($_POST['stay']))

{

checkWinner();

}

else

{

include "card_new_game.tpl";

}

function checkWinner()

{

$_SESSION['state'] = 0;

for($x=1; $x<6; $x++)

{

if(isset($_POST['chk_' . $x]))

{

$_SESSION['counter']++;

$temp = explode('-', $_SESSION['deck'][9 + $_SESSION['counter']]);

$_SESSION['player_cards'][$x-1] = $temp[0];

$_SESSION['player_suits'][$x-1] = $temp[1];

}

}

if(pokerRank($_SESSION['player_cards'], $_SESSION['player_suits']) > pokerRank($_SESSION['dealer_cards'], $_SESSION['dealer_suits']))

{

displayCards('1');

}

elseif(pokerRank($_SESSION['player_cards'], $_SESSION['player_suits']) == pokerRank($_SESSION['dealer_cards'], $_SESSION['dealer_suits']))

{

if(highestCard($_SESSION['player_cards']) > highestCard($_SESSION['dealer_cards']))

{

displayCards('1');

}

elseif(highestCard($_SESSION['player_cards']) == highestCard($_SESSION['dealer_cards']))

{

displayCards('3');

}

else

{

displayCards('2');

}

}

else

{

displayCards('2');

}

}

function displayCards($result)

{

switch($result)

{

case 1:

$msg = "You have won...";

break;

case 2:

$msg = "You have lost...";

break;

case 3:

$msg = "A tie somehow...";

break;

}

include "poker.tpl";

}

function highestCard($cards)

{

sort($cards);

return $cards[0];

}

function pokerRank($cards, $suits)

{

//reassign some cards if needed by number to make it easier to check for straights.

for($x=0; $x<count($cards); $x++)

{

switch ($cards[$x])

{

case "j":

$cards[$x] = 11;

break;

case "q":

$cards[$x] = 12;

break;

case "k":

$cards[$x] = 13;

break;

case "a":

$cards[$x] = 14;

break;

}

}

sort($cards);

//check for one pair

if ($cards[0] == $cards[1] || $cards[1] == $cards[2] || $cards[2] == $cards[3] || $cards[3] == $cards[4])

$pokerRank = 9;

//check for two pair

if( ($cards[0] == $cards[1] && $cards[2] == $cards[3]) ||

($cards[0] == $cards[1] && $cards[3] == $cards[4]) ||

($cards[1] == $cards[2] && $cards[3] == $cards[4]))

$pokerRank = 8;

//check for 3 of a kind.

if( ($cards[0] == $cards[1] && $cards[1] == $cards[2]) ||

($cards[1] == $cards[2] && $cards[2] == $cards[3]) ||

($cards[2] == $cards[3] && $cards[3] == $cards[4]))

$pokerRank = 7;

//check for straight

if( ( $cards[0]+1 == $cards[1] && $cards[1]+1 == $cards[2] && $cards[2]+1 == $cards[3] && $cards[3]+1 == $cards[4]) ||

($cards[4] == "14" && $cards[0] == "2" && $cards[1] == "3" && $cards[2] == "4" && $cards[3] == "5") )

$pokerRank = 6;

//check for flush

if($suits[0] == $suits[1] && $suits[0] == $suits[1] && $suits[0] == $suits[2] && $suits[0] == $suits[3] & $suits[0] == $suits[4])

{

//check for royal straight flush

if($pokerRank == 6 && $cards[4] == 14)

{

$pokerRank = 1;

}

//check for a straight flush

elseif($pokerRank == 6)

{

$pokerRank = 2;

}

else

{

$pokerRank = 5;

}

}

//check for full house

if( ($cards[0] == $cards[1] && $cards[0] == $cards[2] && $cards[3] == $cards[4]) ||

($cards[0] == $cards[1] && $cards[2] == $cards[3] && $cards[3] == $cards[4]) )

$pokerRank = 4;

//check for four of a kind

if( ( $cards[0] == $cards[1] && $cards[1] == $cards[2] && $cards[2] = $cards[3]) ||

($cards[1] == $cards[2] && $cards[2] == $cards[3] && $cards[3] == $cards[4]) )

$pokerRank = 3;

return $pokerRank;

}

?>

Link to comment
Share on other sites

  • Moderators

You're using multiple functions in your .tpl I think that's where the problem is. The tpl is normally where you show results in a table or div what you have in there should all be inside your module file (yourfile.php in your module folder) then in your tpl in an HTML tag you show what you want by calling the functions. Your case should be calling the functions in your browser's address bar like the following:

http://www.yourairline.com/index.php/yourmodule/yourfunction

Note that "yourfunction" is the one you use to show your results.tpl

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...