Wednesday, December 31, 2008

RE: Controller members

Ok fair enough. So how does one use the $javascript->object() ?

I want to pass an array to a javasrcipt variable.

Thanks.

-----Original Message-----
From: cake-php@googlegroups.com [mailto:cake-php@googlegroups.com] On Behalf
Of Bernardo Vieira
Sent: Wednesday, December 31, 2008 3:58 PM
To: cake-php@googlegroups.com
Subject: Re: Controller members


It's not matter of inheritance, the problem is that helpers aren't meant to
be used in controllers. The $helpers array only tells the dispatcher which
helpers to load when rendering the view. Try this:
controllers/ajaxtests_controller

function test() {
$this->set('myvar',$arr);
}

views/ajaxtests/test.ctp
echo $javascript->object($myvar);

rhythmicdevil@gmail.com wrote:
> Confused about inheritance here.
>
> Here is the helpers var from Cake's controller file.
> var $helpers = array('Html', 'Form', 'Javascript', 'Ajax');
>
> AppController extends this so I think that the helpers should be
> available there.
>
> My controller AjaxtestsController extends Appcontroller and so they
> should also be available there
>
> However when I do the following:
> $this->set('myvar', $this->javascript->object($arr)); or
> $this->set('myvar', $javascript->object($arr));
>
> I get the following error:
>
> Notice (8): Undefined property: AjaxtestsController::$javascript [APP
> \controllers\ajaxtests_controller.php, line 26]
>
> Code | Context
>
> $arr = array(
> "item 1",
> "item 2"
> )
>
>
> //debug($this);
> $this->set('myvar', $this->javascript->object($arr));
>
> AjaxtestsController::edit() - APP\controllers
> \ajaxtests_controller.php, line 26
> Object::dispatchMethod() - CORE\cake\libs\object.php, line 115
> Dispatcher::_invoke() - CORE\cake\dispatcher.php, line 245
> Dispatcher::dispatch() - CORE\cake\dispatcher.php, line 211 [main] -
> APP\webroot\index.php, line 88
>
>
> Fatal error: Call to a member function object() on a non-object in C:
> \htdocs\caketest\app\controllers\ajaxtests_controller.php on line 26
>
>
>
> CODE POSTED BELOW
>
> <?php
>
> class AjaxtestsController extends AppController {
>
> var $helpers = array('Javascript');
>
>
> function index()
> {
> $this->pageTitle = 'Index Page';
> }
>
> function view()
> {
> $this->pageTitle = 'View Page';
> }
>
> function edit()
> {
> $this->pageTitle = 'Edit Page';
>
> $arr = array('item 1', 'item 2');
>
> //debug($this);
> $this->set('myvar', $this->javascript->object($arr));
> }
>
> }
>
> ?>
>
> >
>
>


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to cake-php+unsubscribe@googlegroups.com
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

No comments: