# Cakephp function call from outside cakephp how?

**URL:** <https://discourse.cakephp.org/t/cakephp-function-call-from-outside-cakephp-how/7593>\
**Category:** Need Help\
**Created:** [April 4, 2020, 5:51am UTC](https://discourse.cakephp.org/t/cakephp-function-call-from-outside-cakephp-how/7593 "2020-04-04T05:51:40Z")\
**Posts on this page:** 9\
**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:** [April 4, 2020, 5:51am UTC](https://discourse.cakephp.org/t/cakephp-function-call-from-outside-cakephp-how/7593/1 "2020-04-04T05:51:40Z")

</div>

Already build project and i want call some controller function to out side in webroot their directory created some php file and function which works in background .

controller function called that php files how can i do? Is it possible ?

---

<div class="post-metadata">

**Author:** ![Zuluru](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/zuluru/32/1230_2.png) [@Zuluru](https://discourse.cakephp.org/u/Zuluru)\
**Post date:** [April 4, 2020, 2:55pm UTC](https://discourse.cakephp.org/t/cakephp-function-call-from-outside-cakephp-how/7593/2 "2020-04-04T14:55:28Z")

</div>

This is not clear. You have something outside of your controller that you want the controller to be able to call? Or you have something in your controller that you want something outside of it to be able to call?

---

<div class="post-metadata">

**Author:** ![dreamingmind](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/dreamingmind/32/1857_2.png) [@dreamingmind](https://discourse.cakephp.org/u/dreamingmind)\
**Post date:** [April 4, 2020, 4:57pm UTC](https://discourse.cakephp.org/t/cakephp-function-call-from-outside-cakephp-how/7593/3 "2020-04-04T16:57:43Z")

</div>

I was reading it to mean

`external-program --> calls --> cake-application`

---

<div class="post-metadata">

**Author:** ![Zuluru](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/zuluru/32/1230_2.png) [@Zuluru](https://discourse.cakephp.org/u/Zuluru)\
**Post date:** [April 4, 2020, 10:26pm UTC](https://discourse.cakephp.org/t/cakephp-function-call-from-outside-cakephp-how/7593/4 "2020-04-04T22:26:29Z")

</div>

Yeah, but also “call some controller function _to_ out side”, so I’m not 100%. And the answers to each are obviously very different.

---

<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:** [April 5, 2020, 11:13am UTC](https://discourse.cakephp.org/t/cakephp-function-call-from-outside-cakephp-how/7593/5 "2020-04-05T11:13:55Z")

</div>

Yes, your right [dreamingmind](https://discourse.cakephp.org/u/dreamingmind), [Zuluru](https://discourse.cakephp.org/u/Zuluru) I want something like that.

So i create my function like REST API and call from outside but i got an error CSRF token mismatch so how can i resolve this problem. What should i do now Please tell me. is that wrong flow. i don’t want disable CSRF token.

I tried on testing that call on postman and i got error csrf token mismatch

---

<div class="post-metadata">

**Author:** ![Zuluru](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/zuluru/32/1230_2.png) [@Zuluru](https://discourse.cakephp.org/u/Zuluru)\
**Post date:** [April 5, 2020, 4:20pm UTC](https://discourse.cakephp.org/t/cakephp-function-call-from-outside-cakephp-how/7593/6 "2020-04-05T16:20:05Z")

</div>

So this is an entirely standard access of a controller function through your web server, and it works if you disable CSRF? That’s not at all what your original question implied. More specifics would probably help us to understand.

---

<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:** [April 6, 2020, 5:31am UTC](https://discourse.cakephp.org/t/cakephp-function-call-from-outside-cakephp-how/7593/7 "2020-04-06T05:31:29Z")

</div>

My cake app. live so i want some background cron jobs so i need some function defined in my controller which get me reqired data for my cron job so i want implement the such functionality .  
So make my function REST function for accessing that data for that cron job. but i got error in CSRF token mismatch .

---

<div class="post-metadata">

**Author:** ![Zuluru](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/zuluru/32/1230_2.png) [@Zuluru](https://discourse.cakephp.org/u/Zuluru)\
**Post date:** [April 6, 2020, 3:05pm UTC](https://discourse.cakephp.org/t/cakephp-function-call-from-outside-cakephp-how/7593/8 "2020-04-06T15:05:59Z")

</div>

Okay. So, the short answer is that’s the wrong way to do it. 🙂

What you should do is to move that function into the model, and use that function from both the controller and your cron job.

---

<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:** [April 7, 2020, 4:49am UTC](https://discourse.cakephp.org/t/cakephp-function-call-from-outside-cakephp-how/7593/9 "2020-04-07T04:49:12Z")

</div>

Ok thanks I am implemented that code and check it.
