ThinkPHP,__PUBLIC__載入CSS,JS失敗

來源:互聯網
上載者:User

最近在學ThinkPHP,過程當然不是一番風順,一兩天之後,總算有點感覺了:):

我初始化下我的項目目錄結構:

------/www/

----------/www.myapp.com/

-------------------------/myadmin/<!--項目後台-->

             /ThinkPHP/<!--TP檔案夾-->

                                   /index.php<!--前台入口檔案-->

                                   /admin.php<!--後台入口檔案-->

             /myapp/<!--項目前台-->

重點是myapp的配置,myamin原理跟myapp一樣一樣的

我不想按照官網的那樣,把Public檔案夾放根目錄,我想一個應用對應該應用的Public,也就是說,對於,myapp,我的Public的路徑是這樣的:

/www/www.myapp.com/myapp/Public/

/www/www.myapp.com/index.php的配置如下:

 

View Code

<?php    //引入架構統一入口    define('APP_DEBUG',true);    define('THANK_PATH','./ThinkPHP/');    define('APP_PATH','./myapp/');    define('APP_NAME','myapp');    require(THANK_PATH.'ThinkPHP.php');?>

 

 

/www/www.myapp.com/myapp/index.php配置如下

View Code

<?php//定義項目名稱和路徑define('APP_NAME', 'myapp');define('APP_PATH', './');// 載入架構入口檔案require( "../ThinkPHP/ThinkPHP.php");

 

/www/www.myapp.com/myapp/Config/config.php配置如下:

View Code

<?php//array('__PUBLIC__'=>'/myapp'這塊配置一定要是'/myapp'//如果配置的是array('__PUBLIC__'=>'myapp'//利用http://www.myapp.com/myapp/訪問會出現載入不了CSS,js等//'/myapp'是回myapp上一層路徑,另外一個'myapp'是當前路徑return array(    'DB_TYPE'=>'mysql',    'URL_MODEL'=>1,    'DB_HOST'=>'localhost',    'DB_NAME'=>'myapp',    'DB_USER'=>'root',    'DB_PWD'=>'',    'DB_PORT'=>'3306',    'DB_PREFIX'=>'ma_',    'URL_MODEL'=>0,    'TMPL_PARSE_STRING'=>array('__PUBLIC__'=>'/myapp'),);?>

其他的

/www/www.myapp.com/myapp/Lib/Action/Index.class.php的Index()方法裡,$this->display();就可以調用模板了...

比如Index模組的模板應該如下:

/www/www.myapp.com/myapp/Tpl/Index/index.html

/www/www.myapp.com/myapp/Tpl/Index/header.html

/www/www.myapp.com/myapp/Tpl/Index/footer.html

header裡面可以通過以下語句調用js,css:

View Code

<link href="__PUBLIC__/Public/css/a.css"  rel="stylesheet" type="text/css" /><script src="__PUBLIC__/Public/js/a.js" type="text/javascript"></script><script src="__PUBLIC__/Public/js/b.js"  type="text/javascript" ></script>

index.html引入header.html:<include file="header"/>

其他模組,比如添加(add)

/www/www.myapp.com/myapp/Lib/Action/Add.class.php的Index()方法裡,$this->display();就可以調用模板了...

比如Index模組的模板應該如下:

/www/www.myapp.com/myapp/Tpl/Add/index.html

值得一提的是,在這個index.html裡面可以調用Index模組的header.html:<include file="Index:header">

 

 

差不多就這些了,linux下貌似對大小寫敏感,大家注意!

 

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.