# Non-static method Cake\\Routing\\RouteBuilder::scope() cannot be called statically

**URL:** <https://discourse.cakephp.org/t/non-static-method-cake-routing-routebuilder-scope-cannot-be-called-statically/10993>\
**Category:** Need Help\
**Tags:** help\
**Created:** [March 2, 2023, 4:53pm UTC](https://discourse.cakephp.org/t/non-static-method-cake-routing-routebuilder-scope-cannot-be-called-statically/10993 "2023-03-02T16:53:36Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![spadeX](https://avatars.discourse-cdn.com/v4/letter/s/919ad9/32.png) [@spadeX](https://discourse.cakephp.org/u/spadeX)\
**Post date:** [March 2, 2023, 4:53pm UTC](https://discourse.cakephp.org/t/non-static-method-cake-routing-routebuilder-scope-cannot-be-called-statically/10993/1 "2023-03-02T16:53:36Z")

</div>

Non-static method Cake\Routing\RouteBuilder::scope() cannot be called statically

getting error Please let me know this error solution

---

<div class="post-metadata">

**Author:** ![KevinPfeifer](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/kevinpfeifer/32/3365_2.png) [@KevinPfeifer](https://discourse.cakephp.org/u/KevinPfeifer)\
**Post date:** [March 2, 2023, 7:07pm UTC](https://discourse.cakephp.org/t/non-static-method-cake-routing-routebuilder-scope-cannot-be-called-statically/10993/2 "2023-03-02T19:07:10Z")

</div>

Make sure your routes.php file is built like

> <https://github.com/cakephp/app/blob/4.x/config/routes.php>

---

<div class="post-metadata">

**Author:** ![spadeX](https://avatars.discourse-cdn.com/v4/letter/s/919ad9/32.png) [@spadeX](https://discourse.cakephp.org/u/spadeX)\
**Post date:** [March 3, 2023, 5:50am UTC](https://discourse.cakephp.org/t/non-static-method-cake-routing-routebuilder-scope-cannot-be-called-statically/10993/3 "2023-03-03T05:50:10Z")

</div>

I have done as follows Please what is wrong in my code.

```auto
  RouteBuilder::scope('/ContactDetails/add', function (RouteBuilder $routes) {
    // Prior to 3.5.0 use `extensions()`
            $routes->setExtensions(['json']);
            $routes->resources('ContactDetails');
         });

```

I got an error non-static method cake\Routing\RouteBuilder::scope() cannot be called statically.

---

<div class="post-metadata">

**Author:** ![KevinPfeifer](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/kevinpfeifer/32/3365_2.png) [@KevinPfeifer](https://discourse.cakephp.org/u/KevinPfeifer)\
**Post date:** [March 3, 2023, 1:16pm UTC](https://discourse.cakephp.org/t/non-static-method-cake-routing-routebuilder-scope-cannot-be-called-statically/10993/4 "2023-03-03T13:16:52Z")

</div>

Don’t call `RouteBuilder::scope` which is a static method.  
Wrap your routes (like the example file) so you always have an object

```auto
return static function (RouteBuilder $routes) {

    $routes->setRouteClass(DashedRoute::class);
    $routes->scope('/', function (RouteBuilder $builder) {
        $builder->scope('/ContactDetails/add', function (RouteBuilder $routes) {
            $routes->setExtensions(['json']);
            $routes->resources('ContactDetails');
        });
        $builder->fallbacks();
    });

};

```

---

<div class="post-metadata">

**Author:** ![spadeX](https://avatars.discourse-cdn.com/v4/letter/s/919ad9/32.png) [@spadeX](https://discourse.cakephp.org/u/spadeX)\
**Post date:** [March 3, 2023, 4:33pm UTC](https://discourse.cakephp.org/t/non-static-method-cake-routing-routebuilder-scope-cannot-be-called-statically/10993/5 "2023-03-03T16:33:23Z")

</div>

![test](https://canada1.discourse-cdn.com/flex029/uploads/cakephp/original/2X/d/dcbefed5ff0ebbdc0b8904c52e13b67ba3bd9aa0.png)

I follow the same as you mentioned code but i got the error. remove following code

```auto
->add(new CsrfProtectionMiddleware([
                'httponly' => true,
            ]))

```

I need the react app post data to my cakephp app so that i can store data but i got above error.

---

<div class="post-metadata">

**Author:** ![KevinPfeifer](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/kevinpfeifer/32/3365_2.png) [@KevinPfeifer](https://discourse.cakephp.org/u/KevinPfeifer)\
**Post date:** [March 3, 2023, 5:13pm UTC](https://discourse.cakephp.org/t/non-static-method-cake-routing-routebuilder-scope-cannot-be-called-statically/10993/6 "2023-03-03T17:13:39Z")

</div>

You need to add e.g.

- a `X-CSRF-Token` HTTP header to your HTTP requests from react which contains the value from the `_csrfToken` hidden input
- if its a form you submit via POST you can also just add that `_csrfToken` value as part of the submitted data

See [CSRF Protection - 4.x](https://book.cakephp.org/4/en/security/csrf.html#csrf-protection-and-ajax-requests)

But that has nothing to do with your initial problem.
