Hi, this post is all about how to create and register doctrine custom DQL function with symfony. By default symfony with doctrine not allows some special functions like Cos, Sin, Acos, Atan, Date_diff, Concat etc.,
But Doctrine allow us to write three different types of custom DQL functions such as datetime, numeric, string functions. so, this post guide you to take advantage over doctrine custom DQL functions with symfony.
Ok, by simple three steps am gonna guide you to write your own DQL functions.
STEP 1: CREATING CUSTOM DQL FUNCTION CLASS:
very first step is to write your own DQL function. Take example, am gonna write a DQL function for Acos() in mysql. The following is code for Acos function.
Acos.php
<?php
namespace DoctrineExtensions\Query\Mysql;
use Doctrine\ORM\Query\AST\Functions\FunctionNode,
Doctrine\ORM\Query\Lexer;
class Acos extends FunctionNode
{
public $arithmeticExpression;
public function getSql(\Doctrine\ORM\Query\SqlWalker $sqlWalker)
{
return 'ACOS(' . $sqlWalker->walkSimpleArithmeticExpression(
$this->arithmeticExpression
) . ')';
}
public function parse(\Doctrine\ORM\Query\Parser $parser)
{
$lexer = $parser->getLexer();
$parser->match(Lexer::T_IDENTIFIER);
$parser->match(Lexer::T_OPEN_PARENTHESIS);
$this->arithmeticExpression = $parser->SimpleArithmeticExpression();
$parser->match(Lexer::T_CLOSE_PARENTHESIS);
}
}
After creating Acos.php as above. Put above code into DoctrineExtensions\Query\Mysql folder in your symfony Bundle. For instance, folder structure is look as “ src\MyBundle\DoctrineExtensions\Query\Mysql”
Find below link to download different custom DQL functions:
STEP 2: RESGISTER DQL CLASS IN DOCTRINE:
Code:
$classLoader = new \Doctrine\Common\ClassLoader(
'DoctrineExtensions', __DIR__."/../src/MyBundle"
);
$classLoader->register();
STEP 3: REGISTER CUSTOM DQL FUNCTION IN SYMFONY:
Final and most import step to use custom DQL function in symfony is to register the function with symfony. Write the following code in Symfony config.yml file. Find in “app/config/” folder.
Example:
doctrine:
dbal:
#your configuration
orm:
auto_generate_proxy_classes: "%kernel.debug%"
auto_mapping: true
dql:
datetime_functions:
#path to date functions as same as numeric function
numeric_functions:
acos: DoctrineExtensions\Query\Mysql\Acos
string_functions:
#path to string functions as same as numeric function
Thats all, we finish up writing our own DQL function and register it with symfony.
NOTE:
DQL functions are categorized by three. Date functions, Numeric functions, String functions, the methods for writing functions are same but give some important while registering those functions in symfony configuration file.
AGT The Chempions: I’m really happy to say it was an interesting post to read. I learned new information from your article, you are doing a great job. Continue -> AGT The Champions Winner
ReplyDeleteIEEE Final Year projects Project Centers in Chennai are consistently sought after. Final Year Students Projects take a shot at them to improve their aptitudes. IEEE Final Year project centers ground for all fragments of CSE & IT engineers hoping to assemble.Final Year Projects for CSE
DeleteSpring Framework has already made serious inroads as an integrated technology stack for building user-facing applications. Spring Framework Corporate TRaining .
Specifically, Spring Framework provides various tasks are geared around preparing data for further analysis and visualization. Spring Training in Chennai
The Angular Training covers a wide range of topics including Angular Directives, Angular Services, and Angular programmability.Angular Training
Thank you so much for posting this. I really appreciate your work. Keep it up. Great work!Best software training company with placement in Hyderabad
ReplyDeleteThank you so much for posting this. I really appreciate your work. Keep it up. Great work!Best Placement company in Hyderabad
ReplyDeleteI am reading your post from the beginning,it was so interesting to read & I feel thanks to you for posting such a good blog,keep updates regularly..
ReplyDeleteWeb Designing and Development Training in Chennai | Web Designing Training Center in Velachery | Web Design Courses in Pallikaranai
Awesome post.. Really you are done a wonderful job.thank for sharing such a wonderful information with us..please keep on updating..
ReplyDeletePCB Designing Training Institute in Chennai | PCB Training Center in Velachery | PCB Design Courses in Thiruvanmiyur
This is useful post for me. I learn lot of new information from your post. keep sharing. thank you for share us..
ReplyDeleteWeb Designing Training Institute in Chennai | Web Design Taining Center in Velachery | Web Designing Courses in Taramani
Awesome article. thanks for sharing this wonderful article with us.keep updating...
ReplyDeleteTally Training Institute in Chennai | Advanced Tally Courses in Guindy | Tally Training Center in Velachery
Wow! Such an amazing and helpful post this is. I really really love it. It's so good and so awesome. I am just amazed. I hope that you continue to do your work like this in the future also campingplatz holland mit hund
ReplyDeleteAnother table may depict a request and have these segments: item, client, date, and deals cost. Change Site URL Using MySQL
ReplyDeletegolden goose sneakers
ReplyDeletejordan shoes
supreme clothing
jordan 12
kobe byrant shoes
curry 8
yeezy
cheap jordans
kyrie irving shoes
yeezy boost
blood pressure watch professional in R&D wearable blood pressure monitor, in the innovative form of a wrist watch, proactively monitors your heart health by turning real-time heart data into heart.
ReplyDeletemason jar lids canning lids supplier. offer canning Lids in different style and size
Cervical spine massager We aim to create a healthy lifestyle that assists every individual to de-stress, relax. unwind and streamline a pain-free life and at the same time feel and look amazing.
sex machine for her Choose Sex Machine to Get Orgasm and Enjoy Life|
neon light for roomNeon Signs Light Is One-of-a-Kind Activities Designed and Hosted by Expert Locals. All Experiences are Vetted for Quality.
Get Oracle training in Chennai. One of the booming industries is Oracle. It has an erasable place in the IT industry. More than 70% of students choose oracle for their career and All the 70% are shining with a good salary package this the power of the Oracle.Best Oracle Training in Chennai | Infycle Technologies
ReplyDeletesex machine Online Shop
ReplyDeletefucking machines Online Shop
sex machine for her Online Shop
patio heater Online Shop
canning lids Online Shop
dog training collars Online Shop
food truck Online Shop
silk durag Online Shop
sewing machine Online Shop
I was surfing the Internet for information and came across your blog. I am impressed by the information you have on this blog. It shows how well you understand this subject. excellentcustomclothing
ReplyDeleteI would like to say that this blog really convinced me to do it! Thanks, very good post. www.excellentcustomclothing.com
ReplyDeletebpdoctormed
ReplyDeletemakeup tutorial