科哈纳为什么不';你不看我的CSS吗?

科哈纳为什么不';你不看我的CSS吗?,css,kohana,Css,Kohana,我的网站是www.kipclip.com,它运行在Kohana上。我创建了一个新的租赁页面。但它不会占用我的CSS和JS文件。我试图找出这是如何包含的,或者Kohana是否有一种特殊的方法来实现这一点。但仍然没有成功。您对此有什么想法吗?一种快速而肮脏的方法是在视图中使用常规html脚本和样式标记添加脚本和样式的名称,然后继续执行。 但是,如果您不喜欢快速和肮脏,并且更喜欢做得更好、更具体,如果您使用Kohana 3.2,您可以执行以下操作。我没有在较旧或较新的版本上尝试过此功能,因此它可能在这

我的网站是www.kipclip.com,它运行在Kohana上。我创建了一个新的租赁页面。但它不会占用我的CSS和JS文件。我试图找出这是如何包含的,或者Kohana是否有一种特殊的方法来实现这一点。但仍然没有成功。您对此有什么想法吗?

一种快速而肮脏的方法是在视图中使用常规html脚本和样式标记添加脚本和样式的名称,然后继续执行。

但是,如果您不喜欢快速和肮脏,并且更喜欢做得更好、更具体,如果您使用Kohana 3.2,您可以执行以下操作。我没有在较旧或较新的版本上尝试过此功能,因此它可能在这些版本中工作,也可能不工作(如果您尝试将其移植到该版本,请咨询您希望移植的相关版本):

那么,这是如何工作的呢?请记住,
application.php
类是派生所有其他控制器类的基本控制器类通过实现对基本控制器的这种绑定,每个派生控制器都可以访问可用的脚本、样式等。因此,该控制器调用的每个关联视图也可以访问这些变量。

现在,要访问视图中的这些变量:

例如,模板PHP文件:
/application/views/template.PHP

如果它是这样定义的(使用PHP短标记-但是):



在视图文件夹中的kohana中,我们有.xhtml文件,我创建了view.xhtml文件作为其他视图文件。在views/common文件夹中有一个layout.xhtml文件。它包含所有CSS和JS。在其他视图文件中,没有额外添加layout.xhtml文件编码。因此,我没有添加任何额外的代码来将layout.xhtml文件包含到我的view.xhtml文件中。有办法吗?好的,我想我现在明白你的问题了。在您的例子中,
layout.xhtml
是模板视图。在为新页面创建的视图中,例如
rent.xhtml
,您可以在内容中包含
标记以及相关的源。但是,为了尽量减少猜测,可以通过编辑您的问题来发布
rent.xhtml
文件的内容。在这里您可以下载3个文件…dangov.com/3-files。rar@TrajkoDangov,我拿到了,我现在正在看。您应该从您的网站中删除该文件:
3-files.rar
。)可以您的文件确认
layout.xhtml
是您的模板。其他的档案让我知道发生了什么。对于您的第一个问题:Kohana没有一个内置的方法可以简单地将脚本或样式添加到某个视图或页面中。如果样式或脚本是全局的(即必须在任何地方访问),则可以将其放入模板中。如果不是并且特定于一个页面,则有两个选项:将样式/脚本放在该特定视图中,或将其绑定到控制器并从视图中访问脚本名称。
/**
*      /application/classes/controller/application.php
*/
abstract class Controller_Application extends Controller_Template {

    public function before() {
        parent::before();

        if($this->auto_render) {
            //Initialize empty values for use by ALL other derived classes
            $this->template->site_name = '';//this is a psuedo-global set in this class
            $this->template->title = '';//this too is set by the controller and action
            $this->template->content = ''; //this is set by the controller and action
            $this->template->styles = array();
            $this->template->scripts = array();
            $this->template->admin_scripts = array();
        }
    }    

    /**
     * The after() method is called after your controller action.
     * In our template controller we override this method so that we can
     * make any last minute modifications to the template before anything
     * is rendered.
     */
    public function after() 
    {
        if ($this->auto_render) {

            //set the CSS files to include
            $styles = array(
                'style1', //the css file with all the defaults for the site
                'jquery-library-css'
            );


            //set the JavaScript files to include
            $scripts = array(
                'myscript1',
                'myscript2'
            );


            $admin_scripts = array(
                'jquery-admin-functions',
            );
            //now, merge all this information into one so that it can be accessed
            //by all derived classes:
            $this->template->styles = array_merge($this->template->user_styles, $user_styles);
            $this->template->scripts = array_merge($this->template->user_scripts, $user_scripts);
            $this->template->admin_scripts = array_merge($this->template->admin_scripts, $admin_scripts);
        }

        //bind the site_name to the template view
        $this->template->site_name = 'My Site Name';


        //OLD WAY shown below:
        View::set_global('site_name', 'My Site Name'); //set the site name

        //now that everything has been set, use parent::after() to finish setting values
        //and start rendering
        parent::after();
    }

}
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd>
<html>
<head>
    <meta charset='utf-8'/>
    <script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
<?php
/**
 * Link the css files stored in the `static` folder from the project root.
 * This will vary depending on how you have your files saved.
 */
foreach($user_styles as $style) : ?>
    <link rel="stylesheet" href="<?php echo URL::base() . 'static/css/' . $style ?>.css" type="text/css"/>
<?php endforeach; ?>
    <?php //Create AND set a dynamic page title - much like Facebook ?>
    <title><?php echo $site_name; if(!empty($title)) echo ' - ' . $title; ?></title>
</head>
<body>

<!-- Fill in the body with HTML, PHP - whatever you want -->

<?php
/**
 * Now, load the scripts:
 * According to Yahoo, for better site performance, all scripts should be loaded after the body has been loaded
 */

foreach($user_scripts as $script) : ?>
    <script src="<?php echo URL::base() . 'static/js/' . $script; ?>.js" type="text/javascript"></script>
<?php endforeach; ?>
</body>
</html>