I have a problem with dompdf in PHP, in my template file dompdf does not execute my <?php ?> code. Do you have any ideas?
Template.php
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
BEFORE
<?php echo "PHP CODE"; ?>
AFTER
<?php echo $var1; ?>
PHP code
<?php
require dirname(__DIR__) . '/vendor/autoload.php';
require_once dirname(__DIR__) . '/vendor/dompdf/dompdf/lib/html5lib/Parser.php';
require_once dirname(__DIR__) . '/vendor/dompdf/dompdf/src/Autoloader.php';
Dompdf\Autoloader::register();
$var1 = "TEST1";
var_dump($var1);
use Dompdf\Dompdf;
use Dompdf\Options;
$options = new Options();
$options->set('isPhpEnabled', TRUE);
$dompdf = new Dompdf($options);
$dompdf->loadHtml( file_get_contents(dirname(__DIR__) . '\template.php') );
$dompdf->render();
$output = $dompdf->output();
file_put_contents(dirname(__DIR__) . '/data/' .'Output.pdf', $output);
PDF output
BEFORE AFTER
....
Info
dompdf/dompdf version ^0.8.2
PHP 7.2.12
Thanks C,
The problem was the file_get_contents it only takes the content of a file, it do not evaluate the content of the file (fo ex: <?php code?>).
I have to add to my code a buffering mecanics:
ob_start();
include $template;
$contents = ob_get_clean();
$dompdf->loadHtml($contents);
C
Related
We would like to create an override for the Joomla newsflash module which should be able to display the individual Joomla article tags on the frontend:
"tag 1, tag 2, tag 3 etc.."
RokSproket from rockettheme.com is able to achieve exactly that output. But we would like to have the same result with the newsflash module. We currently have the following code saved in our new _item.php override. There is no error message on the frontend but also no tags are visible. Any help is much appreciated.
<?php if ($params->get('show_tags', 1) && !empty($item->tags)) : ?>
<?php $item->tagLayout = new JLayoutFile('joomla.content.tags'); ?>
<?php echo $item->tagLayout->render($item->tags->itemTags); ?>
<?php endif; ?>
Here's how we've solved that question:
<?php
$itemtags = (new JHelperTags)->getItemTags('com_content.article', $item->id);
$taglayout = new JLayoutFile('joomla.content.tags');
$tags='';
if( !empty($itemtags) )
$tags = '<div class="itemtags">'.str_replace(',','',$taglayout->render($itemtags)).'</div>';
?>
<?php echo $tags; ?>
Hi i want generate dynamic Meta tag through helper or library in codeigniter 3
I am creating static website without model.
I have -
Header.php - which have header part and meta tags.
middle_page.php
footer.php
if i am calling meta() html helper in my controller function like index then generated meta tag is showing in top of the page means above to deceleration of header.php
how to write helper or library for that so if i call meta tag in function and in header.php echo meta(); then particular meta tag should be generated.
I have tried many other answers from Stackoverflow but those are not worked for me.
your help will be appreciated.
Follow this pattern Maybe it will help you
IN controller
<?php
function show_home() {
$data['page'] = 'home';
$this->load->view('header',$data);
$this->load->view('home');
$this->load->view('footer');
}
function show_contact_us() {
$data['page'] = 'contact_us';
$this->load->view('header',$data);
$this->load->view('contact_us');
$this->load->view('footer');
}
?>
Create helper meta.php
<?php
function meta($page) {
$meta = '<meta charset="utf-8">';
switch ($page) {
case 'home':
$meta .= '<meta name="description" content="Home page description">';
$meta .= '<meta name="keywords" content="Home page keywords">';
break;
case 'contact_us':
$meta .= '<meta name="description" content="Contact us page description">';
$meta .= '<meta name="keywords" content="Contact us page keywords">';
break;
default:
$meta .= '<meta name="description" content="default page description">';
$meta .= '<meta name="keywords" content="default page keywords">';
break;
}
return $meta;
}
?>
load meta helper in autoload.php
$autoload['helper'] = array("meta");
call meta function in your header for individual view
echo meta($page);
When 404 Page Not Found error occurs application/errors/error_404.php template is used in CodeIgniter. I need to access the base_url() function inside that template. Any suggestion on how base_url() or site_url() functions can be accessed inside error_404.php will be really helpful.
you might want to use this simple trick. Just change the code below:
<?php echo base_url() ?>
to:
<?php echo config_item(‘base_url’); ?>
credit for https://www.petanikode.com/codeigniter-base-url-404/
this work for my case
Try following in application/errors/error_404.php
$CI =& get_instance();
if( ! isset($CI))
{
$CI = new CI_Controller();
}
$CI->load->helper('url');
echo $CI->base_url();
Try this in top of your 404 page:
$CI =& get_instance();
if( ! isset($CI))
{
$CI = new CI_Controller();
}
$CI->load->helper('url');
echo base_url();
// below here base_url(), site_url() will work
Work for all pages under views/errors/html folder
you can directly use these functions, because these are global functions.
eg: you are in 404 page template
<html>
<head>
<title> 404 Error </title>
</head>
<body>
<?php echo base_url('/your path'); ?>
<?php echo site_url('/your path'); ?>
</body>
</html>
Edited
goto your application/config/autoload.php file and add url in autoload array
$autoload['helper'] = array('url', 'form');
after this you can directly use <?php echo base_url('/your path'); ?> everywhere
Edit your /application/config/routes.php
$route['404_override'] = 'your_controller/error';
Add function into your_controller.php
function error(){
show_404();
}
You are ready to go.
refer https://stackoverflow.com/a/48033542/7840849
or do followings
$autoload['helper'] = array('url'); in application\config\autoload.php file
Then simply use echo config_item('base_url'); instead of echo base_url(); in codeigniter default error pages
$autoload['helper'] = array('url'); in application\config\autoload.php file
Then simply use echo config_item('base_url'); instead of echo base_url(); in codeigniter default error pages
this work for my case, try this method
Change the function base_url() to config_item('base_url')
<?php echo config_item('base_url'); ?>
In order to use base_url(), you must first have the URL Helper loaded. This can be done either in application/config/autoload.php
$autoload['helper'] = array('url');
Or, manually:
$this->load->helper('url');
Once it's loaded, be sure to keep in mind that base_url() doesn't implicitly print or echo out anything, rather it returns the value to be printed:
echo base_url();
Check if you have something configured inside the config file /application/config/config.php e.g.
$config['base_url'] = 'http://example.com/';
**Then**
u can use like this..
<link rel="stylesheet" href="<?php echo base_url();?>/css/template/default.css" type="text/css" />
I am attempting to redirect in a template index.php i am building and getting a redirect loop. Am I missing something? What I am attempting to do is redirect the default page depending on the entry URL as well as certain template styles. My template code looks something like this...
config.php
<?php
//joomla configuration
JLoader::import('joomla.filesystem.file');
JHtml::_('behavior.framework', true);
JHtml::_('jquery.framework');
$app = JFactory::getApplication();
$config = JFactory::getConfig();
$doc = JFactory::getDocument();
//load template style sheets and scripts
$doc->addStyleSheet($this->baseurl.'/media/jui/css/bootstrap.min.css');
$doc->addStyleSheet($this->baseurl.'/media/jui/css/bootstrap-responsive.min.css');
$doc->addStyleSheet('templates/' . $this->template . '/css/template.css');
$doc->addScript('templates/' . $this->template . '/javascript/template.js');
//sidebar configuration - determines the span classes for the sidebar and main component area
$component = $this->params->get('component-span');
if(!$this->countModules('sidebar')):
$component = 12;
endif;
$sidebar = 12 - $component;
$sidebar_pos = $this->params->get('sidebar-pos');
//navbar inverse
if($this->params->get('navbar-inverse') == 'TRUE'):
$inverse = ' navbar-inverse';
endif;
//multisite configuration - determines which template params and menu module to display depending on the base URL
$domain = $_SERVER["SERVER_NAME"];
$primary = $this->params->get('site-domain');
$sub1= $this->params->get('domain1-domain');
$sub2= $this->params->get('domain2-domain');
$sub3= $this->params->get('domain3-domain');
$sub4= $this->params->get('domain4-domain');
$sub5= $this->params->get('domain5-domain');
$menuid = $app->getMenu();
if($domain == $primary):
$logo = $this->params->get('logo');
$title = $this->params->get('site-title');
$slogan = $this->params->get('site-slogan');
$menu = '<jdoc:include type="modules" name="menu" />';
elseif($domain == $sub1):
$logo = $this->params->get('domain1-logo');
$title = $this->params->get('domain1-title');
$slogan = $this->params->get('domain1-slogan');
$menu = '<jdoc:include type="modules" name="menu-1" />';
$menuitemid = $this->params->get('domain1-menuid');
$menuitem = $menuid->getItem($menuitemid);
elseif($domain == $sub2):
$logo = $this->params->get('domain2-logo');
$title = $this->params->get('domain2-title');
$slogan = $this->params->get('domain2-slogan');
$menu = '<jdoc:include type="modules" name="menu-2" />';
$itemid = $this->params->get('domain2-menuid');
elseif($domian == $sub3):
$logo = $this->params->get('domain3-logo');
$title = $this->params->get('domain3-title');
$slogan = $this->params->get('domain3-slogan');
$menu = '<jdoc:include type="modules" name="menu-3" />';
$itemid = $this->params->get('domain3-menuid');
elseif($domain == $sub4):
$logo = $this->params->get('domain4-logo');
$title = $this->params->get('domain4-title');
$slogan = $this->params->get('domain4-slogan');
$menu = '<jdoc:include type="modules" name="menu-4" />';
$itemid = $this->params->get('domain4-menuid');
elseif($domain == $sub5):
$logo = $this->params->get('domain5-logo');
$title = $this->params->get('domain5-title');
$slogan = $this->params->get('domain5-slogan');
$menu = '<jdoc:include type="modules" name="menu-5" />';
$itemid = $this->params->get('domain5-menuid');
endif;
?>
index.php
<?php
defined('_JEXEC') or die;
include($this->baseurl.'templates/'.$this->template.'/includes/config.php');
$default_page = new JURI($menuitem->link);
print($domain.'<br />'.$primary.'<br />'.$default_page);
if ($domain != $primary):
$link = $default_page;
$msg = 'Testing Redirect';
$app->redirect($link, $msg);
endif;
?>
<!DOCTYPE html>
<html>
<head>
<?php $this->setTitle($title.' - '.$this->getTitle()); ?>
<jdoc:include type="head" />
</head>
This is occurring because $domain != $primary is failing. The way that you get $domain maybe is the root of cause.
Look at PHP $_SERVER['HTTP_HOST'] vs. $_SERVER['SERVER_NAME'], am I understanding the man pages correctly? and be sure that is not this the problem.
Also, Joomla have JUri package that help with this. If you are working with Joomla, is a good idea use it.
Product viewed located here:
App/code/local/Mage/Reports/Block/Product/Viewed.php
I have added the following code:
class Mage_Reports_Block_Product_Viewed extends Mage_Reports_Block_Product_Abstract{
...
protected function _prepareLayout()
{
parent::_prepareLayout();
$toolbar = $this->getLayout()->createBlock('catalog/product_list_toolbar', microtime())
->setCollection($this->getProductCollection());
$pager = $this->getLayout()->createBlock('page/html_pager', microtime());
$toolbar->setChild('product_list_toolbar_pager', $pager);
$this->setChild('toolbar', $toolbar);
$this->getProductCollection()->load();
return $this;
}
public function getPagerHtml()
{
return $this->getChildHtml('toolbar');
}
}
My template should be like this:
<?php if ($_products = $this->getRecentlyViewedProducts()): ?>
<!-- top pagination -->
<?php echo $this->getPagerHtml(); ?>
<?php if($_collection->getSize()): ?>
...
<?php foreach ($_collection as $_item): ?>
...
<?php endforeach; ?>
<?php endif ?>
<!-- bottom pagination -->
<?php echo $this->getPagerHtml(); ?>
<?php endif ?>
I'm added code not working in Viewed.php. Can someone please help me solve this problem?
Any help would be greatly appreciated.
You can add your Block code under : app/code/local/Mage/Catalog/Block/Product/Viewed.php
And make the class name changes respectively .
If your code is correct , it should work .