English 中文(简体)
守则的识别和布局? [闭门]
原标题:CodeIgniter and layouts? [closed]
最佳回答

我的仇恨模板如Smarty或

采用我自己的方式执行类似于泽德的布局。

Add hook /application/hooks/Layout.php:

<?php

if (!defined( BASEPATH ))
    exit( No direct script access allowed );

/**
 *
 */
class Layout {

    function render() {

        global $OUT;
        $CI = & get_instance();
        $output = $CI->output->get_output();
        if (!isset($CI->layout)) {
            $CI->layout = "default";
        }
        if ($CI->layout != false) {
            if (!preg_match( /(.+).php$/ , $CI->layout)) {
                $CI->layout .=  .php ;
            }

            $requested = BASEPATH .  ../application/layouts/  . $CI->layout;
            $default = BASEPATH .  ../application/layouts/default.php ;

            if (file_exists($requested)) {
                $layout = $CI->load->file($requested, true);
            } else {
                $layout = $CI->load->file($default, true);
            }

            $view = str_replace("{content}", $output, $layout);
            $view = str_replace("{title}", $CI->title, $view);

            $scripts = "";
            $styles = "";
            $metas = "";
            if (count($CI->meta) > 0) {     // Массив с мета-тегами
                $metas = implode("
", $CI->meta);
            }
            if (count($CI->scripts) > 0) {  // Массив со скриптами
                foreach ($CI->scripts as $script) {
                    $scripts .= "<script type= text/javascript  src= " . base_url() . "js/" . $script . ".js ></script>";
                }
            }
            if (count($CI->styles) > 0) {   // Массив со стилями
                foreach ($CI->styles as $style) {
                    $styles .= "<link rel= stylesheet  type= text/css  href= " . base_url() . "css/" . $style . ".css  />";
                }
            }

            if (count($CI->parts) > 0) {    // Массив с частями страницы
                foreach ($CI->parts as $name => $part) {
                    $view = str_replace("{" . $name . "}", $part, $view);
                }
            }
            $view = str_replace("{metas}", $metas, $view);
            $view = str_replace("{scripts}", $scripts, $view);
            $view = str_replace("{styles}", $styles, $view);
            $view = preg_replace("/{.*?}/ims", "", $view); // Подчищаем пустые неподгруженные части шаблона
        } else {
            $view = $output;
        }
        $OUT->_display($view);
    }

}

?> 

之后,在你/申请/没收/没收/没收/没收/没收工作中可找到hoo子:

$config[ enable_hooks ] = TRUE;

之后加上/申请/没收/hoo。 php:

$hook[ display_override ][] = array( class  =>  Layout ,
     function  =>  render ,
     filename  =>  Layout.php ,
     filepath  =>  hooks 
);

创建文件夹/申请/支出/

建立档案/申请/延误/违约:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
    <head>
        <title>{title}</title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        {metas}
        {scripts}
        {styles}
        <link rel="icon" href="<?= base_url() ?>favicon.ico" type="image/x-icon" />
        <link rel="shortcut icon" href="<?= base_url() ?>favicon.ico" type="image/x-icon" />
    </head>
    <body>
        <div class="head">
            {head}
        </div>
        <div class="content">
            {content}
        </div>
    </body>
</html>

用控制器使用:

class main extends MY_Controller {

    function __construct() {
        parent::Controller();
        $this->parts[head] = $this->load->view("frontend/global/header.php", null, true);
        $this->scripts = array("JQuery/jquery-1.4.2.min", "JQuery/form", "Core", "Frontend");
        $this->styles = array("style");
        $this->title = "Blah blah";
    }

    function index() {
        $this->load->view( frontend/index.php );
    }


}
问题回答

过去,我利用这个网站:http://williamsconcepts.com/ci/codeigniter/libraries/template/“rel=“nofollow n或eferer”>Template Library。 文件:

The Template library, written f或 the CodeIgniter PHP-framew或k, is a wrapper f或 CI’s View implementation. Template is a reaction to the numerous questions from the CI community regarding how one would display multiple views f或 one controller, and how to embed “views within views” in a standardized fashion. In addition, Template provides extra Views loading capabilities, the ability to utilize any template parser (like Smarty), and sh或tcuts f或 including CSS, JavaScript, and other common elements in your final rendered HTML.

具体来说,检查图书馆 。 允许你在你的控制者中提出这样的内容:

$this->template->add_js( js/YourJavascriptFile.js );

$this->template->add_js( alert("Hello!"); ,  embed );

Echo $_scripts in your template (preferably in the <head> section) to utilize JavaScript added via this method.

同样,你也可以与你的特别安全局一样:

$this->template->add_css( css/main.css );
$this->template->add_css( #logo {display: block} ,  embed ,  print );

页: 1

希望会有所帮助。

I had the same problem with finding a advance layout library as well, so i wrote my own version which also fits your need (using YAML file).

Features

  • Manage layouts, page title, metas, css and js with YAML file for cleaner and lighter controllers.
  • Default configs can be overwritten in controller configs. So that you can split your css and js into smaller files for more flexible design.
  • Combine and minify css and js files in production mode for faster page loading.

Usage

  // in the controller
  $this->view->render();

这一校准将来自你的阿马列马会会的布局、观点、页标题、 c、 j、 met。

Documentation

download

  • Download source code from Github




相关问题
Very basic WPF layout question

How do I get this listbox to be maxiumum size, i.e. fill the group box its in. I ve tried width="auto" Height="auto", width="stretch" Height="stretch" annoyingly at the moment, it dynamicly sizes to ...

How to align the text to top of TextView?

How to align the text to top of a TextView? Equivalent Android API for Swings setInsets()? that is top of text should start be in (0,0) of TextView <?xml version="1.0" encoding="utf-8"?> <...

Centring a flow in Shoes

Can I center the contents of a flow in Shoes? I know that a paragraph can be centred like: para Centred paragrpah , :align=> center However, this does not work with flows: flow(:align=> ...

Overlaying with CSS

I want to load a website in an iframe, and overlay the website with some hints about the website that is shown. However, i got stuck at the point that the website has a variable passive white space at ...

How do you normally make a program look beautiful? [closed]

How can I make an Application look nice and not like an amateur pulled it together? I mean graphic-wise. Is there some sort of book you can read regarding beautiful program layouts, etc? I put this ...

热门标签