CakePdf - Engine not loaded - cakephp

I have installed CakePdf plugin for cakephp as outlined in the readme file on GitHub. I am getting an error saying the engine iisnt loaded. I have tried all 3 engines that come with the plugin. Anyone else have this issue and find a solution? Rhanks

http://www.slideshare.net/jellehenkens/building-php-documents-with-cakepdf-cakefest-2012
Here is a slideshow how to install the plugin,
To load the engine use this in bootstrap.php
Configure::write('CakePdf', array(
'engine' => 'CakePdf.DomPdf',
'pageSize'=>'A4',
'orientation' => 'landscape',
));
Go to your controller en use in your public function view or index this:
$this -> pdfConfig = array (
'orientation' => 'landscape',
'download' => true,
'filename' => 'Client_' . $id
);
i hope this will help you,

Related

How can I create cached files within CakePHP Plugin?

I have created a plugin for CakePHP that I would like to generate cached files within its own plugin folder at /app/Plugin/MyPlugin/tmp/cache.
I have already cerated the MyPlugin/tmp/cache directory manually.
I have created a bootstrap file at /app/Plugin/MyPlugin/Config/bootstrap.php with the following content:
<?php
Cache::config('short', array(
'engine' => 'File',
'duration' => '+60 minutes',
'path' => 'Plugin/MyPlugin/tmp/cache',
'prefix' => 'cake_short_',
'mask' => 0666,
));
I have created a Shell script at /app/Plugin/MyPlugin/Console/Command/MyPluginShell.php with the following function:
<?php
...
public function get_listings() {
$listings = $this->Listing->find('all');
Cache::write('listings', $listings, 'short');
$this->out('Task Completed');
}
I can run get_listings from within the Cake console just fine and the Task completes, however there is no Cache file being created at /app/Plugin/MyPlugin/tmp/cache like I would expect.
On a side note, I have tried replacing 'path' => 'Plugin/MyPlugin/tmp/cache' with 'path' => CACHE just to see if it will appear in app/tmp/cache but haven't had any luck.
I have also created the /app/Plugin/MyPlugin/tmp/cache within the plugin.
Any help would be appreciated.
I figured it out.
I wasn't loading the plugin correctly within app/Config/bootstrap.php.
I was doing this (incorrect):
CakePlugin::load('MyPlugin', array('routes' => true));
Instead of this (correct):
CakePlugin::load('MyPlugin', array('routes' => true, 'bootstrap' => true));

How to know webroot in core.php

I'm using CakePHP 2.3.1.
Our server has some independent applications in one server. So I want to change session.cookie_path setting following the Cookbook :
Configure::write('Session', array(
'defaults' => 'php',
'ini' => array(
'session.cookie_path' => '/app/dir'
)
));
I could change it successfully with this. But here is a problem. I need to set session.cookie_path value to webroot dynamically (without string literal value such as '/app/dir').
I've tried to use $this->webroot following this Q&A, but of course it does not work because there is no controller in the file app/Config/core.php.
Any ideas?
I realized a php variable is available : $_SERVER['REQUEST_URI'].
So I could solve the problem.
$requestURI = $_SERVER['REQUEST_URI'];
$webroot = preg_replace('/(^\/[^\/]+\/).*$/', '$1', $requestURI);
//echo $webroot;
Configure::write('Session', array(
'defaults' => 'cake',
'ini' => array(
'session.cookie_path' => $webroot // looks like '/app/'
)
));
But this solution does not have reusability enough : it would not work for apps located in deeper directories such as /apps/app1/.
I'm still awaiting a better solution.

Error Loading Views After Changing Route Value of module.config.php - Zend Framework

This question is regarding Zend Framework application version: 2.1.3. I, the developer, am new to Zend Framework and would greatly value your assistance.
I was making a module for a 'Donor Management System' of a church. The module I am working on is called the 'QueryBuilder'. Previous modules were fine and works great. I use the Zend Helper for Sublime Text and it generated some thing similar for the module.config.php
<?php
/**
*
* #package QueryBuilder
*/
return array(
'controllers' => array(
'invokables' => array(
'QueryBuilder\Controller\QueryBuilder' => 'QueryBuilder\Controller\QueryBuilderController',
),
),
// The following section is new and should be added to your file
'router' => array(
'routes' => array(
'querybuilder' => array(
'type' => 'segment',
'options' => array(
'route' => '/querybuilder[/:action][/:id]',
'constraints' => array(
'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
'id' => '[0-9]+',
),
'defaults' => array(
'controller' => 'QueryBuilder\Controller\QueryBuilder',
'action' => 'index',
//'action' => 'search',
//'action' => 'recent',
),
),
),
),
),
'view_manager' => array(
'template_path_stack' => array(
'querybuilder' => __DIR__ . '/../view',
),
),
);
?>
Determined to have a little bit of fun after making some successful modules, I changed the router as follows.
<?php
/**
*
* #package QueryBuilder
*/
return array(
'controllers' => array(
'invokables' => array(
'QueryBuilder\Controller\QueryBuilder' => 'QueryBuilder\Controller\QueryBuilderController',
),
),
// The following section is new and should be added to your file
'router' => array(
'routes' => array(
'querybuilder' => array(
'type' => 'segment',
'options' => array(
'route' => '/query-builder[/:action][/:id]',
'constraints' => array(
'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
'id' => '[0-9]+',
),
'defaults' => array(
'controller' => 'QueryBuilder\Controller\QueryBuilder',
'action' => 'index',
//'action' => 'search',
//'action' => 'recent',
),
),
),
),
),
'view_manager' => array(
'template_path_stack' => array(
'querybuilder' => __DIR__ . '/../view',
),
),
);
?>
Note: Only the route value was changed from /querybuilder... to /query-builder.... When I tried to access the route http://konnections/query-builder I got some error but I didn't go through it.
Wondering why I wan't to be a hero, I changed the value back to its defaults. And tried to load http://konnections/querybuilder but it also gave an error.
Zend\View\Renderer\PhpRenderer::render: Unable to render template "query-builder/query-builder/index"; resolver could not resolve to a file
No where in the code of the module you could find the words query-builder. So common sense says there can be no way query-builder/query-builder/index needs to be accessed.
Thinking it might be some caching, I looked for it in the entire application folder. Then I restarted Apache, the computer, deleted and made a new Module with the same name QueryBuilder and still the error is there.
Note: This is a plugin that was done nothing with. I only changed the route value thinking it will make the URL look neater.
Here is what I end up with [Image]:
Nope, this is not IE, because I tried in Chrome (which didn't access the query-builder url) as well.
The whole of Zend Folder (the root of the website) has no reference to query-builder. Where does it come from and how can I change it?
Thanks in advance.
from ZF1 series (http://framework.zend.com/manual/1.12/en/zend.controller.basics.html), ZF2 is the same but not found this description on manual.
Case Naming Conventions
Since humans are notoriously inconsistent at maintaining case sensitivity when typing links, Zend Framework actually normalizes path information to lowercase. This, of course, will affect how you name your controller and actions... or refer to them in links.
If you wish to have your controller class or action method name have multiple MixedCasedWords or camelCasedWords, you will need to separate those words on the url with either a '-' or '.' (though you can configure the character used).
As an example, if you were going to the action in FooBarController::bazBatAction(), you'd refer to it on the url as /foo-bar/baz-bat or /foo.bar/baz.bat.
I am Ziyan, the one who asked the question in the first place.
After not finding a solution in Google, I wondered in to making another module and ended up with the same plight. Confused I made a new installation of Zend Framework and made a module with the same name.
Zend\View\Renderer\PhpRenderer::render: Unable to render template "query-builder/query-builder/index"; resolver could not resolve to a file did not go away.
Knowing it is not some thing like reconfiguration, I looked closer.
It seemed to put a dash between every word. I was like Zend is insane! But no, it seems to be splitting the Module name from each upper case letter and adjoining them using a '-' (dash).
In my case QueryBuilder becomes query-builder or plugin named HelloModules would be hello-modules.
So the view manager seems to be looking for ../views/query-builder/query-builder/index.
In my case, ZF Helper for Sublime text needs to look in to the situation. If you could fix the plugin at GitHub it would be great. I will give a try my self.
I couldn't find any proof for my claiming and no time to go through the source codes. Would be glad if some one provide some links.

saving records with cakephp-mongo plugin

I am using cake 2.0 with the Mongo Plugin from ichikaway. Mongo version 2.0.2. I am unable to save records to Mongo from my cake app
My database set up is:
public $mongo = array(
'datasource' => 'Mongodb.MongodbSource',
'host' => 'localhost',
'database' => 'blog',
'port' => 27017,
'prefix' => '',
'persistent' => 'true'
);
}
I have tried numerous variations on the examples provided on the plugins github page for my model but to no avail. Apparently I don't need to specify $useTable = false; in the model with the latest version of the plugin - but if I don't I get a missing table error...
Any ideas?!
school boy error on my part, just needed to cd into the plugin/Mongodb directory and then
git checkout -b cake2.0 origin/cake2.0
which will load the cake 2.0 version of the plugin.
Facepalm.

CakePHP page with no headers/footers

In a download page for a blob from a database, how would I make it so that no other output is sent? Right now it's sending the header, debug info, and a footer. How do I make it so that none of that is sent, just for that view?
you can create an clear layout (e.g. empty.ctp ) in you layouts folder, only with
<?php echo $content_for_layout ?>
and then in you action where you're getting your blob data use that layout
$this->layout = 'empty.ctp';
and also to disable debugging, in your controllers use
Configure::write('debug',0);
if you're unable to create new layout you could try this.
$this->layout = null;
$this->render("view_name");
If you're using this to download files, you should use the Media view in cakePHP
http://book.cakephp.org/view/1094/Media-Views
$this->view = 'Media';
$params = array(
'id' => 'example.zip',
'name' => 'example',
'download' => true,
'extension' => 'zip', // must be lower case
'path' => APP . 'files' . DS // don't forget terminal 'DS'
);
CakePhp 2.3 users :
use Sending files from the Book
CakePhp 2.x users :
use '$this->viewClass' instead of '$this->view'
copy-paste ready full solution, right in any controller file:
<?php
public function download($file) {
$fsTarget = APP.WEBROOT_DIR.DS.'files'.DS.$file; // files located in 'files' folder under webroot
if (false == file_exists($fsTarget)){
throw new NotFoundException(__('Invalid file'));
}
$pathinfo = pathinfo($fsTarget);
$this->viewClass = 'Media';
$params = array(
'id' => $file,
'name' => $pathinfo['filename'], // without extension
'download' => true,
'extension' => $pathinfo['extension'], // must be lower case
'path' => dirname($fsTarget) . DS // don't forget terminal 'DS'
);
$this->set($params);
}
Hope this helps!

Resources