简体   繁体   English

Cakephp包含Java的自定义帮助程序

[英]Cakephp Custom Helper containing Javascript

I created a helper for my cakephp project. 我为cakephp项目创建了一个助手。 The helper creates a custom input field with a lot of complicated Javascript running at the backend of the input field. 助手会创建一个自定义输入字段,并在输入字段的后端运行许多复杂的Javascript。 I get an error when I try to run my project though. 但是,当我尝试运行项目时出现错误。

Code in my DropDownHelper.php file: 我的DropDownHelper.php文件中的代码:

class DropDownHelper extends AppHelper {
?>
<!-- JQUERY LOADING -->
<script type="text/javascript"     src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jqueryui/1.8.8/jquery-ui.min.js"></script>
<script>
  jQuery.curCSS = jQuery.css;
</script>
<!-- JQUERY LOADING -->

<!-- STYLE SHEET -->
<style>
  Some custom styles.
</style>
<!-- STYLE SHEET -->

<!-- SCRIPT -->
<script >
  My main Script.
</script>
<!-- SCRIPT -->

<!-- HTML -->
  Some HTML
<!-- HTML -->
<?php
}
?>

Part of my Controller: 我的控制器的一部分:

class PortfoliosController extends AppController {
public $components = array('RequestHandler');
public $helpers  = array('DropDown');

And finally, my View: 最后,我的观点:

echo $this->DropDown->input('Clients');

The error says: Parse error: syntax error, unexpected ';', expecting T_FUNCTION in /...../app/View/Helper/DropDownHelper.php on line 34 该错误说:解析错误:语法错误,意外的';',在第34行的/...../app/View/Helper/DropDownHelper.php中期望T_FUNCTION

Lime 34 is Where I close off the php, right before my scripts, css, and html. Lime 34是我关闭php的地方,就在我的脚本,css和html之前。 ie

class DropDownHelper extends AppHelper {
?>

Line 34 is the line that says "?>". 第34行是显示“?>”的行。

Thanks! 谢谢!

So I figured this out myself. 所以我自己弄清楚了。 All that has to happen is this: 所有要做的事情是这样的:

class DropDownHelper extends AppHelper {
public function functionName()
  {
    All the scripts, css, html
  }
}

So basically you have to put everything inside a function. 因此,基本上,您必须将所有内容放入函数中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM