0
votes

In looking at CookBook and some code examples, I'm told to believe that including $this->App->js(); in view.ctp would output JS [CDATA] but it spits a fatal error:

Fatal error: Call to a member function js() on a non-object in /Users/work/Dropbox/Websites/cake-cart/app/View/Layouts/default.ctp on line 32

A look in the log only shows dispatch error related to:

2012-11-26 13:15:39 Error: [MissingControllerException] Controller class CssController could not be found. //app/webroot/index.php(92): Dispatcher->dispatch(Object(CakeRequest), Object(CakeResponse)) {main}

I can't trace it. Maybe not enough system knowledge. Anyone with more experience pitch in?

The only things about my setup - not sure if it's related - is that I'm using a bootstrap theme and have set the theme in AppController APP/View/Themed/Bootstrap/ with

class AppController extends Controller {

public $theme = "Bootstrap";

... 

which seems to serve the site up ok ... but for this js() fatal error and that CSSController error in the log.

Any help would be appreciated, thanks.

** EDITED **

Ok ... I'm getting this figure out. Looks like the example I'm referencing created a public function in APP/View/Helper/AppHelper.php that looks like this:

class AppHelper extends Helper {

public $helpers = array(
    'Html',
    'Form',
    'Session',
    'Js',
);

public function js() {
    $shop = array();
    $shop['basePath'] = Router::url('/');
    $shop['params'] = array(
        'controller' => $this->params['controller'],
        'action' => $this->params['action'],
    );
    return $this->Html->scriptBlock('var Shop = ' . $this->Js->object($shop) . ';');
}
}

... so that makes sense why it would be $this->App->js() in default.ctp .... but I'm still getting an error

1
Nah. Warning (512): Method HtmlHelper::js does not exist [CORE/Cake/View/Helper.php, line 179] - tremendusapps
Did you include the helpers in the top of your appController class? var $helpers = array('Html', 'Javascript'); - Tim Joyce
Well, no. I don't think that's the problem because the example I'm working from doesn't either. At least not in this way. FYI, the helper is 'Js' anyway, not Javascript. - tremendusapps
The example doesn't do it because it is enabled by default. However, if you have redeclared $helpers somewhere (say, the controller) and not included the Js helper inside the redeclaration then it will override the default. - Tim Joyce

1 Answers

0
votes

Ok, I moved the offending code from AppHelper to my own Helper and called that helper from the main page and it's all good. I never did figure out why $this->App->js(); didn't work. Ah well...many ways to do something sometimes.