Yii framework FAQ: how to solve the filter problem of cgridview joined table fields

Source: Internet
Author: User

Model:

1. Add filter attributes
VaR $ A = "";
VaR $ B = "";

2. modify the configuration in the Rules Method
Array ('......., A, B ', 'safe', 'on' => 'search ');

3. Pay attention to the relations Method
Public Function relations ()
{
// Note: you may need to adjust the relation name and the related
// Class name for the relations automatically generated below.
Return array (
'Xxx' => array (SELF: has_one, 'xxxmodel', array ('... '=> '.... ')),
);
}

4. Modify the search () method to Add rows
$ Criteria-> compare ('xxx. Ax ', $ this-> );
$ Criteria-> compare ('xxx. bx ', $ this-> B );

View
1. 'dataprovider' => $ model-> with ("XXX")-> Search (),

2. Column Display Modification
Array (
'Name' => 'A ',
'Value' => '$ data-> XXX-> ax ',
'Filter' => array (select down menu array ),
),
Array (
'Name' => 'B ',
'Value' => '$ data-> XXX-> BX ',
'Filter' => array (1 => "set", 0 => 'not set '),
),

Code prompt:
1. The added two attributes are only used to record the search conditions on the page.
2. The cdbcriteria Search Method in the search method has not changed. Learn how to use associated search


Yii framework FAQ: how to solve the filter problem of cgridview joined table fields

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.