获取输入值插件octobercms后端

时间:2019-02-28 08:23:34

标签: octobercms octobercms-plugins octobercms-backend

如何为插件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' ];
            } 
        }

1 个答案:

答案 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'));

希望对您有帮助