IndexController.class.php 代码如下:
<?php
namespace Home\Controller;
use Think\Controller;
class IndexController extends Controller {
public function index(){
$attrs =D("attribute");
$attrs->relation(Ture)->find(1);
dump($attrs);
}
}IndexModel.class.php 代码如下:<?php
namespace Home\Model;
use Think\Model\RelationModel;
class IndexModel extends RelationModel{
//定义关联
protected $_link = array(
'good_type' => array(
'mapping_type' => self::BELONGS_TO,
'class_name' => 'goods_type', //关联的表名
'foreign_key' => 'type_id', //外键
'as_fields' => 'type_name',//获取过来的字段
),
);
}发生错误如下::(
Think\Model:relation方法不存在!
错误位置
FILE: C:\wamp64\www\shopp\ThinkPHP\Library\Think\Model.class.php LINE: 257
TRACE
#0 C:\wamp64\www\shopp\ThinkPHP\Library\Think\Model.class.php(257): E('Think\\Model:rel...')
#1 C:\wamp64\www\shopp\Application\Home\Controller\IndexController.class.php(8): Think\Model->__call('relation', Array)
#2 C:\wamp64\www\shopp\Application\Home\Controller\IndexController.class.php(8): Think\Model->relation('Ture')
#3 [internal function]: Home\Controller\IndexController->index()
#4 C:\wamp64\www\shopp\ThinkPHP\Library\Think\App.class.php(178): ReflectionMethod->invoke(ob
#5 C:\wamp64\www\shopp\ThinkPHP\Library\Think\App.class.php(113): Think\App::invokeAction(ob
#6 C:\wamp64\www\shopp\ThinkPHP\Library\Think\App.class.php(213): Think\App::exec()
#7 C:\wamp64\www\shopp\ThinkPHP\Library\Think\Think.class.php(135): Think\App::run()
#8 C:\wamp64\www\shopp\ThinkPHP\ThinkPHP.php(100): Think\Think::start()
#9 C:\wamp64\www\shopp\index.php(24): require('C:\\wamp64\\www\\s...')
#10 {main}
ThinkPHP3.2.3 { Fast & Simple OOP PHP fr
最佳答案