ThinkPHP学习总结

algorain
  1. http://www.test.com/index.php?m=home&c=index&a=add, 当想要访问application中home目录中的controller的主函数中其他方法时,m对应home目录,c对应的是controller中的php文件,indexController.class.php就是index,如果是userContriller.class.php文件,则对应的就是user,a对应的是php文件中的方法,index方法就写index,add方法就写a=add

  2. 后台管理应该在Application中创建一个Admin的文件夹,里面包含Conf,Controller,view这三个文件夹。在Controller创建class类,而不是PHP文件,类中有use和namespace 变量。

  3. 关于layer的使用,在没有碰到layer时弹层是一个很简单但很麻烦的东西,layer只需要到官网下载绿色版,然后放在项目的js文件夹中,使用的时候按照官网的文档直接的 <script>中调用相应的函数即可。

  4. 有时文件中js方法做出修改而游览器没有变化,可能是游览器有了缓存,需要使用ctrl+F5刷新一下。

  5. Ajax的调试可以通过谷歌游览器的F12来查看network的发送情况。

  6. 在使用layer弹窗时记得加exit() if(!username) { dialog.error('用户名不能为空'); exit();}

  7. 在新建一个class的Contrller时,要记得继承extends Controller,并且在头部添加名称空间namespace Admin\Controller;use Think\Controller;

  8. 在html页面中遍历时

1
2
3
4
5
6
7
8
9
10
11
12
<volist name="left_menu" id="menu">

<li class="{$menu.show}">
<a href="{$menu.href}">

<i class="menu-icon fa fa-{$menu.icon}"></i>
<span class="menu-text"> {$menu.name} </span>
</a>

<b class="arrow"></b>
</li>
</volist>
  1. thinkphp中向html页面传值时:$this->assign('left_menu',$left_menu);

  2. html中的if判断,在condition属性中可以支持eq等判断表达式,同上面的比较标签,但是不支持带有”>”、”<”等符号的用法,因为会混淆模板解析,eq或者 equal

1
2
3
<if condition="$list.state == 1">
<span class="label label-sm label-info arrowed arrowed-righ">True</span>
</if>

2017-03-01 16:33:57 星期三 11. 在使用get请求和post请求时,路径写了我的 Controller中的函数,但总是提示模板不存在研究了很长时间,发现是show_list.html找不到,而我的函数名也是show_list,然后在view中新建了一个show_list.html就好了,原来thinkphp中每个函数都必须要有一个对应的html文件 12. thinkphp中的模糊查询语句

1
2
$like['site'] = array('like','%'.$select.'%');
$list = $this->_db->where($like)->select();
  1. thinkphp中的重定向 $this->redirect('/admin.php?c=login');
  • Title: ThinkPHP学习总结
  • Author: algorain
  • Created at: 2017-03-07 20:12:03
  • Updated at: 2023-05-14 21:39:50
  • Link: http://www.rain1024.com/2017/03/07/php-article64/
  • License: This work is licensed under CC BY-NC-SA 4.0.
 Comments
On this page
ThinkPHP学习总结