如何为插件bacckend形式的变量分配输入值。
$termid = Input::get('term_id');
//此代码对我不起作用。
namespace Cng\Tennis\Models;
use Model;
use Flash;
use Db;
use Input;
class Lesson extends Model {
public function getSdateOptions () {
// $attributes = $this->getAttributes();
// $termid = $attributes['term_id'];
$termid = Input::get('term_id');
if ($this->term_id == $termid ) {
$term = Db::table('cng_tennis_term')->where('id', $termid )->first();
return [ $term->start_date => $term->finish_date ];
}
else {
return ['Select a date' => 'Select a date' ];
}
}
答案 0 :(得分:0)
尝试:
namespace Cng\Tennis\Models;
use Model;
use Flash;
use Db;
use Input;
class Lesson extends Model {
public static function getSdateOptions ($term_id = null) {
if(!$term_id){return false;}
// $attributes = $this->getAttributes();
// $termid = $attributes['term_id'];
if ($this->term_id == $termid ) {
$term = Db::table('cng_tennis_term')->where('id', $termid )->first();
return [ $term->start_date => $term->finish_date ];
}
else {
return ['Select a date' => 'Select a date' ];
}
}
以及您的控制器或组件
$result = Lesson::getSdateOptions(Input::get('term_id'));
希望对您有帮助