# Cakephp 2.5 call one controller method inside another controller

**URL:** <https://discourse.cakephp.org/t/cakephp-2-5-call-one-controller-method-inside-another-controller/2927>\
**Category:** Uncategorized\
**Created:** [July 25, 2017, 12:59pm UTC](https://discourse.cakephp.org/t/cakephp-2-5-call-one-controller-method-inside-another-controller/2927 "2017-07-25T12:59:08Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![angelorigo](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/angelorigo/32/193_2.png) [@angelorigo](https://discourse.cakephp.org/u/angelorigo)\
**Post date:** [July 25, 2017, 12:59pm UTC](https://discourse.cakephp.org/t/cakephp-2-5-call-one-controller-method-inside-another-controller/2927/1 "2017-07-25T12:59:08Z")

</div>

Hi,

Can i call a controller method (A) inside another controller (B) ?

The only way i know is using a redirect, i am searching for a way to call without using redirect.

---

<div class="post-metadata">

**Author:** ![enmacc](https://avatars.discourse-cdn.com/v4/letter/e/ee59a6/32.png) [@enmacc](https://discourse.cakephp.org/u/enmacc)\
**Post date:** [July 26, 2017, 4:35pm UTC](https://discourse.cakephp.org/t/cakephp-2-5-call-one-controller-method-inside-another-controller/2927/2 "2017-07-26T16:35:03Z")

</div>

Try to use oop,

use(‘AController’,'Controller);  
class BController …  
function bb(){  
$a = new AController();  
…  
$a-\>aa();  
…  
}

---

<div class="post-metadata">

**Author:** ![etipaced](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/etipaced/32/3338_2.png) [@etipaced](https://discourse.cakephp.org/u/etipaced)\
**Post date:** [July 27, 2017, 2:47pm UTC](https://discourse.cakephp.org/t/cakephp-2-5-call-one-controller-method-inside-another-controller/2927/3 "2017-07-27T14:47:25Z")

</div>

It’s not really good practice to do this. You can, as you said, use a redirect to pass control of your application to another Controller method altogether. However, if you don’t want to do that, you can factor the logic that you need into a Model method which can then be shared from any controller. Remember that all business logic should really be in your models anyway. Controllers simply respond to and field incoming requests (sort of like a traffic cop).

If your logic isn’t business-related, you can always factor your method into a Component which can then be shared with any other Controller in your app.

Component Docs  
[https://book.cakephp.org/2.0/en/controllers/components.html](https://book.cakephp.org/2.0/en/controllers/components.html)

The “Fat Model” Concept  
[https://book.cakephp.org/2.0/en/models/additional-methods-and-properties.html](https://book.cakephp.org/2.0/en/models/additional-methods-and-properties.html)

HTH

---

<div class="post-metadata">

**Author:** ![angelorigo](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/angelorigo/32/193_2.png) [@angelorigo](https://discourse.cakephp.org/u/angelorigo)\
**Post date:** [July 27, 2017, 6:17pm UTC](https://discourse.cakephp.org/t/cakephp-2-5-call-one-controller-method-inside-another-controller/2927/4 "2017-07-27T18:17:51Z")

</div>

I will use a componet. Is a shared logic i will use into two controllers. Thank you !

---

<div class="post-metadata">

**Author:** ![jarekgol](https://avatars.discourse-cdn.com/v4/letter/j/58956e/32.png) [@jarekgol](https://discourse.cakephp.org/u/jarekgol)\
**Post date:** [August 3, 2017, 7:45pm UTC](https://discourse.cakephp.org/t/cakephp-2-5-call-one-controller-method-inside-another-controller/2927/5 "2017-08-03T19:45:23Z")

</div>

in 3.0 I use $this-\>action\_name() (method) and it works (in same controller).
