[英]CakePHP beginner's question about views
I have finally quit the idea of learning Zend and instead i find CakePHP and CodeIgniter to be very impressive and simple to understand rather than cramming the strange global functions and configuration of index.php. 我终于放弃了学习Zend的想法,取而代之的是,我发现CakePHP和CodeIgniter非常令人印象深刻且易于理解,而不是塞满了奇怪的全局函数和index.php的配置。 Anyways, i wanted to ask you that CakePHP even spits out Html in sort of php language like :- 无论如何,我想问你CakePHP甚至以类似如下的php语言吐出Html:
<?= $html->css('default'); ?>
Do i have to necessarily use this syntax only? 我是否必须仅使用此语法? or can i use plain old HTML's link tag to load my stylesheet? 还是可以使用普通的旧HTML的链接标记来加载样式表? If i have to strictly follow these rules only, then how shall i use JQuery and such things in CakePHP? 如果仅必须严格遵循这些规则,那么我该如何在CakePHP中使用JQuery和类似的东西?
Thanks in advance :) 提前致谢 :)
You can use plain html in .ctp files. 您可以在.ctp文件中使用纯HTML。 However using the helpers provided by CakePHP will make your life a lot easier. 但是,使用CakePHP提供的帮助程序将使您的生活更加轻松。
As for using JavaScript (like jquery) 至于使用JavaScript(例如jquery)
echo $javascript->link('scriptfile');
Take a look at the cake book for more info: 看看蛋糕书了解更多信息:
http://book.cakephp.org/view/206/Inserting-Well-Formatted-elements http://book.cakephp.org/view/206/Inserting-Well-Formatted-elements
http://book.cakephp.org/view/349/Methods http://book.cakephp.org/view/349/Methods
In your view files, you can use anything that would be valid in a PHP file. 在视图文件中,可以使用任何在PHP文件中有效的东西。
<?php ... ?>
(don't ever do this: <? ... ?>
- IE will fail) <?php ... ?>
( 永远不要这样做: <? ... ?>
-IE将会失败) <script type=....> ... </script>
<script type=....> ... </script>
JS Using the css and javascript and html image helpers, if the path you specify does not include a '/' at the first char, CakePHP will look in webroot/css (or webroot/js or webroot/img). 使用css和javascript和html图像助手,如果您指定的路径的第一个字符不包含“ /”,则CakePHP将在webroot / css(或webroot / js或webroot / img)中查找。 If the first char of the path is a '/' then you can specify your own location, eg 如果路径的第一个字符为“ /”,则可以指定自己的位置,例如
echo $javascript->link('scriptfile'); // webroot/js/scriptfile.css
echo $javascript->link('scriptfile'); // webroot/js/scriptfile.css
(note the helper appends the filetype) echo $javascript->link('scriptfile'); // webroot/js/scriptfile.css
(注意帮助程序会附加文件类型)
echo $javascript->link('/myScripts/scriptfile'); // webroot/myScripts/scriptfile.css
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.