View Error CakePHP UploadPack plugin - cakephp-2.0

I am using CakePHP's UploadPlugin (https://github.com/szajbus/uploadpack). Storing images goes smooth as documented, the problem kicks in when trying to use the helper to view the images:
Fatal Error
Error: Call to a member function image() on a non-object
Code:
<?php echo $upload->image($entry['User']['id'], 'User.avatar') ?>
The helper is correctly loaded in the controllers. What could caseis issue? thanks
UPDATE:
My helper is included as follows:
public $helpers = array('Form', 'UploadPack.Upload');

I had the same issue. I was able to fix it by doing the following:
echo $this->upload->image($MODELNAME, 'MODEL.avatar');

Related

controller logic for included view files in cakephp

As I am including elements/header.ctp file in another main.ctp file..
<?php echo $this->element('header'); ?>
I have included header in main.ctp it is displaying quite good. but when I am writing the query in ElementsController in is throwing an error undefined varible..
Below code for Elements Controller header() is the included file function.
public function header()
{
$this->set('marquee',$this->Newsmaster->find('all',array('order'=>array('Newsmaster.priority DESC'),'limit' =>20)));
$userid = $this->Session->read('user');
}
can anyone help me in solving this please... thank You
Elements Controller is not needed to set "marquee" varaible , you need to code in your usual controller for eg. for pages/index you will need to set variable in PagesController's index function not in under ElementsController

CakePHP - Class ** cannot be found

I have a strange problem with CakePHP
CakePHP gives an error on the following line:
View/Designer/cards:
$this->JsBridge->set('Card.DISPLAY_TYPE_FOLDER_GREETING', Card::DISPLAY_TYPE_FOLDER_GREETING);
Class 'card' can not be found.
However in DesignersController I load the model Card via de following line:
public $uses = array('Designer', 'Card');
If I add the following line in the top of DesignersController
App::uses('Card', 'Model');
The page loads, but the following line does not work:
$this->paginate = $this->Card->getPagination($filter);
I have put the code for the model Card.php here : http://pastebin.com/U7zxKHCx
Can you tell me what is going wrong?
Thank you!
Are you including the CardModel in your Controller?
$uses = array('....','Card',....);
Controller properties, classes attached etc. are NOT directly accessible in a View. You will need to set this constant Card::DISPLAY_TYPE_FOLDER_GREETING to a variable:
$this->set('variableName1', Card::DISPLAY_TYPE_FOLDER_GREETING);
Then use it in the View:
$this->JsBridge->set('Card.DISPLAY_TYPE_FOLDER_GREETING', $variableName1);

CakePHP 2.0: Error on loading an image with the html-helper

I've switched to the newest Version of CakePHP, but when I was about to build up my layout, I got this error:
Fatal error: Call to a member function image() on a non-object in C:\xampp\htdocs\propfe\app\View\Layouts\default.ctp on line 91
of course I've already included the helper in lib/Cake/Controller/AppController.php:
public $helpers = array('Session','Html','Js');
and although it's improbable, the error is in this line, here's no 91 of the layout:
<?php echo $this->html->image('aesculap.jpg'); ?>
You have to use $this->Html instead of $this->html.
You have the helper defined in AppController, but does your controller that is loading this view extend AppController or Controller.

CakePHP 2.0: Preparing data from a different model by the AppController for a Helper?

I've made a helper, that should output some data from my database in the layout, so this data have to be available everywhere. Now I tried to load and set a variable by the AppController, but it seems I can not use the usual find()-method. Here's my error:
Fatal error: Call to a member function find() on a non-object in C:\xampp\htdocs\propfe\Controller\AppController.php on line 46
That's how I tried to load the Model, once by the $uses-variable and once by the App::import()-Command:
var $uses = 'Surgeryhour';
App::import('Model','Surgeryhour');
And here's the line 46 of the error:
$this->set('data', $this->Surgeryhour->find(null, '1'));
Any ideas how I can get all this to work?
Try load model like this:
$this->loadModel('Surgeryhour');
$this->set('data', $this->Surgeryhour->find(null, '1'));
Don't need variable $uses.
never use App::import for models
always:
$this->Surgeryhour = ClassRegistry::init('Surgeryhour');

HtmlHelper not loaded in tutorial example

I followed the tutorial to create a blog for CakePHP 1.3 up to this step but keep getting error when running the app:
Notice (8): Undefined property: View::$Html [APP\views\posts\index.ctp, line 27]
Line 27:
echo $this->Html->link($post['Post']['title'], array('controller' => 'posts', 'action' => 'view', $post['Post']['id']));
Apparently CakePHP doesn't load the HtmlHelper class, I check over and over again in my controller, the Html should be loaded properly.
class PostsController extends AppController {
var $name = 'Posts';
var $helpers = array('Html', 'Form');
function index() {
$this->set('posts', $this->Post->find('all'));
}
}
When I added this line to the view (index.ctp), it works
$this->Html = &$this->loaded['html'];
But apparently I can't do that for every ctp file. I'm running Windows 7, WAMP 2, PHP 5.3.5, CakePHP 1.3.7 stable.
Anyone has a clue?
Like the comment by mtnorthrop above:
Is the FormHelper being loaded in your
views? What do you get if you do
pr($this->Html) in your view? How
about pr($html)? Until CakePHP 1.3,
helpers were accessed directly instead
of through the View object. In CakePHP
1.3 both methods should work. Does the plain $html->link() or $form->input()
methods work for you? – mtnorthrop 51
mins ago
From the book:
"The HtmlHelper is available in all
views by default. If you're getting an
error informing you that it isn't
there, it's usually due to its name
being missing from a manually
configured $helpers controller
variable."
You shouldn't need to specify it in your controllers. Perhaps somehow doing so is interfering with the core? BTW, you don't need to specify Form either.

Resources