CakePHP 主题?

发布于 2024-12-10 20:29:35 字数 1907 浏览 2 评论 0原文

我尝试创建一个基于主题的 CakePHP 应用程序。我使用最新版本 CakePHP 2.0.0

我的应用程序由文件

/app/Controller/AppController.php

class AppController extends Controller
{
    public $helpers = array('Html', 'Session', 'Form');

    public function beforeFilter()
    {
        $this->setupTheme();
    }

    private function setupTheme()
    {
        $this->viewClass = 'Theme';
        $this->theme = 'Mars';
        $this->layout = 'admin';
    }
}

/app/Controller/LanguagesController.php

class LanguagesController extends AppController
{
    public $name = "Languages";

    public function index()
    {}
}

/app/View/Themed/Mars/Languages/index.php

// Currently Empty

/app/View/ 组成Themed/Mars/Layouts/admin.ctp

<?php echo $this->Html->docType('xhtml-strict'); ?>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <?php echo $this->Html->charset(); ?>
    <meta name="author" content="Nikos Merianos" />

<title><?php echo $title_for_layout; ?></title>

    <?php
        echo $this->Html->meta('icon');
        echo $this->Html->css('amdin.css');
?>
</head>

<body>
    <?php 
        echo $this->Session->flash(); 
        echo $content_for_layout;
        echo $this->element('sql_dump');
        echo $scripts_for_layout;
    ?>
</body>
</html>

/app/View/Themed/Mars/webroot/css/admin.css

body
{
    background: #FA0;
}

我现在的问题

为什么代码进入 Layout 文件夹下的 admin.ctp 第 11 行(echo $this->Html->css('amdin.css');) 返回以下结果:

<link rel="stylesheet" type="text/css" href="/mars/css/amdin.css" />

问题是链接不正确。 CSS 文件未加载,因为该路径中不存在该文件。有什么想法吗?

I try to create a CakePHP application based on themes. I using the latest version CakePHP 2.0.0

My application consists from that files

/app/Controller/AppController.php

class AppController extends Controller
{
    public $helpers = array('Html', 'Session', 'Form');

    public function beforeFilter()
    {
        $this->setupTheme();
    }

    private function setupTheme()
    {
        $this->viewClass = 'Theme';
        $this->theme = 'Mars';
        $this->layout = 'admin';
    }
}

/app/Controller/LanguagesController.php

class LanguagesController extends AppController
{
    public $name = "Languages";

    public function index()
    {}
}

/app/View/Themed/Mars/Languages/index.php

// Currently Empty

/app/View/Themed/Mars/Layouts/admin.ctp

<?php echo $this->Html->docType('xhtml-strict'); ?>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <?php echo $this->Html->charset(); ?>
    <meta name="author" content="Nikos Merianos" />

<title><?php echo $title_for_layout; ?></title>

    <?php
        echo $this->Html->meta('icon');
        echo $this->Html->css('amdin.css');
?>
</head>

<body>
    <?php 
        echo $this->Session->flash(); 
        echo $content_for_layout;
        echo $this->element('sql_dump');
        echo $scripts_for_layout;
    ?>
</body>
</html>

/app/View/Themed/Mars/webroot/css/admin.css

body
{
    background: #FA0;
}

My problem now

Why the code into admin.ctp under Layout folder in line 11 (echo $this->Html->css('amdin.css');) return the following result :

<link rel="stylesheet" type="text/css" href="/mars/css/amdin.css" />

The problem is that link is incorect. The CSS file is not loaded because does not exists into that path. Any idea please ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

浅听莫相离 2024-12-17 20:29:35

检查你的拼写...

/app/View/Themed/Mars/webroot/css/admin.css

<link rel="stylesheet" type="text/css" href="/mars/css/amdin.css" />

当您包含 CSS 文件时,“admin”中的字母被调换了...

Check your spelling...

/app/View/Themed/Mars/webroot/css/admin.css

<link rel="stylesheet" type="text/css" href="/mars/css/amdin.css" />

You have letters in 'admin' transposed when you include your CSS file...

半世蒼涼 2024-12-17 20:29:35

admin 应该是 admin,而不是 amdin

编辑:就像 Farray 所说。

admin should be admin, not amdin

Edit: like Farray said.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文