Fatal error: Invalid template - php

i am new to PHP and it seems i ran into some deathcode.
Error given:
( ! ) Fatal error: Invalid template: FPage in /home/jharvard/vhosts/localhost/includes/functions.php on line 218
Call Stack
# Time Memory Function Location
1 0.0001 124636 {main}( ) ../buy.php:0
2 1.3034 144340 render( ) ../buy.php:6
3 1.3035 144476 trigger_error ( ) ../functions.php:218
This is as soon as i POST to my form at Buy.php
<?php
require("../includes/config.php");
if ($_SERVER["REQUEST_METHOD"] == "POST"){
$symbol = $_POST["symbol"];
$price = lookup($symbol)["price"];
render("FPage", ["price" => $price]);
}
else{render("BuyPage.php");}
?>
BuyPage and FPage are respectively:
<form action="buy.php" method='post'><input name="symbol"><input name="SAmount"><input type="submit"></form>
and
<?php
echo $price;
?>
And functions.php(If need be) is at http://pastebin.com/Kd9Zg32S
What i was going for:
Pretty much a simple program to "buy" fake stocks for a programming challange. Lookup pretty much looks up a stock's symbol on yahoo finance and returns a list.
Render pretty much renders the template along with header and footer as well as extracting and inputting any variables passed in.
However about half way around the place i get struck here with a "hairball" of bugs, and this one i just cant seem to pass by.
Debugging help is highly appreciated.
Ps: Config is just a file that checks if the user is logged in, loading in functions e.t.c e.t.c, i brought in all the code that i thought was needed, if more is needed please notify me.

...
render("FPage", ["price" => $price]);
}
else{render("BuyPage.php");}
...
You render "FPage" and "BuyPage.php"
"BuyPage.php" works but FPage does not.
Try replacing "FPage" by "FPage.php".

Related

The $MetaTags(false) variable breaks the page (SilverStripe 3.7.1)

(First of all I'm still trying to figure my way around in SilverStripe so please be gentle)
I'm having a problem with one of the pages on a site where the error is:
[User Error] Uncaught Error: Call to a member function RelativeLink() on null
This is happening in Line 522 in SiteTree.php which has not been altered in any way.
516 if($this->ParentID && self::config()->nested_urls) {
517 $parent = $this->Parent();
518 // If page is removed select parent from version history (for archive page view)
519 if((!$parent || !$parent->exists()) && $this->IsDeletedFromStage) {
520 $parent = Versioned::get_latest_version('SiteTree', $this->ParentID);
521 }
522 $base = $parent->RelativeLink($this->URLSegment);
523 } elseif(!$action && $this->URLSegment == RootURLController::get_homepage_link()) {
524 // Unset base for root-level homepages.
525 // Note: Homepages with action parameters (or $action === true)
526 // need to retain their URLSegment.
527 $base = null;
528 }
After looking at the stack-trace I figured I would look in the Head.ss file and tried to comment out things in order to narrow down my search. So I found out that if I remove the $MetaTags(false) variable in Head.ss everything is working fine.
Trace:
SiteTree->RelativeLink()
SiteTree.php:468
SiteTree->Link()
SiteTree.php:484
SiteTree->AbsoluteLink()
Translatable.php:1583
Translatable->MetaTags(http://silverstripe.org" /> ,,,,,,)
Object.php:1068
SS_Object->extend(MetaTags,http://silverstripe.org" /> )
SiteTree.php:1429
SiteTree->MetaTags(false)
Object.php:746
SS_Object->__call(metatags,Array)
ViewableData.php:466
ViewableData->obj(MetaTags,Array,,1)
ViewableData.php:539
ViewableData->XML_val(MetaTags,Array,1)
SSViewer.php:187
SSViewer_Scope->__call(XML_val,Array)
SSViewer.php:650
SSViewer_DataPresenter->__call(XML_val,Array)
.cache.themes.express.templates.Includes.Head.ss:23
include(/var/www/jackon.no/silverstripe-cache/www-data-php7.0.30-0ubuntu0.16.04.1/.cache.themes.express.templates.Includes.Head.ss)
SSViewer.php:1172
SSViewer->includeGeneratedTemplate(/var/www/jackon.no/silverstripe-cache/www-data-php7.0.30-0ubuntu0.16.04.1/.cache.themes.express.templates.Includes.Head.ss,Product_Controller,Array,Array,SSViewer_DataPresenter)
SSViewer.php:1234
SSViewer->process(Product_Controller,Array,SSViewer_DataPresenter)
SSViewer.php:1273
SSViewer::execute_template(Head,Product_Controller,Array,SSViewer_DataPresenter)
.cache.themes.express.templates.Page.ss:2
include(/var/www/jackon.no/silverstripe-cache/www-data-php7.0.30-0ubuntu0.16.04.1/.cache.themes.express.templates.Page.ss)
SSViewer.php:1172
SSViewer->includeGeneratedTemplate(/var/www/jackon.no/silverstripe-cache/www-data-php7.0.30-0ubuntu0.16.04.1/.cache.themes.express.templates.Page.ss,Product_Controller,,Array,)
SSViewer.php:1234
SSViewer->process(Product_Controller)
Controller.php:201
Controller->handleAction(SS_HTTPRequest,index)
RequestHandler.php:208
RequestHandler->handleRequest(SS_HTTPRequest,DataModel)
Controller.php:151
Controller->handleRequest(SS_HTTPRequest,DataModel)
ContentController.php:174
ContentController->handleRequest(SS_HTTPRequest,DataModel)
ContentController.php:154
ContentController->handleRequest(SS_HTTPRequest,DataModel)
ContentController.php:154
ContentController->handleRequest(SS_HTTPRequest,DataModel)
ModelAsController.php:75
ModelAsController->handleRequest(SS_HTTPRequest,DataModel)
Director.php:385
Director::handleRequest(SS_HTTPRequest,Session,DataModel)
Director.php:149
Director::direct(/bygg/jackon-thermomur/thermomur-350-super/,DataModel)
main.php:194
There is only one page out of many not working and when I try to see what the $MetaTags(false) outputs on one of the working pages it is three <link rel="alternate" ...> tags giving a link to the same page in three different languages.
I would love to get some help on how I can locate and fix the problem. I can't really understand how line 522 could go wrong with the if-conditional in line 519.
The page does have a parent and looks exactly the same as a page with the same parent except for changes in the content like text.

Undefined variable when calling an id from api

I'm working on a PHP project the teacher gave us, basically we have to make a website dynamic and create a liste.php with tasks stored in an API the teacher has.
So I have the index.php with the front page on it and the list of all the projects going on ( like trip preparation, shopping list and appartment decoration ). I created a liste.php with all the tasks contained in each project ( buying tickets, booking the hotel and buying a postcard for the trip preparation ).
Now I have to get all the tasks of each project from the API he gave us.
Here's the API
http://todo_api.xx.firstname-lastname.com/tache.php?liste_id=1
That's the API for project n°1, there are 3 projects in total ( I mentionned them all above )
I also have a functions.php with the $api_url stored, and 2 functions, one getting the list of projects, the other getting the tasks for each project.
$api_url = "http://todo_api.xx.firstname-lastname.com/";
function getAllListes(): array {
global $api_url;
$json = file_get_contents($api_url . "liste.php");
return json_decode($json, true);
}
function getAllTaches(): array {
global $api_url;
$json = file_get_contents($api_url . "tache.php?liste_id=" . $id);
return json_decode($json, true);
}
But when I try to print_r that, or even just display each task, I get this :
Notice: Undefined index: liste_id in /Applications/MAMP/htdocs/todo/database/functions.php on line 17
So obviously something is wrong, and this keeps me from going on. Any idea ?
Edit : here's my html/php code regarding the tasklist
$listes = getAllListes();
$taches = getAllTaches($id);
<ul>
<?php foreach ($taches as $tache) : ?>
<li><?php echo $tache["libelle"] ;?></li>
<?php endforeach ; ?>
</ul>
libelle is the index of the information required.
Thanks a lot !
Your code in functions.php
function getAllTaches(): array { //declared function without parameter
but html/php code
$taches = getAllTaches($id);// calling the function with parameter.
i guess if you pass the parameter to the function it will work.

PHP Twig Error: Object of class __TwigTemplate_XYZ could not be converted to string

Hey and good morning :).
I'll start with the error message and explain afterwards what I've tried and did:
Catchable fatal error: Object of class __TwigTemplate_[64chars] could not be converted to string in /someFolder/lib/Twig/Loader/Filesystem.php on line 139
The full error message as Image:
The PHP Error Message
The call stack as Text:
Call Stack
# Time Memory Function Location
1 0.0001 123400 {main}( ) ../handleOOP.php:0
2 0.0107 1269656 OOPHandler::runPage( ) ../handleOOP.php:7
3 0.0107 1269768 AnweisungEingeben->stepkontrolle( ) ../OOPHandler.php:62
4 0.0108 1271536 AnweisungEingeben->ausgabe( ) ../AnweisungEingeben.php:77
5 0.0383 1669484 Twig_Environment->render( ) ../AnweisungEingeben.php:442
6 0.0383 1669484 Twig_Environment->loadTemplate( ) ../Environment.php:347
7 0.0383 1669512 Twig_Environment->getTemplateClass( ) ../Environment.php:378
8 0.0384 1669512 Twig_Loader_Filesystem->getCacheKey( ) ../Environment.php:312
In the AnweisungEingeben.php I have the following code fragment:
include_once "../lib/Twig/Autoloader.php";
Twig_Autoloader::register();
$template_dirs = array(
$root.'templates/web/anweisungen',
[...]
);
$twig_loader = new Twig_Loader_Filesystem($template_dirs);
$twig = new Twig_Environment($twig_loader, array("debug" => true));
$template = $twig->loadTemplate('Anweisung_Base.phtml');
$wech = $twig->render($template); // line 442 from AnweisungEingeben.php
I already tried:
If the paths are correct (via scandir("path"))
If Twig gets loaded
Minimal Code like
$loader = new Twig_Loader_Array(array('index.html' => 'Hello World!'));
$twig = new Twig_Environment($loader);
echo $twig->render('index.html');
Unfortunately everything results in the same.
The strange thing is, that the exact same code is working flawlessly in a minimal project.
I know it's very chaotic, but the project is existing and growing now for about ~20 years and this twig approach is my try to start(!) separating the logic from the html code.
You're mixing methods up, you are trying to pass a Twig_Template to the Twig_Environment's render method, while this method actually expect the path to the template as it's first parameter
So either do :
$template = $twig->loadTemplate('Anweisung_Base.phtml');
echo $template->render();
Or
echo $twig->render('Anweisung_Base.phtml');

I need to store contact form data into database i did some piece of code but getting error in IndexController.php

ERROR:
Fatal error: Call to a member function setGuestName() on a non-object in IndexController.php
{main}( ) - index.php
Mage::run( ) - index.php(line:87)
Mage_Core_Model_App->run( ) - Mage.php(line:684)
Mage_Core_Controller_Varien_Front->dispatch( ) - App.php(line:354)
Mage_Core_Controller_Varien_Router_Standard->match( ) - Front.php(line:172)
Mage_Core_Controller_Varien_Action->dispatch( ) - Standard.php(line:250)
Test_Contacts_IndexController->postAction( ) - Action.php(line:418)
My code:
$model = Mage::getModel('contacts/contacts');
$model->setGuestName( trim($post['name']) );
$model->setGuestEmail(trim($post['email']));
$model->setGuestTelephone(trim($post['telephone']));
$model->setGuestComments(trim($post['comment']));
$model->setGuestAttachment(trim($post['attachment']));
$model->save( );
I'm not sure how your framework works, but shouldn't it be
$_POST[''] instead of $POST['']?
Is it possible the permissions are incorrectly set on contacts/contacts? Are you sure contacts/contacts is the right location?
Please confirm your model object loading correctly by using following code:
$model = Mage::getModel('contacts/contacts');
echo get_class($model);
die;
This will print you model class name If it is loading correctly. Otherwise you need to check config xml.
If you want to save contact form data in database. Here it is teh nice extension:
http://www.magentocommerce.com/magento-connect/ultimate-contact-us-page-1.html
Hope this help !!

MediaWiki: Show user name in skin

This should be fairly simple for anyone familiar with MediaWiki, but it's stumping me for me because being me.
I'm working on a skin, and I need to show the currently logged in user's name in a top bar - let's assume in plain text, for simplicity's sake, with changes via CSS.
Initially, I was planning on using the automatically generated one used in the personal tools bar, but since the generating line in the skin is
<?php $this->renderNavigation( 'PERSONAL' ); ?>
, it's inseparable from there. I looked in User.php and found its generation line:
public function getUserPage() {
return Title::makeTitle( NS_USER, $this->getName() );
}
So, I figure I might be able to use this function somehow, but I have very little knowledge of PHP, and am unsure how.
EDIT: It appears that this is used for the generation in the personal tools line itself, but again, I'm not sure how to adapt this.
$personal_urls['userpage'] = array(
'text' => $this->username,
'href' => &$this->userpageUrlDetails['href'],
'class' => $this->userpageUrlDetails['exists'] ? false : 'new',
'active' => ( $this->userpageUrlDetails['href'] == $pageurl )
);
Could I duplicate this into a separate function, and make something like the following?
<?php $this->renderNavigation( 'USERNAME' ); ?>
You can use this code:
<?php echo htmlspecialchars($this->getSkin()->getUser()->getName()); ?>
Or, as the User class has a __ToString() magic method:
<?php echo htmlspecialchars($this->getSkin()->getUser()); ?>
Sources :
The SkinTemplate class in MediaWiki code documentation
The User class in the same documentation
CurrentUsers
http://www.mediawiki.org/wiki/Extension:CurrentUsers
GetUserName
http://www.mediawiki.org/wiki/Extension:GetUserName
Modify these extension for your needs
If you indeed just want the username inserted somewhere into the skin HTML, this should do it:
<?php echo htmlspecialchars( $this->username ); ?>

Categories