I get this error, when using Zend Framework v2.4: Call to undefined method Zend\Mvc\View\Http\ViewManager::getResolver() in /../../../demo/vendor/dino/dompdf-module/src/DOMPDFModule/Mvc/Service/ViewPdfRendererFactory.php on line 39 But there is no getResolver method in viewmanager. I am using zend framework 2.4/
Can you help me to solve this?
This is included in vender.
<?php
use DOMPDFModule\View\Model\PdfModel;
This is controller action
public function generatepdfAction(){
// $pdf1 = new Zendpdf\PdfDocument();
echo "bbb";
$pdf = new PdfModel();
$pdf->setOption('filename', 'monthly-report'); // Triggers PDF download, automatically appends ".pdf"
$pdf->setOption('paperSize', 'a4'); // Defaults to "8x11"
$pdf->setOption('paperOrientation', 'landscape'); // Defaults to "portrait"
// To set view variables
$pdf->setVariables(array(
'message' => 'Hello'
));
return $pdf;
}
It's not a error in your code. This is a known issue as you can see on https://github.com/raykolbe/DOMPDFModule/issues/37
There is also a pull request for that issue. I solved this with creating my own DOMPDFModule with the changes of this commit, because it seems that there won't be an update of DOMPDFModule soon.
Another possibility would be using an older version of zend-mvc, because the issue appears since zend-mvc 2.7. Just use
"zendframework/zend-mvc": "~2.6.3"
in your composer.json and the the DOMPDFModule will work again. But this should be only a temporarily solution if you want to use new features of the Zend Framework and its modules in the future.
Related
I use the pear extension File_PDF in an old PHP app I maintain.
It seems like the last version by that module is version 0.3.3 from and it is not maintained anymore and has been superseded by the package Horde_Pdf from pear.horde.org.
Can I just change the codebase to the new package? Or do I need to change the function calls?
I started a repository where I convert the old code to the new code at https://github.com/rubo77/File_PDF
The old PDF.php was renamed to Writer.php and the fonts are now in another folder. and the class File_PDF was renamed to class Horde_Pdf_Writer.
I replaced the code in my scripts:
and changed
require_once('vendors/pear/File_PDF/PDF.php');
$this->pdf = &File_PDF::factory();
to
require_once('vendors/pear/Horde_Pdf_Writer/Writer.php');
$this->pdf = new Horde_Pdf_Writer();
now I get the error
Uncaught Error: Class 'Horde_String' not found in /var/www/app/vendors/pear/Horde_Pdf_Writer/Writer.php
A better solution would be to use a more actively maintained PDF generation library like TCPDF, which doesn't need much changes either, e.g. from file_PDF to TCPDF just:
replace newLine() with Ln()
replace getOutput() with Output()
SetFont('Arial', ... doesn't work, so just use SetFont('', ...
If you really need this old Library you need to also download those packages:
Horde_Exception
Horde_Util
Horde_Translation
To let it run in a local folder, edit some files:
instead of calling File_PDF with
require_once('vendors/pear/File_PDF/PDF.php');
$this->pdf = &File_PDF::factory();
now call
require_once('vendors/pear/Horde/Pdf/Writer.php');
require_once('vendors/pear/Horde/Pdf/Exception.php');
require_once('vendors/pear/Horde/String.php');
$this->pdf = new Horde_Pdf_Writer();
in Writer.php the function _getFontFile() needs these extra lines:
$fontname = Horde_String::ucfirst(Horde_String::lower($fontkey));
require_once('vendors/pear/Horde/Pdf/Font/'.$fontname.'.php');
$fontClass = 'Horde_Pdf_Font_' . $fontname;
in Exception.php you need to call
require_once('vendors/pear/Horde/Exception/Wrapped.php');
in Wrapped.php you need
require_once('vendors/pear/Horde/Exception.php');
I'm trying to rewrite a "custom framework" application to the Symfony, but I can not do everything at once, so I've divided the process into steps.
From important notes - I've already implemented the symfony/templating component and the symfony/twig-bridge component.
That's how I want to output the form in the template:
<?php echo $view['form']->form($form) ?>
As I'm doing so the following error is thrown:
Symfony\Component\Form\Exception\LogicException
No block "form" found while rendering the form.
/var/www/html/vendor/symfony/form/FormRenderer.php on line 98
To render the templates I'm using the DelegatingEngine which uses the PhpEngine and the TwigEngine.
Setting up the Twig with the \Symfony\Bridge\Twig\Extension\FormExtension is well documented, but what I'm missing is the php setup. This is how I'm doing this:
new \Symfony\Component\Form\Extension\Templating\TemplatingExtension($phpEngine, $this->csrfManager());
Could you point me what am I missing or what's wrong with my setup?
I think the simplest way would have been to install the Symfony 3.3 standard edition next to your app (pending the release of Symfony Flex).
After this, find a way to use the router of Symfony with the router of your application.
So you could have the full Symfony framework, create your form type in it and let Symfony render it :
With an ajax call
With a new Symfony Kernel in your legacy app
I've found the answer:
I was using the wrong FormRendererEngineInterface. Instead of relying on the \Symfony\Component\Form\Extension\Templating\TemplatingExtension class I've registered the form helper by myself:
$phpEngine = new PhpEngine(new TemplateNameParser(), new FilesystemLoader(realpath(__DIR__.'/../Template').'/%name%'));
$twigEngine = new TwigEngine($this->twig(), new TemplateNameParser());
$this->TemplateEngine = new DelegatingEngine(array(
$phpEngine,
$twigEngine,
));
$phpEngine->addHelpers(array(
new FormHelper(new FormRenderer($this->twigFormRendererEngine())),
));
As you can see in the TemplatingEngine:
public function __construct(PhpEngine $engine, CsrfTokenManagerInterface $csrfTokenManager = null, array $defaultThemes = array())
{
$engine->addHelpers(array(
new FormHelper(new FormRenderer(new TemplatingRendererEngine($engine, $defaultThemes), $csrfTokenManager)),
));
}
It relies on the TemplatingRendererEngine while I need the TwigRendererEngine instance, as the form templates are the twig files.
Correct me if my explanation is wrong, but the solution is working.
i'm want to creating a design pattern and use the "Blade templating engine".
Can I use the Blade templating engine outside of Laravel and use it in my new pattern ?
For the record:
I tested many libraries to run blade outside Laravel (that i don't use) and most are poor hacks of the original library that simply copied and pasted the code and removed some dependencies yet it retains a lot of dependencies of Laravel.
So I created (for a project) an alternative for blade that its free (MIT license, i.e. close source/private code is OK) in a single file and without a single dependency of an external library. You could download the class and start using it, or you could install via composer.
https://github.com/EFTEC/BladeOne
https://packagist.org/packages/eftec/bladeone
It's 100% compatible without the Laravel's own features (extensions).
How it works:
<?php
include "lib/BladeOne/BladeOne.php";
use eftec\bladeone;
$views = __DIR__ . '/views'; // folder where is located the templates
$compiledFolder = __DIR__ . '/compiled';
$blade=new bladeone\BladeOne($views,$compiledFolder);
echo $blade->run("Test.hello", ["name" => "hola mundo"]);
?>
Another alternative is to use twig but I tested it and I don't like it. I like the syntax of Laravel that its close to ASP.NET MVC Razor.
Edit: To this date (July 2018), it's practically the only template system that supports the new features of Blade 5.6 without Laravel. ;-)
You certainly can, there are lots of standalone blade options on packagist, as long as you are comfortable with composer then there should be no issue, this one looks pretty interesting due to having a really high percentage of stars compared to downloads.
Be warned though i have not tried it myself, like you i was looking for a standalone option for my own project and came across it, i will be giving it a real good workout though at sometime in the near future,
Matt Stauffer has created a whole repository showing you how you can use various Illuminate components directly outside of Laravel. I would recommend following his example and looking at his source code.
https://github.com/mattstauffer/Torch
Here is the index.php of using Laravel Views outside of Laravel
https://github.com/mattstauffer/Torch/blob/master/components/view/index.php
You can write a custom wrapper around it so that you can call it like Laravel
use Illuminate\Container\Container;
use Illuminate\Events\Dispatcher;
use Illuminate\Filesystem\Filesystem;
use Illuminate\View\Compilers\BladeCompiler;
use Illuminate\View\Engines\CompilerEngine;
use Illuminate\View\Engines\EngineResolver;
use Illuminate\View\Engines\PhpEngine;
use Illuminate\View\Factory;
use Illuminate\View\FileViewFinder;
function view($viewName, $templateData)
{
// Configuration
// Note that you can set several directories where your templates are located
$pathsToTemplates = [__DIR__ . '/templates'];
$pathToCompiledTemplates = __DIR__ . '/compiled';
// Dependencies
$filesystem = new Filesystem;
$eventDispatcher = new Dispatcher(new Container);
// Create View Factory capable of rendering PHP and Blade templates
$viewResolver = new EngineResolver;
$bladeCompiler = new BladeCompiler($filesystem, $pathToCompiledTemplates);
$viewResolver->register('blade', function () use ($bladeCompiler) {
return new CompilerEngine($bladeCompiler);
});
$viewResolver->register('php', function () {
return new PhpEngine;
});
$viewFinder = new FileViewFinder($filesystem, $pathsToTemplates);
$viewFactory = new Factory($viewResolver, $viewFinder, $eventDispatcher);
// Render template
return $viewFactory->make($viewName, $templateData)->render();
}
You can then call this using the following
view('view.name', ['title' => 'Title', 'text' => 'This is text']);
Yes you can use it where ever you like. Just install one of the the many packages available on composer for it.
If you're interested in integrating it with codeigniter I have a blog post here outlining the process.
Following the above steps should make it obvious how to include it into any framework.
I am trying to use highchart in cakephp and have followed the below tutorial and also the stackoverflow post on the subject.
I still get a highchart not found.
I downloaded highchartPHP and placed all the 4 files in Vendor/HighchartsPHP
In the layout, I add the lines with the actual js files in webroot/js
echo $this->Html->script('jquery-1.9.1.min'); // Include jQuery library
echo $this->Html->script('highcharts'); // Include jQuery library
This is my code
<?php
App::import('Vendor', 'HighchartsPHP/Highchart');
class ChartsController extends AppController
{
public function index() {
$chart = new Highchart(); /////////////////Error: Class 'Highchart' not found
$chart->chart = array(
'renderTo' => 'container', // div ID where to render chart
'type' => 'line'
);
$chart->series[0]->name = 'Tokyo';
$chart->series[0]->data = array(7.0, 6.9, 9.5);
$this->set( compact( 'chart' ) );
}
In view file
<?php $chart->printScripts(); ?>
<script type="text/javascript">
<?php echo $chart->render("chart");?>
</script>
https://coderwall.com/p/c6yasq
Using HighchartsPHP library in CakePHP
I can't find any more instructions about cakePHP setup with highcharts so I am stuck and I get a highchart not found error.
I still have something missing. What has confused me is that highchartPHP doesn't explain how you install it for a MVC version with cakephp.
How to setup highchart so it works in cakephp ?
I got from the download zip button link so it must be v3
https://github.com/ghunti/HighchartsPHP
also Error: Class 'Highchart' not found from the controller as I outlined above
That's what happens when people don't mention version numbers...
...a year later nobody knows what they were talking about anymore. The tutorial and the question are most probably about version 1.x.
https://github.com/ghunti/HighchartsPHP/tree/v1.0
So a quick fix would be to use v1, but I'm not sure if that's a very good idea as it's probably not maintained anymore.
Namespaces and Composer
Look at the source code of version 2.x and 3.x, they are now using namespaces, and so the class cannot be found when not pointing into that namespace properly.
As mentioned on the projects homepage the library should be installed via composer, and with pretty much all those libraries using composer the generated autoloader needs to be used, but this isn't really the place here to explain how to use composer, this is already extensively covered all over the net.
https://getcomposer.org/doc/00-intro.md
Be sure to check out the CakePHP docs on how to use the composer autoloader with CakePHP too:
[...]
If you’re installing any other libraries with Composer, you’ll need to setup the autoloader, and work around an issue in Composer’s autoloader. In your Config/bootstrap.php file add the following:
// Load Composer autoload.
require APP . 'Vendor/autoload.php';
// Remove and re-prepend CakePHP's autoloader as Composer thinks it is the
// most important.
// See: http://goo.gl/kKVJO7
spl_autoload_unregister(array('App', 'load'));
spl_autoload_register(array('App', 'load'), true, true);
http://book.cakephp.org/.../advanced-installation.html#installing-cakephp-with-composer
I am trying to use ZF2 PhpRenderer without the MVC framework. Currently I am not able to implement everything but wanted to start re-factoring some stuff into a modified version until I am able to implement the whole framework later in life.
I have been trying to use the Programmer's Reference.
At the top of my tester.php script I have.
use Zend\View\Model\ViewModel,
Zend\View\Renderer\PhpRenderer,
Zend\View\Resolver;
Then later on in the script I have this to start trying to render a script.
$renderer = new PhpRenderer();
$map = new Resolver\TemplateMapResolver(array(
'tester' => __DIR__ . '/tester.phtml',
));
$resolver = new Resolver\TemplateMapResolver($map);
$model = new ViewModel();
$model->setVariable('foo', 'bar');
$model->setTemplate('tester');
echo $renderer->render($model);
The error I get is this
Unable to render template "tester"; resolver could not resolve to a file' in /home/lumberjacked/workspace/www/vendor/zf2/library/Zend/View/Renderer/PhpRenderer.php on line 461
Any help would be awesome.
I found the solution and its pretty simple. After declaring your $resolver you have to set it in the $renderer.
$renderer->setResolver($resolver);
I found this in the constructor of the renderer calling this method.