Showing message Twig_Error_Loader in open cart - php

I am using open cart version 3. And I got the following message: Twig_Error_Loader in open cart after replacing theme files.
Full error:
Fatal error: Uncaught exception 'Twig_Error_Loader' with message 'Unable to
find template "common/column_left.twig" (looked into:
C:/xampp/htdocs/fast/catalog/view/theme).' in
C:\xampp\htdocs\fast\system\library\template\Twig\Loader\Filesystem.php:215
Stack trace: #0
C:\xampp\htdocs\fast\system\library\template\Twig\Loader\Filesystem.php(139
Twig_Loader_Filesystem->findTemplate('common/column_l...') #1
C:\xampp\htdocs\fast\system\library\template\Twig\Environment.php(312):
Twig_Loader_Filesystem->getCacheKey('common/column_l...') #2
C:\xampp\htdocs\fast\system\library\template\Twig\Environment.php(378):
Twig_Environment->getTemplateClass('common/column_l...', NULL) #3
C:\xampp\htdocs\fast\system\library\template\twig.php(52): Twig_Environment-
>loadTemplate('common/column_l...') #4
C:\xampp\htdocs\fast\system\library\template.php(22): Template\Twig-
>render('common/column_l...', false, 'fastor') #5
C:\xampp\htdocs\fast\system\engine\loader.php(86): Template-
>render('common/column_l...', Object(Registry), '1') #6 C:\xampp\ in
C:\xampp\htdocs\fast\system\library\template\Twig\Loader\Filesystem.php on
line 215
Your help will be greatly appreciated

it looks that the problem resides in
catalog/controller/event/theme.php
the Code assigns a path only when $theme:info isn't set.
if ($theme_info) {
$template = html_entity_decode($theme_info['code'], ENT_QUOTES, 'UTF-8');
}elseif (is_file(DIR_TEMPLATE . $theme . '/template/' . $route . '.twig')) {
$this->config->set('template_directory', $theme . '/template/');
} elseif (is_file(DIR_TEMPLATE . 'default/template/' . $route . '.twig')) {
$this->config->set('template_directory', 'default/template/');
}
I modified the code to this.
Now a path is asigned and the whole thing works. You still have to reload the cache to see modification.
if ($theme_info) {
$template = html_entity_decode($theme_info['code'], ENT_QUOTES, 'UTF-8');
}
if (is_file(DIR_TEMPLATE . $theme . '/template/' . $route . '.twig')) {
$this->config->set('template_directory', $theme . '/template/');
} elseif (is_file(DIR_TEMPLATE . 'default/template/' . $route . '.twig')) {
$this->config->set('template_directory', 'default/template/');
}

Solved in the following way. In the admin panel, go to Design-> template editor, on the right "History" Find and delete common/column_left. The left column will be rolled back "by default" If you need to make changes to it, do it in the column_left.twig file and upload it to the server, update the cache.

Related

How to call the instance of class?

I am using the setup, I download and setup package from github with link below:
https://github.com/graphaware/reco4php
I have also installed the php7 and neo7j they are running properly on localhost (ubuntu16.04).
I am getting error in browser:
Fatal error: Uncaught Error: Class 'GraphAware\Reco4PHP\Demo\Github\RecommendationEngine' not found in /var/www/html/recommendation_2/example.php:9 Stack trace: #0 {main} thrown in /var/www/html/recommendation_2/example.php on line 9
when hit example.php form browser.example.php file code below:
<?php
// example.php file
require_once __DIR__.'/vendor/autoload.php';
use GraphAware\Reco4PHP\Demo\Github\RecommendationEngine;
use GraphAware\Reco4PHP\RecommenderService;
$rs = RecommenderService::create("http://neo4j:idealindore#localhost:7474");
$rs->registerRecommendationEngine(new RecommendationEngine());
$stopwatch = new \Symfony\Component\Stopwatch\Stopwatch();
$input = $rs->findInputBy('User', 'login', 'jakzal');
$engine = $rs->getRecommender("github_who_to_follow");
$stopwatch->start('reco');
$recommendations = $engine->recommend($input);
$e = $stopwatch->stop('reco');
//echo $recommendations->size() . ' found in ' . $e->getDuration() . 'ms' .PHP_EOL;
foreach ($recommendations->getItems(10) as $reco) {
echo $reco->item()->get('login') . PHP_EOL;
echo $reco->totalScore() . PHP_EOL;
foreach ($reco->getScores() as $name => $score) {
echo "\t" . $name . ':' . $score->score() . PHP_EOL;
}
}
Can anybody help me how can I solve this issue?
You are getting this error because you did not use the right path to the classes.
Change This :
use GraphAware\Reco4PHP\Demo\Github\RecommendationEngine;
use GraphAware\Reco4PHP\RecommenderService;
to where you actually store These files.
RecommendationEngine.php
RecommenderService.php
Beside you also need to use these classes :
use GraphAware\Common\Cypher\Statement;
use GraphAware\Common\Type\Node;
use GraphAware\Reco4PHP\Context\Context;
use GraphAware\Reco4PHP\Engine\SingleDiscoveryEngine;
See This Link and follow the tutorial step by step to learn how to build a graph base recommendation system with Neo4J.
Also Check This Post if you have any problem with the tutorial.

How to hit a url and download its xml using php

I tried everything to get the xml from the url, even smottt idea from PHP How to hit a url and download its xml , but didnt work for me.
my scenario;
URL that generates Dollar Exchange Rates:
nrb.org.np/exportForexXML.php?YY=2015&MM=03&DD=01&YY1=2015&MM1=03&DD1=01
Here: YY MM DD are the starting date and YY1 MM1 DD1 are the ending date of report. I believe , it generates an xml in unix time of Kathmandu, Asia. Everytime and second seperate xml file name.
Searched internet but nothing,
I want to display the result of xml in a page using php either by downloading the xml from the given url to my localhost folder or directly from web.
please help.
Thanks in Advance
Edited: Code I am using is
$url = "nrb.org.np/exportForexXML.php?YY=2015&MM=03&DD=01&YY1=2015&MM1=03&DD1=01";
$xml = new SimpleXMLElement($url, null, true);
foreach($xml->CurrencyConversionResponse as $CurrencyConversionResponse) {
echo $CurrencyConversionResponse->BaseCurrency . "<br />";
echo $CurrencyConversionResponse->TargetCurrency . "<br />";
echo $CurrencyConversionResponse->ConversionTime . "<br />";
echo $CurrencyConversionResponse->ConversionRate . "<br />";
}
And the error message is
Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: I/O warning : failed to load external entity "nrb.org.np/exportForexXML.php?YY=2015&MM=03&DD=01&YY1=2015&MM1=03&DD1=01" in C:\xampp\htdocs\xml.php on line 4
Fatal error: Uncaught exception 'Exception' with message 'String could not be parsed as XML' in C:\xampp\htdocs\xml.php:4 Stack trace: #0 C:\xampp\htdocs\xml.php(4): SimpleXMLElement->__construct('nrb.org.np/expo...', 0, true) #1 {main} thrown in C:\xampp\htdocs\xml.php on line 4
Add the http:// to the URL
$url = "http://nrb.org.np/exportForexXML.php?YY=2015&MM=03&DD=01&YY1=2015&MM1=03&DD1=01";
$xml = new SimpleXMLElement($url, null, true);
foreach($xml->CurrencyConversionResponse as $CurrencyConversionResponse) {
echo $CurrencyConversionResponse->BaseCurrency . "<br />";
echo $CurrencyConversionResponse->TargetCurrency . "<br />";
echo $CurrencyConversionResponse->ConversionTime . "<br />";
echo $CurrencyConversionResponse->ConversionRate . "<br />";
}

failed to open stream: Success in opencart ajax request

I have googled for a day without a luck. Can anyone help please??
I have an AJAX request which loads more categories at home page. The code is
$json=array();
$template = new Template();
$template->data['categories'] = $this->data['categories'];
$html = $template->fetch($this->config->get('config_template') . '/template/common/category_load.tpl');
$json['success'] = $html;
$json['output'] = $this->render();
$this->response->setOutput(json_encode($json));
While I check the function it gives the correct output. But while trying to load through AJAX it gives the error saying
failed to open stream: Success in /var/www/html/boomrc/system/engine/controller.php on line 82
Have I done any mistake? I'm new to OpenCart.
if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/common/category_load.tpl')) {
$this->template = $this->config->get('config_template') . '/template/common/category_load.tpl';
}
$json['content'] = str_replace("\r\n", "", $this->render());
echo json_encode($jdata);
Try this one..
Please use Browser-Debug-Console.
Be sure, that you doesn't do a cross-domain-request for your ajax.
There are some security-limitations, so you can't do cross-domain request for ajax.
Maybe post your controlle.php (or simplified code of it) here.

SiteCake and my PHP are clashing

I am trying to install sitecake, I followed all the instructions by adding <?php include "sitecake/server/sitecake_entry.php"; ?> on the top of the page and classes to the divs that I want to be edited.
The problem is, when I add <?php include "sitecake/server/sitecake_entry.php"; ?> my PHP stops working, why is that? what I am doing wrong?
For example, here is one of my PHP scripts that is added to the pages using PHP include:
<!--add class .active to current page-->
<?php
$directoryURL = $_SERVER['REQUEST_URI'];
$path = parse_url($directoryURL, PHP_URL_PATH);
$components = explode('/', $path);
$currentPage = preg_replace("/\\.[^.\\s]{3,4}$/", "", end($components));
if ($currentPage == "") {
$currentPage = "index";
}
function href($url) {
global $currentPage;
$path = explode('/', $url);
$page = preg_replace("/\\.[^.\\s]{3,4}$/", "", end($path));
echo 'href="' . $url . '" ';
if ($page == $currentPage) {
echo 'class="active"';
}
}
?>
Here is the error I get when I use error_reporting(E_ALL):
Fatal error: Uncaught exception 'Zend_Session_Exception'
with message 'Session must be started before any output has been sent to the browser; output started in /home/approach/public_html/index.php/2'
in /home/approach/public_html/sitecake/server/library/Zend/Session.php:454
Stack trace:
#0 /home/approach/public_html/sitecake/server/library/Zend/Session/Namespace.php(143): Zend_Session::start(true)
#1 /home/approach/public_html/sitecake/server/application/services/impl/onesite/Bootstrap.php(21): Zend_Session_Namespace->__construct('Default', false)
#2 /home/approach/public_html/sitecake/server/library/Zend/Application/Bootstrap/BootstrapAbstract.php(666): Bootstrap->_initSession()
#3 /home/approach/public_html/sitecake/server/library/Zend/Application/Bootstrap/BootstrapAbstract.php(619): Zend_Application_Bootstrap_BootstrapAbstract->_executeResource('session')
#4 /home/approach/public_html/sitecake/server/library/Zend/Application/Bootstrap/BootstrapAbstract.php(583): Zend_Application_Bootstrap_BootstrapAbstract->_bootstra in /home/approach/public_html/sitecake/server/library/Zend/Session.php on line 454
Your error message is this:
Session must be started before any output has been sent to the browser; output started in /home/approach/public_html/index.php/2
And the error occurred at:
/home/approach/public_html/sitecake/server/library/Zend/Session.php:454
The full explanation of the meaning of this message is already explained in detail at another answer, I highly recommend that you read this answer to get a better example of what's going on.
For your specific case, it would seem that you're including your sitecake_entry.php script at the top of the page, or, at least somewhere before you initialize Zend. What you want to do, is this (from the SiteCake examples page):
<?php include "sitecake/server/sitecake_entry.php"; ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
I don't know the details of Zend, or your application in particular, the thing you probably want to do is find your HTML template, you could search your projects's directory for <!DOCTYPE, and add the line above that, as per the example, instead of adding it to your index.php.

How to trace PHP files callstack used to render a page?

For many "on the rush" web development (CMS customisation or simple helping hand to a friend beggin "please help, I can't remove this div on my wordpress page") one common problem appears : what is the code behind the page where our problem lives.
Then my question is simple : is there any tool / method that can ease the searching of the scripts implied in a given page production on a php based webapp ?
Something that can build a call tree for a given page would be great !
xdebug provides a navigable callstack and much much more. On their documentation page there are a long list of wonderful things.
you're looking for debug_backtrace()
This is a particularly helpful function taken from the CakePHP framework:
function debug($var = false, $showHtml = false, $showFrom = true) {
if ($showFrom) {
$calledFrom = debug_backtrace();
echo '<strong>' . substr(str_replace(ROOT, '', $calledFrom[0]['file']), 1) . '</strong>';
echo ' (line <strong>' . $calledFrom[0]['line'] . '</strong>)';
}
echo "\n<pre class=\"debug\">\n";
$var = print_r($var, true);
if ($showHtml) {
$var = str_replace('<', '<', str_replace('>', '>', $var));
}
echo $var . "\n</pre>\n";
}

Categories