{"id":1080,"date":"2025-06-12T12:21:02","date_gmt":"2025-06-12T04:21:02","guid":{"rendered":"https:\/\/www.zhaozhao123.cn\/php\/php-application-manual\/symfony\/1080.html"},"modified":"2025-06-12T12:21:02","modified_gmt":"2025-06-12T04:21:02","slug":"symfony%e6%a1%86%e6%9e%b6%e4%b8%ad%e7%9a%84%e4%ba%8b%e4%bb%b6%e7%9b%91%e5%90%ac%e5%99%a8%e4%b8%8e%e8%ae%a2%e9%98%85%e8%80%85%ef%bc%9a%e5%ae%9e%e8%b7%b5%e6%8c%87%e5%8d%97%ef%bc%88%e5%90%ab%e7%a4%ba","status":"publish","type":"my1js","link":"https:\/\/www.zhaozhao123.cn\/php\/my1js\/1080.html","title":{"rendered":"Symfony\u6846\u67b6\u4e2d\u7684\u4e8b\u4ef6\u76d1\u542c\u5668\u4e0e\u8ba2\u9605\u8005\uff1a\u5b9e\u8df5\u6307\u5357\uff08\u542b\u793a\u4f8b\uff09"},"content":{"rendered":"<div class=\"wp-block-columns p-0 border is-layout-flex wp-container-core-columns-is-layout-28f84493 wp-block-columns-is-layout-flex\">\r\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\r\n<div class=\"wp-block-columns px-4 py-3 border-bottom has-background is-layout-flex wp-container-core-columns-is-layout-28f84493 wp-block-columns-is-layout-flex\" style=\"background:linear-gradient(243deg,rgb(238,238,238) 0%,rgba(58,166,242,0.15) 100%)\">\r\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\r\n<div class=\"wp-block-group is-nowrap is-layout-flex wp-container-core-group-is-layout-6c531013 wp-block-group-is-layout-flex\">\r\n<figure class=\"wp-block-image size-thumbnail is-resized is-style-rounded is-style-rounded--1\"><img decoding=\"async\" src=\"https:\/\/www.zhaozhao123.cn\/myitems\/images\/sites16\/2025\/06\/dyA-1-400x300.jpg\" alt=\"Bug&#32534;&#35793;&#29422;\" class=\"wp-image-1842\" style=\"object-fit:cover;width:30px;height:30px\"><\/figure>\r\n\r\n\r\n\r\n<h2 class=\"wp-block-heading my-0\" style=\"font-size:clamp(0.875rem, 0.875rem + ((1vw - 0.2rem) * 0.175), 1rem);\">Bug&#32534;&#35793;&#29422;<\/h2>\r\n<\/div>\r\n<\/div>\r\n<\/div>\r\n\r\n\r\n\r\n<div class=\"wp-block-columns px-xl-5 px-4 py-xl-4 py-3 is-layout-flex wp-container-core-columns-is-layout-28f84493 wp-block-columns-is-layout-flex\">\r\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\r\n<p>&#26631;&#39064;&#65306;Symfony&#26694;&#26550;&#20013;&#30340;&#20107;&#20214;&#30417;&#21548;&#22120;&#19982;&#35746;&#38405;&#32773;&#65306;&#23454;&#36341;&#25351;&#21335;&#65288;&#21547;&#31034;&#20363;&#65289;<\/p>\n<h3>&#24341;&#35328;<\/h3>\n<p>&#22312;&#29616;&#20195;&#30340;Web&#24320;&#21457;&#20013;&#65292;&#20107;&#20214;&#39537;&#21160;&#32534;&#31243;&#26159;&#19968;&#31181;&#24120;&#35265;&#30340;&#35774;&#35745;&#27169;&#24335;&#65292;&#23427;&#20801;&#35768;&#24212;&#29992;&#31243;&#24207;&#20013;&#30340;&#19981;&#21516;&#37096;&#20998;&#36890;&#36807;&#21457;&#24067;&#21644;&#35746;&#38405;&#26426;&#21046;&#36827;&#34892;&#36890;&#20449;&#12290;Symfony&#26694;&#26550;&#25552;&#20379;&#20102;&#24378;&#22823;&#30340;&#20107;&#20214;&#31995;&#32479;&#65292;&#20351;&#24471;&#24320;&#21457;&#32773;&#21487;&#20197;&#36731;&#26494;&#22320;&#23454;&#29616;&#20107;&#20214;&#30417;&#21548;&#22120;&#21644;&#35746;&#38405;&#32773;&#21151;&#33021;&#12290;<\/p>\n<p>&#26412;&#31687;&#25991;&#31456;&#23558;&#35814;&#32454;&#35762;&#35299;&#22914;&#20309;&#22312;Symfony&#26694;&#26550;&#20013;&#20351;&#29992;&#20107;&#20214;&#30417;&#21548;&#22120;&#21644;&#35746;&#38405;&#32773;&#65292;&#24182;&#25552;&#20379;&#19968;&#20010;&#23436;&#25972;&#30340;&#31034;&#20363;&#65292;&#24110;&#21161;&#35835;&#32773;&#26356;&#22909;&#22320;&#29702;&#35299;&#36825;&#19968;&#27010;&#24565;&#12290;<\/p>\n<h3>&#20160;&#20040;&#26159;&#20107;&#20214;&#30417;&#21548;&#22120;&#65311;<\/h3>\n<p>&#20107;&#20214;&#30417;&#21548;&#22120;&#26159;&#20107;&#20214;&#22788;&#29702;&#31243;&#24207;&#30340;&#19968;&#31181;&#26041;&#24335;&#65292;&#24403;&#29305;&#23450;&#31867;&#22411;&#30340;&#20107;&#20214;&#21457;&#29983;&#26102;&#65292;&#20107;&#20214;&#30417;&#21548;&#22120;&#20250;&#34987;&#33258;&#21160;&#35843;&#29992;&#12290;&#20107;&#20214;&#30417;&#21548;&#22120;&#36890;&#24120;&#29992;&#20110;&#21709;&#24212;&#29992;&#25143;&#36755;&#20837;&#12289;&#22788;&#29702;&#24322;&#27493;&#25805;&#20316;&#25110;&#20854;&#20182;&#38656;&#35201;&#21516;&#27493;&#25191;&#34892;&#30340;&#20219;&#21153;&#12290;<\/p>\n<h3>&#20160;&#20040;&#26159;&#35746;&#38405;&#32773;&#65311;<\/h3>\n<p>&#35746;&#38405;&#32773;&#26159;&#36127;&#36131;&#35302;&#21457;&#20107;&#20214;&#30340;&#32452;&#20214;&#12290;&#35746;&#38405;&#32773;&#21487;&#20197;&#36890;&#36807;&#20107;&#20214;&#21457;&#24067;&#32773;&#21521;&#20854;&#20182;&#32452;&#20214;&#24191;&#25773;&#20107;&#20214;&#12290;&#20107;&#20214;&#21457;&#24067;&#32773;&#36890;&#24120;&#26159;&#25511;&#21046;&#22120;&#12289;&#26381;&#21153;&#25110;&#20854;&#20182;&#32452;&#20214;&#12290;<\/p>\n<h3>&#22914;&#20309;&#22312;Symfony&#20013;&#20351;&#29992;&#20107;&#20214;&#30417;&#21548;&#22120;&#21644;&#35746;&#38405;&#32773;<\/h3>\n<ol>\n<li>\n<p><strong>&#21019;&#24314;&#20107;&#20214;&#31867;<\/strong>&#65306;\n&#39318;&#20808;&#65292;&#25105;&#20204;&#38656;&#35201;&#21019;&#24314;&#19968;&#20010;&#20107;&#20214;&#31867;&#65292;&#36825;&#20010;&#31867;&#23558;&#34987;&#29992;&#26469;&#23450;&#20041;&#20107;&#20214;&#30340;&#20855;&#20307;&#20449;&#24687;&#12290;<\/p>\n<pre><code class=\"language-php\">\/\/ src\/Event\/UserRegisteredEvent.php\nnamespace AppEvent;\n\nuse SymfonyContractsEventDispatcherEventInterface;\n\nclass UserRegisteredEvent extends Event implements EventInterface\n{\n   private $userId;\n   private $userName;\n\n   public function __construct(int $userId, string $userName)\n   {\n       $this-&gt;userId = $userId;\n       $this-&gt;userName = $userName;\n   }\n\n   public function getUserId(): int\n   {\n       return $this-&gt;userId;\n   }\n\n   public function getUserName(): string\n   {\n       return $this-&gt;userName;\n   }\n}<\/code><\/pre>\n<\/li>\n<li>\n<p><strong>&#21019;&#24314;&#20107;&#20214;&#30417;&#21548;&#22120;<\/strong>&#65306;\n&#25509;&#19979;&#26469;&#65292;&#25105;&#20204;&#21019;&#24314;&#19968;&#20010;&#20107;&#20214;&#30417;&#21548;&#22120;&#26469;&#22788;&#29702;<code>UserRegisteredEvent<\/code>&#20107;&#20214;&#12290;<\/p>\n<pre><code class=\"language-php\">\/\/ src\/EventListener\/UserRegisteredListener.php\nnamespace AppEventListener;\n\nuse AppEventUserRegisteredEvent;\nuse SymfonyComponentEventDispatcherEventSubscriberInterface;\n\nclass UserRegisteredListener implements EventSubscriberInterface\n{\n   public static function getSubscribedEvents()\n   {\n       return [\n           UserRegisteredEvent::class =&gt; 'onUserRegistered',\n       ];\n   }\n\n   public function onUserRegistered(UserRegisteredEvent $event)\n   {\n       echo \"User {$event-&gt;getUserName()} registered with ID {$event-&gt;getUserId()}n\";\n   }\n}<\/code><\/pre>\n<\/li>\n<li>\n<p><strong>&#37197;&#32622;&#20107;&#20214;&#21457;&#24067;&#32773;<\/strong>&#65306;\n&#22312;<code>config\/services.yaml<\/code>&#25991;&#20214;&#20013;&#65292;&#27880;&#20876;&#20107;&#20214;&#30417;&#21548;&#22120;&#12290;<\/p>\n<pre><code class=\"language-yaml\"># config\/services.yaml\nservices:\n   AppEventListenerUserRegisteredListener:\n       tags:\n           - { name: kernel.event_listener, event: user_registered, method: onUserRegistered }<\/code><\/pre>\n<\/li>\n<li>\n<p><strong>&#21457;&#24067;&#20107;&#20214;<\/strong>&#65306;\n&#26368;&#21518;&#65292;&#25105;&#20204;&#22312;&#25511;&#21046;&#22120;&#20013;&#21457;&#24067;<code>UserRegisteredEvent<\/code>&#20107;&#20214;&#12290;<\/p>\n<pre><code class=\"language-php\">\/\/ src\/Controller\/UserController.php\nnamespace AppController;\n\nuse AppEventUserRegisteredEvent;\nuse SymfonyBundleFrameworkBundleControllerAbstractController;\nuse SymfonyComponentHttpFoundationResponse;\nuse SymfonyComponentHttpKernelEventGetResponseEvent;\n\nclass UserController extends AbstractController\n{\n   public function registerUser(GetResponseEvent $event): Response\n   {\n       $request = $event-&gt;getRequest();\n       $username = $request-&gt;query-&gt;get('username');\n\n       if ($username) {\n           $userId = uniqid(); \/\/ &#31034;&#20363;ID&#29983;&#25104;&#36923;&#36753;\n           $event = new UserRegisteredEvent($userId, $username);\n           $this-&gt;dispatcher-&gt;dispatch($event);\n\n           return new Response(\"User {$username} registered with ID {$userId}\");\n       }\n\n       return new Response(\"Username is required\");\n   }\n}<\/code><\/pre>\n<\/li>\n<\/ol>\n<h3>&#31034;&#20363;&#20195;&#30721;&#35299;&#37322;<\/h3>\n<ul>\n<li><strong>UserRegisteredEvent<\/strong>&#65306;&#23450;&#20041;&#20102;&#19968;&#20010;&#31616;&#21333;&#30340;&#20107;&#20214;&#31867;&#12290;<\/li>\n<li><strong>UserRegisteredListener<\/strong>&#65306;&#23454;&#29616;&#20102;<code>EventSubscriberInterface<\/code>&#25509;&#21475;&#65292;&#24182;&#22312;<code>getSubscribedEvents<\/code>&#26041;&#27861;&#20013;&#22768;&#26126;&#20102;&#35201;&#30417;&#21548;&#30340;&#20107;&#20214;&#31867;&#22411;&#12290;<\/li>\n<li><strong>UserController<\/strong>&#65306;&#22312;<code>registerUser<\/code>&#26041;&#27861;&#20013;&#21457;&#24067;&#20102;&#19968;&#20010;<code>UserRegisteredEvent<\/code>&#20107;&#20214;&#65292;&#24182;&#20351;&#29992;<code>$this-&gt;dispatcher-&gt;dispatch<\/code>&#26041;&#27861;&#26469;&#20998;&#21457;&#20107;&#20214;&#12290;<\/li>\n<\/ul>\n<p>&#36890;&#36807;&#20197;&#19978;&#27493;&#39588;&#65292;&#25105;&#20204;&#25104;&#21151;&#22320;&#22312;Symfony&#26694;&#26550;&#20013;&#23454;&#29616;&#20102;&#19968;&#20010;&#31616;&#21333;&#30340;&#20107;&#20214;&#30417;&#21548;&#22120;&#21644;&#35746;&#38405;&#32773;&#21151;&#33021;&#12290;&#24076;&#26395;&#36825;&#31687;&#25945;&#31243;&#33021;&#24110;&#21161;&#20320;&#26356;&#22909;&#22320;&#29702;&#35299;&#21644;&#24212;&#29992;&#36825;&#20123;&#27010;&#24565;&#12290;<\/p>\r\n<\/div>\r\n<\/div>\r\n<\/div>\r\n<\/div><div class=\"wp-block-columns p-0 border is-layout-flex wp-container-core-columns-is-layout-28f84493 wp-block-columns-is-layout-flex\">\r\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\r\n<div class=\"wp-block-columns px-4 py-3 border-bottom has-background is-layout-flex wp-container-core-columns-is-layout-28f84493 wp-block-columns-is-layout-flex\" style=\"background:linear-gradient(243deg,rgb(238,238,238) 0%,rgba(58,166,242,0.15) 100%)\">\r\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\r\n<div class=\"wp-block-group is-nowrap is-layout-flex wp-container-core-group-is-layout-6c531013 wp-block-group-is-layout-flex\">\r\n<figure class=\"wp-block-image size-thumbnail is-resized is-style-rounded is-style-rounded--2\"><img decoding=\"async\" src=\"https:\/\/www.zhaozhao123.cn\/myitems\/images\/sites16\/2025\/06\/zp-400x300.jpg\" alt=\"&#40657;&#26495;Bug&#35762;&#24072;\" class=\"wp-image-1849\" style=\"object-fit:cover;width:30px;height:30px\"><\/figure>\r\n\r\n\r\n\r\n<h2 class=\"wp-block-heading my-0\" style=\"font-size:clamp(0.875rem, 0.875rem + ((1vw - 0.2rem) * 0.175), 1rem);\">&#40657;&#26495;Bug&#35762;&#24072;<\/h2>\r\n<\/div>\r\n<\/div>\r\n<\/div>\r\n\r\n\r\n\r\n<div class=\"wp-block-columns px-xl-5 px-4 py-xl-4 py-3 is-layout-flex wp-container-core-columns-is-layout-28f84493 wp-block-columns-is-layout-flex\">\r\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\r\n<body><h2>Symfony&#20107;&#20214;&#31616;&#20171;<\/h2><p>Symfony&#30340;&#20107;&#20214;&#21457;&#24067;&#32773;&#32452;&#20214;&#26159;&#19968;&#27454;&#24378;&#22823;&#30340;&#24037;&#20855;&#65292;&#29992;&#20110;&#24320;&#21457;&#35299;&#32806;&#30340;&#24212;&#29992;&#31243;&#24207;&#12290;&#23427;&#20801;&#35768;&#24212;&#29992;&#31243;&#24207;&#30340;&#19981;&#21516;&#37096;&#20998;&#36890;&#36807;&#21457;&#24067;&#20107;&#20214;&#21644;&#30417;&#21548;&#20107;&#20214;&#26469;&#20114;&#30456;&#36890;&#20449;&#12290;&#22312;&#26412;&#25351;&#21335;&#20013;&#65292;&#25105;&#20204;&#23558;&#25506;&#35752;&#22914;&#20309;&#21033;&#29992;&#20107;&#20214;&#30417;&#21548;&#22120;&#21644;&#35746;&#38405;&#32773;&#38057;&#20837;&#21040;Symfony&#30340;&#20107;&#20214;&#21457;&#24067;&#26426;&#21046;&#20013;&#12290;<\/p><h3>&#29702;&#35299;&#20107;&#20214;<\/h3><p>Symfony&#20107;&#20214;&#26159;&#24212;&#29992;&#31243;&#24207;&#25191;&#34892;&#20013;&#30340;&#29305;&#23450;&#28857;&#65292;&#20363;&#22914;&#35831;&#27714;&#30340;&#23436;&#25104;&#25110;&#23454;&#20307;&#30340;&#26356;&#26032;&#12290;&#24320;&#21457;&#20154;&#21592;&#21487;&#20197;&#33258;&#23450;&#20041;&#20107;&#20214;&#25110;&#21033;&#29992;Symfony&#25552;&#20379;&#30340;&#20107;&#20214;&#65292;&#24182;&#23558;&#20854;&#36923;&#36753;&#38468;&#21152;&#21040;&#36825;&#20123;&#20107;&#20214;&#19978;&#12290;<\/p><h2>&#20107;&#20214;&#30417;&#21548;&#22120;&#30340;&#35299;&#37322;<\/h2><p>&#20107;&#20214;&#30417;&#21548;&#22120;&#26159;&#19968;&#20010;PHP&#21487;&#35843;&#29992;&#20989;&#25968;&#65292;&#24403;&#23427;&#27880;&#20876;&#30340;&#20107;&#20214;&#34987;&#35302;&#21457;&#26102;&#20250;&#34987;&#36890;&#30693;&#12290;&#20197;&#19979;&#26159;&#23450;&#20041;&#19968;&#20010;&#20107;&#20214;&#30417;&#21548;&#22120;&#30340;&#26041;&#27861;&#65306;<\/p><pre><code>namespace AppEventListener;\n\nuse SymfonyComponentHttpKernelEventResponseEvent;\n\nclass ResponseListener\n{\n    public function onKernelResponse(ResponseEvent $event)\n    {\n        \/\/ ... modify the response object\n    }\n}\n<\/code><\/pre><p>&#20026;&#20102;&#27880;&#20876;&#36825;&#20010;&#30417;&#21548;&#22120;&#21040;&#20869;&#26680;&#21709;&#24212;&#20107;&#20214;&#65292;&#20320;&#38656;&#35201;&#22312; services.yaml &#25991;&#20214;&#20013;&#28155;&#21152;&#20197;&#19979;&#20869;&#23481;&#65306;<\/p><pre><code>services:\n    AppEventListenerResponseListener:\n        tags:\n            - { name: 'kernel.event_listener', event: 'kernel.response', method: 'onKernelResponse' }\n<\/code><\/pre><h2>&#20107;&#20214;&#35746;&#38405;&#32773;&#35299;&#37322;<\/h2><p>&#20107;&#20214;&#35746;&#38405;&#32773;&#26159;&#19968;&#31181;&#23454;&#29616;&#20102; EventSubscriberInterface &#30340;&#31867;&#65292;&#23427;&#23450;&#20041;&#20102;&#19968;&#20010;&#26041;&#27861;&#26469;&#35746;&#38405;&#19968;&#20010;&#25110;&#22810;&#20010;&#20107;&#20214;&#12290;&#20197;&#19979;&#26159;&#21019;&#24314;&#19968;&#20010;&#20107;&#20214;&#35746;&#38405;&#32773;&#30340;&#27493;&#39588;&#65306;<\/p><pre><code>namespace AppEventSubscriber;\n\nuse SymfonyComponentEventDispatcherEventSubscriberInterface;\nuse SymfonyComponentHttpKernelEventResponseEvent;\n\nclass AppSubscriber implements EventSubscriberInterface\n{\n    public static function getSubscribedEvents()\n    {\n        return [\n            'kernel.response' =&gt; 'onKernelResponse',\n        ];\n    }\n\n    public function onKernelResponse(ResponseEvent $event)\n    {\n        \/\/ ... modify the response object\n    }\n}\n<\/code><\/pre><p>&#24744;&#19981;&#38656;&#35201;&#25163;&#21160;&#20026;&#35746;&#38405;&#32773;&#25171;&#26631;&#31614;&#65292;&#26694;&#26550;&#20250;&#33258;&#21160;&#35782;&#21035;&#24182;&#27880;&#20876;&#23427;&#12290;<\/p><h2>&#21019;&#24314;&#33258;&#23450;&#20041;&#20107;&#20214;<\/h2><p>&#20320;&#21487;&#20197;&#21019;&#24314;&#33258;&#23450;&#20041;&#20107;&#20214;&#22312;Symfony&#20013;&#12290;&#36825;&#37324;&#26377;&#19968;&#20010;&#31034;&#20363;&#65306;<\/p><pre><code>namespace AppEvent;\n\nuse SymfonyContractsEventDispatcherEvent;\n\nclass PostCreatedEvent extends Event\n{\n    public const NAME = 'post.created';\n\n    protected $post;\n\n    public function __construct(Post $post)\n    {\n        $this-&gt;$post = $post;\n    }\n\n    public function getPost()\n    {\n        return $this-&gt;post;\n    }\n}\n<\/code><\/pre><p>&#20026;&#20102;&#35302;&#21457;PostCreated&#20107;&#20214;&#65292;&#20320;&#38656;&#35201;&#20351;&#29992;&#20107;&#20214;&#21457;&#24067;&#32773;&#65306;<\/p><pre><code>$event = new PostCreatedEvent($post);\n$eventDispatcher-&gt;dispatch($event, PostCreatedEvent::NAME);\n<\/code><\/pre><h2>&#21548;&#20247;&#20248;&#20808;&#26435;<\/h2><p>&#20320;&#38656;&#35201;&#25511;&#21046;&#21516;&#19968;&#20107;&#20214;&#30340;&#30417;&#21548;&#32773;&#25353;&#20160;&#20040;&#39034;&#24207;&#34987;&#35843;&#29992;&#12290;&#36825;&#36890;&#36807;&#20248;&#20808;&#32423;&#26469;&#23454;&#29616;&#12290;&#35753;&#25105;&#20204;&#30475;&#19968;&#20010;&#22312; services.yaml &#20013;&#30340;&#20363;&#23376;&#65306;<\/p><pre><code>services:\n    AppEventListenerFirstResponseListener:\n        tags:\n            - { name: 'kernel.event_listener', event: 'kernel.response', method: 'onKernelResponse', priority: 10 }\n    AppEventListenerSecondResponseListener:\n        tags:\n            - { name: 'kernel.event_listener', event: 'kernel.response', method: 'onKernelResponse', priority: 5 }\n<\/code><\/pre><p>&#22312;&#36825;&#31181;&#24773;&#20917;&#19979;&#65292;FirstResponseListener &#23558;&#22312; SecondResponseListener &#20043;&#21069;&#34987;&#35843;&#29992;&#12290;<\/p><h2>&#35843;&#35797;&#20107;&#20214;<\/h2><p>Symfony &#25552;&#20379;&#20102;&#19968;&#20010;&#21629;&#20196;&#34892;&#24037;&#20855;&#26469;&#35843;&#35797;&#20107;&#20214;&#30417;&#21548;&#22120;&#21644;&#35746;&#38405;&#32773;&#65306;<\/p><pre><code>php bin\/console debug:event-dispatcher<\/code><\/pre><p>&#35813;&#21629;&#20196;&#21015;&#20986;&#24744;&#30340;&#24212;&#29992;&#31243;&#24207;&#20013;&#27880;&#20876;&#30340;&#25152;&#26377;&#20107;&#20214;&#21450;&#20854;&#30417;&#21548;&#32773;&#65292;&#21253;&#25324;&#20248;&#20808;&#32423;&#12290;<\/p><h2>&#32467;&#35770;&#12290;<\/h2><p>&#23398;&#20064;&#22914;&#20309;&#27491;&#30830;&#20351;&#29992;&#20107;&#20214;&#30417;&#21548;&#22120;&#21644;&#35746;&#38405;&#32773;&#22312;Symfony&#26694;&#26550;&#20013;&#21487;&#20197;&#26174;&#33879;&#25552;&#21319;&#24212;&#29992;&#31243;&#24207;&#30340;&#24615;&#33021;&#65292;&#36890;&#36807;&#20419;&#36827;&#25972;&#27905;&#12289;&#35299;&#32806;&#21644;&#21487;&#27979;&#35797;&#30340;&#20195;&#30721;&#26469;&#23454;&#29616;&#36825;&#19968;&#30446;&#26631;&#12290;&#35831;&#35760;&#20303;&#35201;&#20805;&#20998;&#21033;&#29992;&#33258;&#23450;&#20041;&#20107;&#20214;&#65292;&#24182;&#26126;&#26234;&#22320;&#31649;&#29702;&#30417;&#21548;&#22120;&#20248;&#20808;&#32423;&#20197;&#20445;&#25345;&#23545;&#24212;&#29992;&#27969;&#30340;&#25511;&#21046;&#12290;<\/p><\/body>\r\n<\/div>\r\n<\/div>\r\n<\/div>\r\n<\/div><div class=\"wp-block-columns p-0 border is-layout-flex wp-container-core-columns-is-layout-28f84493 wp-block-columns-is-layout-flex\">\r\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\r\n<div class=\"wp-block-columns px-4 py-3 border-bottom has-background is-layout-flex wp-container-core-columns-is-layout-28f84493 wp-block-columns-is-layout-flex\" style=\"background:linear-gradient(243deg,rgb(238,238,238) 0%,rgba(58,166,242,0.15) 100%)\">\r\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\r\n<div class=\"wp-block-group is-nowrap is-layout-flex wp-container-core-group-is-layout-6c531013 wp-block-group-is-layout-flex\">\r\n<figure class=\"wp-block-image size-thumbnail is-resized is-style-rounded is-style-rounded--3\"><img decoding=\"async\" src=\"https:\/\/www.zhaozhao123.cn\/myitems\/images\/sites16\/2025\/06\/xygcfznnzczhsdmwydzhsmzzzmddnq-400x300.jpg\" alt=\"&#38271;&#24037;&#30721;&#22900;1523\" class=\"wp-image-2906\" style=\"object-fit:cover;width:30px;height:30px\"><\/figure>\r\n\r\n\r\n\r\n<h2 class=\"wp-block-heading my-0\" style=\"font-size:clamp(0.875rem, 0.875rem + ((1vw - 0.2rem) * 0.175), 1rem);\">&#38271;&#24037;&#30721;&#22900;1523<\/h2>\r\n<\/div>\r\n<\/div>\r\n<\/div>\r\n\r\n\r\n\r\n<div class=\"wp-block-columns px-xl-5 px-4 py-xl-4 py-3 is-layout-flex wp-container-core-columns-is-layout-28f84493 wp-block-columns-is-layout-flex\">\r\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\r\n<p>&#22312; Symfony &#26694;&#26550;&#20013;&#65292;&#20107;&#20214;&#26159;&#22788;&#29702;&#31995;&#32479;&#34892;&#20026;&#30340;&#19968;&#31181;&#26426;&#21046;&#65292;&#32780;&#30417;&#21548;&#22120;&#21644;&#35746;&#38405;&#32773;&#21017;&#26159;&#23454;&#29616;&#36825;&#19968;&#21151;&#33021;&#30340;&#20851;&#38190;&#32452;&#20214;&#12290;&#19979;&#38754;&#25105;&#20204;&#23558;&#20174;&#27010;&#24565;&#19978;&#29702;&#35299;&#23427;&#20204;&#65292;&#24182;&#25552;&#20379;&#19968;&#20123;&#23454;&#29992;&#30340;&#23454;&#36341;&#25351;&#21335;&#12290;<\/p>\n<h3>&#20160;&#20040;&#26159;&#20107;&#20214;&#65311;<\/h3>\n<p>&#22312; Symfony &#20013;&#65292;&#20107;&#20214;&#26159;&#19968;&#31181;&#25277;&#35937;&#30340;&#27010;&#24565;&#65292;&#23427;&#20195;&#34920;&#20102;&#19968;&#20010;&#29305;&#23450;&#26102;&#38388;&#28857;&#30340;&#29366;&#24577;&#21464;&#21270;&#12290;&#36890;&#36807;&#27880;&#20876;&#22810;&#20010;&#30417;&#21548;&#22120;&#21040;&#21516;&#19968;&#20010;&#20107;&#20214;&#65292;&#21487;&#20197;&#23558;&#19981;&#21516;&#31867;&#22411;&#30340;&#20107;&#20214;&#26144;&#23556;&#21040;&#19981;&#21516;&#30340;&#22788;&#29702;&#22120;&#20989;&#25968;&#12290;<\/p>\n<h3>&#20160;&#20040;&#26159;&#30417;&#21548;&#22120;&#65311;<\/h3>\n<p>&#30417;&#21548;&#22120;&#26159; Symfony &#20013;&#22788;&#29702;&#20107;&#20214;&#30340;&#19968;&#20010;&#25509;&#21475;&#12290;&#27599;&#20010;&#30417;&#21548;&#22120;&#37117;&#26377;&#19968;&#20010;&#21807;&#19968;&#30340;&#21517;&#31216;&#65292;&#29992;&#26469;&#26631;&#35782;&#20854;&#22788;&#29702;&#30340;&#20107;&#20214;&#31867;&#22411;&#12290;&#24403;&#26576;&#20010;&#20107;&#20214;&#21457;&#29983;&#26102;&#65292;&#26681;&#25454;&#25351;&#23450;&#30340;&#30417;&#21548;&#22120;&#21517;&#31216;&#65292;&#30456;&#24212;&#30340;&#22788;&#29702;&#22120;&#20250;&#34987;&#35843;&#29992;&#25191;&#34892;&#12290;<\/p>\n<h3>&#20160;&#20040;&#26159;&#35746;&#38405;&#32773;&#65311;<\/h3>\n<p>&#35746;&#38405;&#32773;&#26159;&#30417;&#21548;&#22120;&#30340;&#19968;&#20010;&#23454;&#20363;&#21270;&#29256;&#26412;&#65292;&#36127;&#36131;&#25509;&#25910;&#20107;&#20214;&#24182;&#35843;&#29992;&#23545;&#24212;&#30340;&#22788;&#29702;&#22120;&#26041;&#27861;&#12290;&#20026;&#20102;&#26356;&#22909;&#22320;&#25511;&#21046;&#20107;&#20214;&#30340;&#22788;&#29702;&#39034;&#24207;&#65292;&#27599;&#20010;&#35746;&#38405;&#32773;&#37117;&#25317;&#26377;&#19968;&#20010;&#20248;&#20808;&#32423;&#12290;&#22914;&#26524;&#20004;&#20010;&#35746;&#38405;&#32773;&#20855;&#26377;&#30456;&#21516;&#30340;&#20248;&#20808;&#32423;&#65292;&#37027;&#20040;&#25353;&#23383;&#27597;&#39034;&#24207;&#36827;&#34892;&#25490;&#24207;&#12290;<\/p>\n<h3>&#23454;&#36341;&#25351;&#21335;&#65306;<\/h3>\n<h4>&#21019;&#24314;&#30417;&#21548;&#22120;<\/h4>\n<ol>\n<li>\n<p><strong>&#23450;&#20041;&#20107;&#20214;<\/strong>&#65306;<\/p>\n<ul>\n<li>&#22312; <code>src\/Events<\/code> &#30446;&#24405;&#19979;&#21019;&#24314;&#19968;&#20010;&#26032;&#30340;&#25991;&#20214;&#65292;&#20363;&#22914; <code>EventSubscriber.php<\/code>&#12290;<\/li>\n<li>&#23450;&#20041;&#20107;&#20214;&#31867;&#65292;&#20363;&#22914; <code>MyEvent<\/code>&#12290;<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>&#23454;&#29616;&#30417;&#21548;&#22120;<\/strong>&#65306;<\/p>\n<ul>\n<li>&#32534;&#20889;&#19968;&#20010;&#32487;&#25215;&#33258; <code>ListenerInterface<\/code> &#30340;&#23454;&#29616;&#31867;&#65292;&#22914; <code>EventListener<\/code>.<\/li>\n<li>&#23454;&#29616; <code>on<\/code> &#26041;&#27861;&#65292;&#35813;&#26041;&#27861;&#25509;&#21463;&#19968;&#20010; <code>$event<\/code> &#21442;&#25968;&#65292;&#20854;&#20013; $event &#26159;&#20107;&#20214;&#23545;&#35937;&#12290;<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>&#27880;&#20876;&#30417;&#21548;&#22120;<\/strong>&#65306;<\/p>\n<ul>\n<li>&#22312; <code>config\/services.yaml<\/code> &#25110; <code>app\/config\/config.yml<\/code> &#25991;&#20214;&#20013;&#28155;&#21152;&#30417;&#21548;&#22120;&#37197;&#32622;&#12290;<\/li>\n<li>\n<p>&#31034;&#20363;&#65306;<\/p>\n<p>yaml:\nservices:\nEventSubscriber: &#8216;@EventSubscriber&#8217;<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>&#20351;&#29992;&#30417;&#21548;&#22120;<\/strong>&#65306;<\/p>\n<ul>\n<li>&#23558;&#30417;&#21548;&#22120;&#20316;&#20026;&#26381;&#21153;&#27880;&#20837;&#21040;&#25511;&#21046;&#22120;&#25110;&#20854;&#20182;&#32452;&#20214;&#20013;&#12290;<\/li>\n<li>&#22312;&#25511;&#21046;&#22120;&#25110;&#32452;&#20214;&#20013;&#35843;&#29992; <code>$this-&gt;get('EventSubscriber')<\/code> &#26469;&#33719;&#21462;&#23454;&#20363;&#12290;<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<h4>&#20351;&#29992;&#35746;&#38405;&#32773;<\/h4>\n<ol>\n<li>\n<p><strong>&#21019;&#24314;&#35746;&#38405;&#32773;<\/strong>&#65306;<\/p>\n<ul>\n<li>&#22312; <code>src\/Listeners<\/code> &#30446;&#24405;&#19979;&#21019;&#24314;&#19968;&#20010;&#26032;&#30340;&#25991;&#20214;&#65292;&#20363;&#22914; <code>SubscriptionListener.php<\/code>&#12290;<\/li>\n<li>&#23454;&#29616; <code>before()<\/code> &#21644; <code>after()<\/code> &#26041;&#27861;&#26469;&#22788;&#29702;&#20107;&#20214;&#21069;&#21518;&#30340;&#29366;&#24577;&#21464;&#21270;&#12290;<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>&#27880;&#20876;&#35746;&#38405;&#32773;<\/strong>&#65306;<\/p>\n<ul>\n<li>&#22312; <code>config\/services.yaml<\/code> &#25110; <code>app\/config\/config.yml<\/code> &#25991;&#20214;&#20013;&#28155;&#21152;&#35746;&#38405;&#32773;&#37197;&#32622;&#12290;<\/li>\n<li>\n<p>&#31034;&#20363;&#65306;<\/p>\n<p>yaml:\nservices:\nSubscriptionListener: &#8216;@SubscriptionListener&#8217;<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>&#20351;&#29992;&#35746;&#38405;&#32773;<\/strong>&#65306;<\/p>\n<ul>\n<li>&#23558;&#35746;&#38405;&#32773;&#20316;&#20026;&#26381;&#21153;&#27880;&#20837;&#21040;&#25511;&#21046;&#22120;&#25110;&#20854;&#20182;&#32452;&#20214;&#20013;&#12290;<\/li>\n<li>&#22312;&#25511;&#21046;&#22120;&#25110;&#32452;&#20214;&#20013;&#35843;&#29992; <code>$this-&gt;get('SubscriptionListener')<\/code> &#26469;&#33719;&#21462;&#23454;&#20363;&#12290;<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<h3>&#31034;&#20363;&#20195;&#30721;<\/h3>\n<p>&#20197;&#19979;&#26159;&#19968;&#20010;&#31616;&#21333;&#30340;&#20363;&#23376;&#65292;&#23637;&#31034;&#20102;&#22914;&#20309;&#22312; Symfony &#20013;&#20351;&#29992;&#20107;&#20214;&#30417;&#21548;&#22120;&#21644;&#35746;&#38405;&#32773;&#65306;<\/p>\n<pre><code class=\"language-php\">&lt;?php\n\nnamespace AppListeners;\n\nuse AppEventsSomeEvent;\nuse AppListenersSomeListener;\n\nclass SomeSubscriptionListener\n{\n    public function before(SomeEvent $event)\n    {\n        \/\/ &#22788;&#29702;&#20107;&#20214;&#21069;&#30340;&#25805;&#20316;\n    }\n\n    public function after(SomeEvent $event)\n    {\n        \/\/ &#22788;&#29702;&#20107;&#20214;&#21518;&#30340;&#25805;&#20316;\n    }\n}<\/code><\/pre>\n<p>&#22312;&#36825;&#20010;&#20363;&#23376;&#20013;&#65292;&#25105;&#20204;&#21019;&#24314;&#20102;&#19968;&#20010;&#21517;&#20026; <code>SomeSubscriptionListener<\/code> &#30340;&#35746;&#38405;&#32773;&#31867;&#65292;&#23427;&#23454;&#29616;&#20102; <code>ListenerInterface<\/code>&#12290;&#28982;&#21518;&#25105;&#20204;&#22312;&#25511;&#21046;&#22120;&#25110;&#20854;&#20182;&#32452;&#20214;&#20013;&#27880;&#20837;&#20102;&#36825;&#20010;&#35746;&#38405;&#32773;&#23454;&#20363;&#12290;&#24403;&#26576;&#20123;&#20107;&#20214;&#35302;&#21457;&#26102;&#65292;&#25105;&#20204;&#21487;&#20197;&#36890;&#36807; <code>$this-&gt;get('SomeSubscriptionListener')<\/code> &#35843;&#29992;&#23427;&#30340; <code>before()<\/code> &#21644; <code>after()<\/code> &#26041;&#27861;&#26469;&#36827;&#34892;&#30456;&#24212;&#22788;&#29702;&#12290;<\/p>\n<p>&#36825;&#26679;&#65292;&#25105;&#20204;&#23601;&#25104;&#21151;&#22320;&#22312; Symfony &#20013;&#23454;&#29616;&#20102;&#20107;&#20214;&#30417;&#21548;&#22120;&#21644;&#35746;&#38405;&#32773;&#30340;&#20351;&#29992;&#12290;&#24076;&#26395;&#36825;&#33021;&#24110;&#21161;&#24744;&#29702;&#35299;&#21644;&#24212;&#29992;&#36825;&#20123;&#27010;&#24565;&#65281;<\/p>\r\n<\/div>\r\n<\/div>\r\n<\/div>\r\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Bug&#32534;&#35793;&#29422; &#26631;&#39064;&#65306;Symfony&#26694;&#26550;&#20013;&#30340;&#20107;&#20214;&#30417;&#21548;&#22120;&#19982;&#35746;&#38405;&#038;#327..<\/p>\n","protected":false},"author":1,"featured_media":0,"menu_order":0,"template":"","meta":{"_acf_changed":false},"tags":[],"my1js2nav":[45],"tuisongtax":[],"class_list":["post-1080","my1js","type-my1js","status-publish","hentry","my1js2nav-symfony"],"acf":{"qian_art_seotitle":"","qian_art_seotitle_source":{"label":"SEO\u6807\u9898","type":"text","formatted_value":""},"qian_art_seokws":"","qian_art_seokws_source":{"label":"SEO\u5173\u952e\u8bcd","type":"text","formatted_value":""},"qian_art_stzhong":"","qian_art_stzhong_source":{"label":"\u4e2d | \u77ed\u6807\u9898","type":"text","formatted_value":""}},"_links":{"self":[{"href":"https:\/\/www.zhaozhao123.cn\/php\/wp-json\/wp\/v2\/my1js\/1080","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.zhaozhao123.cn\/php\/wp-json\/wp\/v2\/my1js"}],"about":[{"href":"https:\/\/www.zhaozhao123.cn\/php\/wp-json\/wp\/v2\/types\/my1js"}],"author":[{"embeddable":true,"href":"https:\/\/www.zhaozhao123.cn\/php\/wp-json\/wp\/v2\/users\/1"}],"wp:attachment":[{"href":"https:\/\/www.zhaozhao123.cn\/php\/wp-json\/wp\/v2\/media?parent=1080"}],"wp:term":[{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.zhaozhao123.cn\/php\/wp-json\/wp\/v2\/tags?post=1080"},{"taxonomy":"my1js2nav","embeddable":true,"href":"https:\/\/www.zhaozhao123.cn\/php\/wp-json\/wp\/v2\/my1js2nav?post=1080"},{"taxonomy":"tuisongtax","embeddable":true,"href":"https:\/\/www.zhaozhao123.cn\/php\/wp-json\/wp\/v2\/tuisongtax?post=1080"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}