How to use the findByField function for fleaphpcrud operations
Source: Internet
Author: User
Use the findByField function of fleaphpcrud operation. For more information, see. FindByField function prototype
The code is as follows:
/**
* Returns the first record with the specified field value.
*
* @ Param string $ field
* @ Param mixed $ value
* @ Param string $ sort
* @ Param mixed $ fields
*
* @ Return array
*/
Function & findByField ($ field, $ value, $ sort = null, $ fields = '*')
{
Return $ this-> find (array ($ field => $ value), $ sort, $ fields );
}
FindByField function parameter description
$ Field: query fields
$ Value indicates the queried value.
$ Sort sorting method
$ Fields: query the field names displayed.
Use findByField function for fleaphp crud operations
The code is as follows:
$ Dirname = dirname (_ FILE __);
Define ('app _ dir', $ dirname. '/app ');
Define ('no _ LEGACY_FLEAPHP ', true );
Require ($ dirname. '/FleaPHP/FLEA. php ');
// Set the cache Directory
FLEA: setAppInf ('internalcachedir', $ dirname. '/_ cache ');
// Link to the database
$ Dsn = array (
'Driver '=> 'mysql ',
'Host' => 'localhost ',
'Login' => 'root ',
'Password' => '',
'Database' => 'wordpress'
);
FLEA: setAppInf ('dbdsn ', $ dsn );
// Read wp_posts content
FLEA: loadClass ('Flea _ Db_TableDataGateway ');
Class Teble_Class extends FLEA_Db_TableDataGateway {
Var $ tableName = 'WP _ posts ';
Var $ primaryKey = 'id ';
}
$ Tableposts = & new Teble_Class ();
$ Rowsets = $ tableposts-> findByField ('id', 4, 'post _ date desc', array ('id', 'post _ title '));
Dump ($ rowsets );
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