举例:文章--分类
controller/Article.php
<?php
namespace app\admin\controller;
use think\Controller;
use think\Loader;
use app\admin\model\Article as ArticleModle;
/**
* Description of Article
*
* @author Ivan
*/
class Article extends Controller {
public function lst() {
// $list = db('article')->alias('a')->join('cate c' ,'c.id=a.cateid')->field('a.*,c.catename')->order('id')->paginate(4);
$list = ArticleModle::paginate(4);
$this->assign('list', $list);
return $this->fetch();
}
}
model/Article.php
<?php
namespace app\admin\model;
use think\Model;
/**
* Description of Article
*
* @author Ivan
*/
class Article extends Model
{
public function cate()
{
return $this->belongsTo('cate','cateid');
}
}
article/lst.htm
<tbody>
{volist name='list' id='vo'}
<tr>
<td align="center">{$vo.id}</td>
<td align="center">{$vo.title}</td>
<td align="center">{$vo.author}</td>
<td align="left">{$vo.desc}</td>
<td align="center">{$vo.keywords}</td>
<td class="text-center">
{if condition="$vo['pic'] neq '' "}
<img src="__IMG__.{$vo.pic}" height='50'/>
{else /}
暂无图片
{/if}
</td>
<td align="center">{$vo.click}</td>
<td align="center">
{if condition = "$vo['state'] eq '1' "}
已推荐
{else /}
未推荐
{/if}
</td>
<td align="center">{$vo.time}</td>
<td align="center">{$vo.cate.catename}</td>
<--只有这个字段是cate表里的,即外部关联表所以写法不一样-->
<td align="center">
<a href="{:url('edit',array('id'=>$vo['id']))}" class="btn btn-primary btn-sm shiny">
<i class="fa fa-edit"></i> 编辑
</a>
{if condition="$vo.id neq '0'"}
<a href="{:url('del',array('id'=>$vo['id']))}" onClick="warning('确实要删除吗')" class="btn btn-danger btn-sm shiny">
<i class="fa fa-trash-o"></i> 删除
</a>
{/if}
</td>
</tr>
{/volist}
</tbody>
以上还不够,还需要创建,model/Cate.php 空的就可以
namespace app\admin\model;
use think\Model;
/**
* Description of Article
*
* @author Ivan
*/
class Cate extends Model
{
}
提示类不存在,要么没引入,要么没创建,这个类包括controller和model
提示属性不存在,就是view层的问题 当然要看哪个是主表,那个是关联表