定义自定义变量并在视图部分中直接调用变量 [英] define custom variables and direct call the variables in view part

查看:150
本文介绍了定义自定义变量并在视图部分中直接调用变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要做的是在 config 目录中创建一个文件,如 my_custom_settings.php ,并调用定义的变量










$ b b

  define('TEMPLATE_DIR','assets / front'); 

并直接在HTML中查看:

 < link href =<?= TEMPLATE_DIR?  /stylesheet/style.css> 

或任何其他替代解决方案



PS:现在我使用 base_url()访问路径

解决方案

个人我扩展/core/helpers/url_helper.php,默认值是 site_url(),base_url(),current_url(); ...我只是延长了 base_static_url();



所以放在core / helpers / url_helper。 php:

  if(!function_exists('base_static_url'))
{
function base_static_url b $ b {
$ CI =& get_instance();
return $ CI-> config-> slash_item('base_static_url');
}
}

那么在config.php文件中,行:

  $ config ['base_url'] =http://mysite.com/ 
$ config ['base_static_url'] =http://mysite.com/static/; //路径到静态资源文件夹

那么你可以调用静态资源:

 < img src =<?php echo base_static_url();?> img / myimage.png/> 


What I want to do is creating a file like my_custom_settings.php in config directory and call the defined variable in view part.

let's say in my_custom_settings.php:

define('TEMPLATE_DIR', 'assets/front');

and in view part direct in HTML:

<link href="<?=TEMPLATE_DIR?>/stylesheet/style.css">

or any other alternative solution??

PS: Now I am using base_url() to access the path

解决方案

personally i extend the /core/helpers/url_helper.php , defaults are site_url() , base_url(), current_url(); etc ... i just extended that for having base_static_url();

so put in core/helpers/url_helper.php:

if ( ! function_exists('base_static_url'))
{
    function base_static_url()
    {
        $CI =& get_instance();
        return $CI->config->slash_item('base_static_url');
    }
}

then in config.php file you just add 1 more line:

$config['base_url'] = "http://mysite.com/";
$config['base_static_url'] = "http://mysite.com/static/"; //path to your static resources folder

then you can call static resources using :

<img src="<?php echo base_static_url();?>img/myimage.png"/>

这篇关于定义自定义变量并在视图部分中直接调用变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆