Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
144 views
in Technique[技术] by (71.8m points)

My search is not working in yii2 ,i have to try to find the solution but fails

I want to search my data but the search is not working. I can't understand what's going wrong? please help to fix it... here is the code

payable controller

<?php

namespace appcontrollers;

use Yii;
use appmodelsPayable;
use appmodelsPayableSearch;
use yiiwebController;
use yiiwebNotFoundHttpException;
use yiifiltersVerbFilter;

/**
 * PayableController implements the CRUD actions for Payable model.
 */
class PayableController extends Controller
{
    /**
     * {@inheritdoc}
     */
    public function behaviors()
    {
        return [
            'verbs' => [
                'class' => VerbFilter::className(),
                'actions' => [
                    'delete' => ['POST'],
                ],
            ],
        ];
    }

    /**
     * Lists all Payable models.
     * @return mixed
     */
    public function actionIndex()
    {
        $searchModel = new PayableSearch();
        $dataProvider = $searchModel->search(Yii::$app->request->queryParams);

        return $this->render('index', [
            'searchModel' => $searchModel,
            'dataProvider' => $dataProvider,
        ]);
    }

    /**
     * Displays a single Payable model.
     * @param integer $id
     * @return mixed
     * @throws NotFoundHttpException if the model cannot be found
     */
    public function actionView($id)
    {
        return $this->render('view', [
            'model' => $this->findModel($id),
        ]);
    }

    /**
     * Creates a new Payable model.
     * If creation is successful, the browser will be redirected to the 'view' page.
     * @return mixed
     */
    public function actionCreate()
    {
        $model = new Payable();

        if ($model->load(Yii::$app->request->post()) && $model->save()) {
            return $this->redirect(['view', 'id' => $model->id]);
        }

        return $this->render('create', [
            'model' => $model,
        ]);
    }

    /**
     * Updates an existing Payable model.
     * If update is successful, the browser will be redirected to the 'view' page.
     * @param integer $id
     * @return mixed
     * @throws NotFoundHttpException if the model cannot be found
     */
    public function actionUpdate($id)
    {
        $model = $this->findModel($id);

        if ($model->load(Yii::$app->request->post()) && $model->save()) {
            return $this->redirect(['view', 'id' => $model->id]);
        }

        return $this->render('update', [
            'model' => $model,
        ]);
    }

    /**
     * Deletes an existing Payable model.
     * If deletion is successful, the browser will be redirected to the 'index' page.
     * @param integer $id
     * @return mixed
     * @throws NotFoundHttpException if the model cannot be found
     */
    public function actionDelete($id)
    {
        $this->findModel($id)->delete();

        return $this->redirect(['index']);
    }

    /**
     * Finds the Payable model based on its primary key value.
     * If the model is not found, a 404 HTTP exception will be thrown.
     * @param integer $id
     * @return Payable the loaded model
     * @throws NotFoundHttpException if the model cannot be found
     */
    protected function findModel($id)
    {
        if (($model = Payable::findOne($id)) !== null) {
            return $model;
        }

        throw new NotFoundHttpException('The requested page does not exist.');
    }
}

PaybleSearch

<?php

namespace appmodels;

use yiiaseModel;
use yiidataActiveDataProvider;
use appmodelsPayable;

/**
 * PayableSearch represents the model behind the search form of `appmodelsPayable`.
 */
class PayableSearch extends Payable
{
    /**
     * {@inheritdoc}
     */
    public function rules()
    {
        return [
            [['id', 'consumer_id', 'total_months_conservancy', 'water_arrears', 'conservancy_amount', 'total_water_and_conservancy_amount', 'tinure', 'dues_amount', 'per_month_charges', 'no_of_months', 'total_amount_of_current_months', 'advanced_pay', 'arrears', 'arrears_period', 'total_bill', 'after_due_date_charges', 'total_after_due_date', 'balance_arears', 'water_charges_per_month', 'conservancy_charges_per_month', 'four_months_water_charges', 'four_months_conservancy_charges'], 'integer'],
            [['water_remarks', 'remarks', 'billing_months', 'issue_date', 'due_date'], 'safe'],
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function scenarios()
    {
        // bypass scenarios() implementation in the parent class
        return Model::scenarios();
    }

    /**
     * Creates data provider instance with search query applied
     *
     * @param array $params
     *
     * @return ActiveDataProvider
     */
    public function search($params)
    {
        $query = Bill::find()->where('status=0');
        // echo"<pre>";
        // print_r($query);
        // exit();
        // add conditions that should always apply here

        $dataProvider = new ActiveDataProvider([
            'query' => $query,
        ]);

        $this->load($params);

        if (!$this->validate()) {
            // uncomment the following line if you do not want to return any records when validation fails
            // $query->where('0=1');
            return $dataProvider;
        }

        // grid filtering conditions
        $query->andFilterWhere([
            'id' => $this->id,
            'consumer_id' => $this->consumer_id,
            'total_months_conservancy' => $this->total_months_conservancy,
            'water_arrears' => $this->water_arrears,
            'conservancy_amount' => $this->conservancy_amount,
            'total_water_and_conservancy_amount' => $this->total_water_and_conservancy_amount,
            'tinure' => $this->tinure,
            'dues_amount' => $this->dues_amount,
            'per_month_charges' => $this->per_month_charges,
            'no_of_months' => $this->no_of_months,
            'total_amount_of_current_months' => $this->total_amount_of_current_months,
            'advanced_pay' => $this->advanced_pay,
            'arrears' => $this->arrears,
            'arrears_period' => $this->arrears_period,
            'total_bill' => $this->total_bill,
            'after_due_date_charges' => $this->after_due_date_charges,
            'total_after_due_date' => $this->total_after_due_date,
            'balance_arears' => $this->balance_arears,
            'water_charges_per_month' => $this->water_charges_per_month,
            'conservancy_charges_per_month' => $this->conservancy_charges_per_month,
            'four_months_water_charges' => $this->four_months_water_charges,
            'four_months_conservancy_charges' => $this->four_months_conservancy_charges,
            'issue_date' => $this->issue_date,
            'due_date' => $this->due_date,
        ]);

        $query->andFilterWhere(['like', 'water_remarks', $this->water_remarks])
            ->andFilterWhere(['like', 'remarks', $this->remarks])
            ->andFilterWhere(['like', 'billing_months', $this->billing_months]);

        return $dataProvider;
    }
}

Payable Model

<?php

namespace appmodels;

use Yii;

/**
 * This is the model class for table "payable".
 *
 * @property int $id
 * @property int $consumer_id
 * @property int $total_months_conservancy
 * @property int $water_arrears
 * @property string $water_remarks
 * @property int $conservancy_amount
 * @property int $total_water_and_conservancy_amount
 * @property int $tinure
 * @property int $dues_amount
 * @property int $per_month_charges
 * @property int $no_of_months
 * @property int $total_amount_of_current_months
 * @property int $advanced_pay
 * @property int $arrears
 * @property int $arrears_period
 * @property int $total_bill
 * @property int $after_due_date_charges
 * @property int $total_after_due_date
 * @property int $balance_arears
 * @property string $remarks
 * @property int $water_charges_per_month
 * @property int $conservancy_charges_per_month
 * @property int $four_months_water_charges
 * @property int $four_months_conservancy_charges
 * @property string $billing_months
 * @property string $issue_date
 * @property string $due_date
 */
class Payable extends yiidbActiveRecord
{
    /**
     * {@inheritdoc}
     */
    public static function tableName()
    {
        return 'payable';
    }

    /**
     * {@inheritdoc}
     */
    public function rules()
    {
        return [
            [['consumer_id', 'total_months_conservancy', 'water_arrears', 'water_remarks', 'conservancy_amount', 'total_water_and_conservancy_amount', 'tinure', 'dues_amount', 'per_month_charges', 'no_of_months', 'total_amount_of_current_months', 'advanced_pay', 'arrears', 'arrears_period', 'total_bill', 'after_due_date_charges', 'total_after_due_date', 'balance_arears', 'remarks', 'water_charges_per_month', 'conservancy_charges_per_month', 'four_months_water_charges', 'four_months_conservancy_charges', 'billing_months', 'issue_date', 'due_date'], 'required'],
            [['consumer_id', 'total_months_conservancy', 'water_arrears', 'conservancy_amount', 'total_water_and_conservancy_amount', 'tinure', 'dues_amount', 'per_month_charges', 'no_of_months', 'total_amount_of_current_months', 'advanced_pay', 'arrears', 'arrears_period', 'total_bill', 'after_due_date_charges', 'total_after_due_date', 'balance_arears', 'water_charges_per_month', 'conservancy_charges_per_month', 'four_months_water_charges', 'four_months_conservancy_charges'], 'integer'],
            [['issue_date', 'due_date'], 'safe'],
            [['water_remarks'], 'string', 'max' => 250],
            [['remarks'], 'string', 'max' => 350],
            [['billing_months'], 'string', 'max' => 25],
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'consumer_id' => 'Consumer ID',
            'total_months_conservancy' => 'Total Months Conservancy',
            'water_arrears' => 'Water Arrears',
            'water_remarks' => 'Water Remarks',
            'conservancy_amount' => 'Conservancy Amount',
            'total_water_and_conservancy_amount' => 'Total Water And Conservancy Amount',
            'tinure' => 'Tinure',
            'dues_amount' => 'Dues Amount',
            'per_month_charges' => 'Per Month Charges',
            'no_of_months' => 'No Of Months',
            'total_amount_of_current_months' => 'Total Amount Of Current Months',
            'advanced_pay' => 'Advanced Pay',
            'arrears' => 'Arrears',
            'arrears_period' => 'Arrears Period',
            'total_bill' => 'Total Bill',
            'after_due_date_charges' => 'After Due Date Charges',
            'total_after_due_date' => 'Total After Due Date',
            'balance_arears' => 'Balance Arears',
            'remarks' => 'Remarks',
            'water_charges_per_month' => 'Water Charges Per Month',
            'conservancy_charges_per_month' => 'Conservancy Charges Per Month',
            'four_months_water_charges' => 'Four Months Water Charges',
            'four_months_conservancy_charges' => 'Four Months Conservancy Charges',
          

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...