
首先,去PHPExcel官方网站下载PHPExcel,官方地址为;>
和框架无关,都是用 include或者require(或者include_once, require_once) __DIR__ '/加路径'
其中__DIR__是魔术变量,表示当前编辑的文件所在的目录的绝对路径
如果构造的时候就需要调用,通常写在前面,如
require_once 'filephp';
class
如果仅在特定方法中使用,可以在方法内 require
在js文件中使用相对路径的时候,这个相对路径是针对引用这个js文件的页面来说的
不同目录级别下的东西引用相同的js引起的相对路径是不同的。不过你可以写绝对路径。如dd\ff\kkjpg。当然,相对路径可以写\\kkjpg;\kkjpg等。
-- 前台使用了bootstrap框架技术,美化页面效果很显著(接下来计划有时间总结下bootstrap);并且应用HTML语义化文章结构,便于搜索引擎查找。
-- 后台打算使用ThinkPHP框架技术,这样可以使整体架构是MVC模式,结构化和模块化项目,并且使页面的html页码和php代码分离。
-- 最后计划实现页面的静态化,方便吸引搜索引擎爬虫的曝光率。
后台应用TP框架:
1)路径问题
由于TP框架是MVC架构,原理跟smaty模板的一样,contraller调用view下的模板,将模板html页面替换成php,然后包含到contraller下的控制页面,并且缓存在缓存夹cache中,访问contraller时会自动定位到cache下的缓存php文件。这样就引出了路径的问题,模板view下的相对路径需要些contraller的相对路径,建议用绝对路径。
介绍几个系统常量:
网站根目录地址 __ROOT__ 路径为根目录 /
当前路径下 __URL__
公共区: __PUBLIC__ 路径为 /Public/
当前应用入口 __APP__
还可以自己定义路径变量,方便项目开发。
例子:建议使用绝对路径代替相对路径
<link rel="stylesheet" href="__PUBLIC__/css/bootstrapcss"> 代替<link rel="stylesheet" href="//Public/css/bootstrapcss">
<img src="__ROOT__/admin/Home/View/Public/images/logopng"/>代替 <img src="////admin/Home/View/Public/images/logopng"/>
2)数据库的连接展示,例子效果如下:
(1)ThinkPHP/Conf/conversationphp中配置数据库连接参数:
/ 数据库设置 /
'DB_TYPE' => 'mysql', // 数据库类型
'DB_HOST' => 'localhost', // 服务器地址
'DB_NAME' => 'yanhui', // 数据库名
'DB_USER' => 'root', // 用户名
'DB_PWD' => '', // 密码
'DB_PORT' => '', // 端口
(2)Contraller中新建控制news页面NewsContrallor:
<php
namespace Home\Controller;
use Think\Controller;
class NewsController extends Controller {
public function index(){
$user=M('news');
$this->rows=$user->order('id')->select();
$this->display();
}
public function add(){
$this->display();
}
public function insert(){
$this->display();
}
public function delete(){
$this->display();
}
public function edit(){
$this->display();
} public function update(){
$this->display();
}
}
(3)View下新建模板页面News/indexhtml(用了bootstrap展示前端)
<div class="container">
<div class="panel panel-primary">
<div class="panel-heading">新闻展示</div>
<div class="panel-body">
<table class="table table-bordered table-striped">
<tr>
<th>id</th>
<th>标题</th>
<th>概要</th>
<th>上墙</th>
<th>时间</th>
<th>栏目</th>
</tr>
<volist name='rows' id='row'>
<tr>
<td>{$rowid}</td>
<td>{$rowtitle}</td>
<td>{$rowabstract}</td>
<td>{$rowshelf}</td>
<td>{$rowregtime|date='Y-m-d',###}</td>
<td>{$rownewsclassId}</td>
</tr>
</volist>
</table>
</div>
</div>
</div>
(根据这个例子,依次实现news模块的增删改查方法)
ThinkPHP redirect 方法
ThinkPHP redirect 方法可以实现页面的重定向(跳转)功能。redirect 方法语法如下:
$this->redirect(string url, array params, int delay, string msg)
参数说明:
参数
说明
url 必须,重定向的 URL 表达式。
params 可选,其它URL参数。
delay 可选, 重定向延时,单位为秒。
msg 可选,重定向提示信息。
ThinkPHP redirect 实例
在 Index 模块 index 方法中,重定向到本模块的 select *** 作:
class IndexAction extends Action{
public function index(){
$this->redirect('select', array('status'=>1), 3, '页面跳转中~');
}
}
重定向后得到的 URL 可能为exphp/Index/select/status/1
由于该方法调用了 U 函数来生成实际的 URL 重定向地址,因此重定向后的 URL 可能因配置不同而有所不同:
隐藏了入口文件 indexphp 的
5idevcom/Index/select/status/1
隐藏了入口文件 indexphp 且设置了伪静态的
hom/Index/select/status/1html
一些常用的 redirect 重定向例子:
// 不延时,直接重定向
$this->redirect('select', array('status'=>1));
// 延时跳转,但不带参数,输出默认提示
$thi >
以上就是关于thinkphp3.1中的phpexcel导入怎么用全部的内容,包括:thinkphp3.1中的phpexcel导入怎么用、thinkphp 入口文件index.php、thinkphp 怎么使用controller等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)