English 中文(简体)
代码化代码化器, 一个从缓存文件夹获取类似配置的阵列的简单方法Name
原标题:Codeigniter a simple way to get config-like array from cache folder

I have some data in array format which I wrote to a file in application/cache folder. Format is:

$extra_data[ some_key ] =  some_data ;

它与网站配置无关, 所以我不想将其放入 < code> application/ config 。 然而, 在某些情况下, 我必须在控制器或模型中找到这个 < code> $extra_ data

我所做的是,

(1) (1) 定义控制器中的变量

class pages_model extends CI_Model
{
  var $extra_data;

(2) 插入缓存文件,并将其与以上变量联系起来,

  function __construct()
  {
     parent::__construct();
     @include_once APPPATH . "cache/extra_data.php";
     $this->extra_data = $extra_data;
  }

3) 获得类变量作为变量,然后使用它:

function func_name()
{
  $extra_data = $this->extra_data;

这就是我使用的方法,但我不确定这是正确或有效的方法。

感谢任何想法和支持。

最佳回答

Why dont you create a file in config folder that is called cache.php in the file just put the data like this

$config[ some_key ] =  some_data ;

然后您可以在构造中使用此代码

    $this->load->config( cache , TRUE);
    $extra_data = $this->config->item( cache )

我知道它不是配置的东西, 但是既然你把它们放在分开的档案里, 使用它们比较好

问题回答

用缓存扩展加载器库如何?

然后,你可以把它称为:

$this->load->cache( extra_data );

<强势>图书馆/MY_Loader.php

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

class MY_Loader extends CI_Loader {

    /* Load custom cache values */
    function cache($str =   ) {

        $CI =& get_instance();

        $data = array();
        $path = APPATH . "cache/{$str时 时.php";
        if (file_exists($path)) {

            include $path;
            $data = $extra_data;

        时 时

        $CI->$str = $data;

    时 时

时 时





相关问题
Template Classes in C++ ... a required skill set?

I m new to C++ and am wondering how much time I should invest in learning how to implement template classes. Are they widely used in industry, or is this something I should move through quickly?

JSON with classes?

Is there a standardized way to store classes in JSON, and then converting them back into classes again from a string? For example, I might have an array of objects of type Questions. I d like to ...

Object-Oriented Perl constructor syntax and named parameters

I m a little confused about what is going on in Perl constructors. I found these two examples perldoc perlbot. package Foo; #In Perl, the constructor is just a subroutine called new. sub new { #I ...

Passing another class amongst instances

I was wondering what is the best practice re. passing (another class) amongst two instances of the same class (lets call this Primary ). So, essentially in the constructor for the first, i can ...

Where can I find object-oriented Perl tutorials? [closed]

A Google search yields a number of results - but which ones are the best? The Perl site appears to contain two - perlboot and perltoot. I m reading these now, but what else is out there? Note: I ve ...

热门标签