在gridview中显示字段的多个值

时间:2016-01-30 10:32:44

标签: gridview yii2 yii2-basic-app

我是yii2的新人。我有一个languages主表(在name字段中包含html,css,java,php ...)和一个registration表,其中有一个名为language_id的字段。我使用json_encode为该字段插入了多个值。 现在在数据库中显示语言ID为["1","2","3","4","5"]

现在我想使用gridview显示存储在db中的数据。如何在gridview中显示语言的多个值。以下是我使用 gridview

尝试的内容
<?= GridView::widget([
        'dataProvider' => $dataProvider,
        'filterModel' => $searchModel,
        'columns' => [
            ['class' => 'yii\grid\SerialColumn'],

            'first_name',
            'last_name',
            'gender',
            'address',
            ['label'=>'Course',
            'value'=>'course.name'],
            'email:email',
            ['label'=>'Languages Known',
            'value'=>'languages.name'],
            'course_completion_date',

            ['class' => 'yii\grid\ActionColumn'],
        ],
    ]); ?>

并在我的模型代码中如下

public function getLanguages(){

        $result = json_decode($this->language_id, true);

        return $this->hasOne(Languages::className(), ['id' => $result]);
    }

1 个答案:

答案 0 :(得分:0)

最后我得到了回答。但我不认为这是解决这个问题的正确方法。分页不起作用(当我进入2页等等)并显示错误时:

  

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

public void CameraClick(View v) {

        Intent intent= new Intent(MediaStore.ACTION_IMAGE_CAPTURE);

        // creating Dir to save clicked Photo
        String root = Environment.getExternalStorageDirectory().toString();
        File myDir = new File(root + "/cam_Intent");
        myDir.mkdirs();

        // save clicked pic to given dir with given name

        File file = new File(Environment.getExternalStorageDirectory(),
                "/cam_Intent/MyPhoto.jpg");

        outPutfileUri = Uri.fromFile(file);
        intent.putExtra(MediaStore.EXTRA_OUTPUT, outPutfileUri);
        startActivityForResult(intent, TAKE_PIC);
    }

    Bitmap bitmap = null;

    @Override
    protected void onActivityResult(int requestCode, int resultCode,Intent data)
    {
        if (requestCode == TAKE_PIC && resultCode==RESULT_OK) {

            String uri = outPutfileUri.toString();
            Log.e("uri-:", uri);
            Toast.makeText(this, outPutfileUri.toString(),Toast.LENGTH_LONG).show();

            //Bitmap myBitmap = BitmapFactory.decodeFile(uri);
           // mImageView.setImageURI(Uri.parse(uri));   OR drawable make image strechable so try bleow also

            try {
                bitmap = MediaStore.Images.Media.getBitmap(this.getContentResolver(), outPutfileUri);
                Drawable d = new BitmapDrawable(getResources(), bitmap);
                mImageView.setImageDrawable(d);
            } catch (IOException e) {
                e.printStackTrace();
            }


        }
}