蛋糕图像未显示在视图中.ctp



我想使用 CakePHP 在我的页面上插入一个评级星。图像的路径在javascript中,如下所示。但是,图像没有显示。

$.fn.jRating = function(op) {
        var defaults = {
            /** String vars **/
            bigStarsPath : '../img/icons/stars.png' , // path of the icon stars.png
            smallStarsPath : '../img/icons/small.png', // path of the icon small.png
            phpPath : 'app/jRating.php', // path of the php file jRating.php
            type : 'big', // can be set to 'small' or 'big'

我已经尝试使用<?php echo $this->webroot; ?>img/icons/stars.png. 但没有运气。 谁能帮我。

我在我的布局中经常做的是放置一个像这样的javascript变量:

<script type="text/javascript">
var root = '<?php echo $this->Html->url('/'); ?>';
</script>

这样,您始终可以引用项目的根目录。

然后你的代码将是:

$.fn.jRating = function(op) {
    var defaults = {
        /** String vars **/
        bigStarsPath : root+'img/icons/stars.png' , // path of the icon stars.png
        smallStarsPath : root+'img/icons/small.png', // path of the icon small.png
        phpPath : 'app/jRating.php', // path of the php file jRating.php
        type : 'big', // can be set to 'small' or 'big'

我在这里看到的问题是phpPath指向app/,我认为这是不可见的,因为项目的根设置为app/webroot/。

因此,要么将文件jRating.php移动到app/webroot/,要么将逻辑移动到控制器的操作中。

请改用$this->Html->image()。该函数检索路由并将其添加到位于 app/webroot/img 中的映像。

文档:http://book.cakephp.org/2.0/en/core-libraries/helpers/html.html#HtmlHelper::image

使用 html 帮助程序,只需将 URL 设置为如下所示:

../folder-name-in-webroot/file-name

最新更新