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 i开发者_StackOverflow社区mpressive and simple to understand rather than cramming the strange global functions and configuration of index.php. Anyways, i wanted to ask you that CakePHP even spits out Html in sort of php language like :-
<?= $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? If i have to strictly follow these rules only, then how shall i use JQuery and such things in CakePHP?
Thanks in advance :)
You can use plain html in .ctp files. However using the helpers provided by CakePHP will make your life a lot easier.
As for using JavaScript (like 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/349/Methods
In your view files, you can use anything that would be valid in a PHP file.
- In your mind, just think HTML and PHP at the same time:
- PHP inside
<?php ... ?>
(don't ever do this:<? ... ?>
- IE will fail) - JS inside
<script type=....> ... </script>
- HTML inside: ...well, not inside anything.
- You can include inline CSS or CSS files with HTML or via helper.
- Even PHP includes can be used.
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). If the first char of the path is a '/' then you can specify your own location, e.g.
echo $javascript->link('scriptfile'); // webroot/js/scriptfile.css
(note the helper appends the filetype)echo $javascript->link('/myScripts/scriptfile'); // webroot/myScripts/scriptfile.css
精彩评论