> For the complete documentation index, see [llms.txt](https://docs.cs-cart.jp/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.cs-cart.jp/core/controllers/pre-and-post-controllers.md).

# Pre\&Post コントローラー

Pre-controllers（プレ・コントローラー）とPost-controllers（ポスト・コントローラー）は 標準のコントローラーが実行された前後に呼び出される（アドオンファイルの構造内での名前や場所に応じて）特別なPHPファイルです。

例:

* 「添付ファイルアドオン」の\_/controllers/backendや/controllers/frontend\_ディレクトリで次のようなファイルをみつけることができます: `products.post.php`

```
/app/addons/attachments/controllers/backend/products.post.php
```

これらのディレクトリ内にあるファイルはアドオン専用のコントローラーか標準コントローラー用のpre-/post-controllers どちらかです。

* pre- または post-controller ファイルの名前は以下のような構造(命名規則)となります。:

```http
[controller名].[pre/post].php
```

“products”はCS-Cartのコアコントローラー(標準コントローラー)なので、pre- または post-controllerを宣言することができます。ファイル名最後の「.post」 は、標準の“products”コントローラーが動作した後に実行されることを示しています。

```php
<?php
...
if ($mode == 'update') {
    // Assign attachments files for products
    $attachments = fn_get_attachments('product', $_REQUEST['product_id'], 'M', DESCR_SL);

    Registry::set('navigation.tabs.attachments', array (
        'title' => __('attachments'),
        'js' => true
    ));

    Registry::get('view')->assign('attachments', $attachments);
}
```

標準コントローラーの実行前に動作させたい場合は、.postを.preに置き換えて下さい。

* products.**post**.php ・・・ productsコントローラーの後に実行される
* products.**pre**.php ・・・ productsコントローラーの前に実行される


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.cs-cart.jp/core/controllers/pre-and-post-controllers.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
