具有以下型号:
新闻.php
class News extends Aware {
public static $table = 'noticia';
public static $key = 'idnoticia';
public static $timestamps = false;
public static $rules = array(
'titulo' => 'required',
'subtitulo' => 'required',
);
public function images()
{
return $this->has_many('Image');
}
}
图像.php
class Image extends Aware {
public static $timestamps = true;
public static $rules = array(
'unique_name' => 'required',
'original_name' => 'required',
'location' => 'required',
'news_id' => 'required',
);
public function news()
{
return $this->belongs_to('News');
}
}
然后在控制器中我执行以下操作:
$image = new Image(array(
'unique_name' => $fileName,
'original_name' => $file['file']['name'],
'location' => $directory.$fileName,
'news_id' => $news_id,
));
News::images()->insert($image);
我不断收到以下错误消息:
假设 $this 来自不兼容的上下文,不应静态调用非静态方法 News::images()
任何想法我做错了什么?
public static function images()
似乎不需要设置,因为刷新后我收到一条错误消息
$this 不在对象上下文中时
戈登说News::images()->insert($image);
我这样做是在做一个静态调用,但这就是锯做的方式