db
db copied to clipboard
Setting escapingReplacements property of the LikeCondition
Object Form in yii\db\Query
conditions introduced in Yii 2.0.14 is really great and timely enhancement!
It would be nice although setting its escapingReplacements
property in a more convenient way, than calling its setter method:
$likeObject->setEscapingReplacements( false );
The property itself is not public
but protected
, so direct assignment raises exception:
$likeObject->escapingReplacements = false;
In general, it would be nice to set escapingReplacements
at object creation as fouth parameter passed to __construct
method, e.g. like this:
$data = ( new Query())
->select([ 'id', 'name' ])
->from( 'locality' )
->where( new LikeCondition( 'postal', 'LIKE', '12345_', false ))
->all();
This would eliminate the need in additional object holding var and code lines:
$likeObject = new LikeCondition( 'postal', 'LIKE', '12345_' );
$likeObject->setEscapingReplacements( false );
$data = ( new Query())
->select([ 'id', 'name' ])
->from( 'locality' )
->where( $likeObject )
->all();
Additional info
Q | A |
---|---|
Yii version | 2.0.14 |
PHP version | 5.6.12 |
Operating system | Windows |