{"id":13296,"date":"2014-05-02T13:28:30","date_gmt":"2014-05-02T07:58:30","guid":{"rendered":"http:\/\/www.tothenew.com\/blog\/?p=13296"},"modified":"2017-02-12T19:21:12","modified_gmt":"2017-02-12T13:51:12","slug":"common-functionality-among-multiple-controllers","status":"publish","type":"post","link":"https:\/\/www.tothenew.com\/blog\/common-functionality-among-multiple-controllers\/","title":{"rendered":"Common functionality among Multiple Controllers"},"content":{"rendered":"<p>Many a times, we see a requirement, where we have to write same <strong>functions<\/strong> in multiple <strong>controllers<\/strong> just to <strong>share<\/strong> a <strong>common<\/strong> <strong>functionality<\/strong> among them, which is a bad approach, because in future, if any changes are required to that <strong>function<\/strong>, we\u2019ll have to make the changes manually in all the copies of that <strong>function<\/strong> where it is defined or if we want to add that particular <strong>functionality<\/strong> in another <strong>controller<\/strong>, again we\u2019ll have to copy-paste the whole <strong>function<\/strong> <strong>scope<\/strong> in that <strong>controller<\/strong> too. And doing so is completely against the <strong>DRY (Don&#8217;t Repeat Yourself) principle<\/strong>.<\/p>\n<p>So to solve this problem, we write <strong>directives<\/strong>. Let\u2019s play more with the <strong>directives<\/strong> \ud83d\ude09<\/p>\n<p><strong>NOTE:<\/strong> If you are not aware with the basics of <strong>directives<\/strong>, then I will advice you to please read the links below to get to know an idea of <strong>Directives<\/strong>:<br \/>\n1. <a href=\"http:\/\/www.itsgroovybaby.in\/blog\/javascript\/angularjs\/angularjs-directives-introduction\/\" target=\"_blank\">Directive Introduction<\/a><br \/>\n2. Components in AngularJS<\/p>\n<p>In my AngularJS Routes blog, we made a single page application (With user CRUD functionality) demo. We were having remove user functionality only in LIST page, but now we want to add remove <strong>functionality<\/strong> to SHOW and EDIT Page. So instead of doing copy-paste in SHOW and EDIT page, we are going to write <strong>directive<\/strong> for that as below:<br \/>\n[js]<br \/>\n\/*<br \/>\n * Defining RemoveUserFunctionality Directive, to share it among<br \/>\n * multiple controllers. This directive injects remove function to scope where it is marked.<br \/>\n * *\/<br \/>\nrouteTestModule.directive(&#8216;removeUserFunctionality&#8217;, [&#8216;$location&#8217;, function ($location) {<br \/>\n    return {<br \/>\n        scope: true,<br \/>\n        link: function ($scope) {<br \/>\n            \/*<br \/>\n             * We remove function from ListUserController and place it here (in directive),<br \/>\n             * And inject remove function everywhere with the help of this directive.<br \/>\n             * *\/<br \/>\n            $scope.remove = function (id) {<br \/>\n                $scope.users = _.filter(users, function (user) {<br \/>\n                    return user.id != id;<br \/>\n                });<br \/>\n                users = $scope.users;<br \/>\n                $location.path(&amp;quot;\/user\/list&amp;quot;);<br \/>\n            };<br \/>\n        }<br \/>\n    }<br \/>\n}]);<br \/>\n[\/js]<br \/>\nLet\u2019s use removeUserFunctionality <strong>directive<\/strong> and add Remove function to EDIT and SHOW Pages as below:<\/p>\n<p><strong>partials\/edit.html:<\/strong><br \/>\n[html]<br \/>\n&amp;lt;!&#8211; We are using remove-user-functionality directive to inject Remove function into scope &#8211;&amp;gt;<br \/>\n&amp;lt;table remove-user-functionality&amp;gt;<br \/>\n    &amp;lt;tr&amp;gt;<br \/>\n        &amp;lt;td&amp;gt;Name&amp;lt;\/td&amp;gt;<br \/>\n        &amp;lt;td&amp;gt;{{user.name}}&amp;lt;\/td&amp;gt;<br \/>\n    &amp;lt;\/tr&amp;gt;<br \/>\n    &amp;lt;tr&amp;gt;<br \/>\n        &amp;lt;td&amp;gt;Age&amp;lt;\/td&amp;gt;<br \/>\n        &amp;lt;td&amp;gt;{{user.age}}&amp;lt;\/td&amp;gt;<br \/>\n    &amp;lt;\/tr&amp;gt;<br \/>\n    &amp;lt;tr&amp;gt;<br \/>\n        &amp;lt;td&amp;gt;&amp;lt;a ng-href=&amp;quot;#\/user\/edit\/{{user.id}}&amp;quot;&amp;gt;Edit&amp;lt;\/a&amp;gt;&amp;lt;\/td&amp;gt;<br \/>\n        &amp;lt;td&amp;gt;&amp;lt;input type=&amp;quot;button&amp;quot; value=&amp;quot;Remove&amp;quot; ng-click=&amp;quot;remove(user.id)&amp;quot; \/&amp;gt;&amp;lt;\/td&amp;gt;<br \/>\n        &amp;lt;!&#8211;<br \/>\n        Here Remove function is not defined into EditUserController, its injected by<br \/>\n        remove-user-functionality directive.<br \/>\n        &#8211;&amp;gt;<br \/>\n    &amp;lt;\/tr&amp;gt;<br \/>\n&amp;lt;\/table&amp;gt;<br \/>\n[\/html]<\/p>\n<p><strong>partials\/show.html<\/strong>:<br \/>\n[html]<br \/>\n&amp;lt;!&#8211; We are using remove-user-functionality directive to inject Remove function into scope &#8211;&amp;gt;<br \/>\n&amp;lt;table remove-user-functionality&amp;gt;<br \/>\n    &amp;lt;tr&amp;gt;<br \/>\n        &amp;lt;td&amp;gt;Name&amp;lt;\/td&amp;gt;<br \/>\n        &amp;lt;td&amp;gt;&amp;lt;input type=&amp;quot;text&amp;quot; ng-model=&amp;quot;user.name&amp;quot; \/&amp;gt;&amp;lt;\/td&amp;gt;<br \/>\n    &amp;lt;\/tr&amp;gt;<br \/>\n    &amp;lt;tr&amp;gt;<br \/>\n        &amp;lt;td&amp;gt;Age&amp;lt;\/td&amp;gt;<br \/>\n        &amp;lt;td&amp;gt;&amp;lt;input type=&amp;quot;text&amp;quot; ng-model=&amp;quot;user.age&amp;quot; \/&amp;gt;&amp;lt;\/td&amp;gt;<br \/>\n    &amp;lt;\/tr&amp;gt;<br \/>\n    &amp;lt;tr&amp;gt;<br \/>\n        &amp;lt;td&amp;gt;&amp;lt;input type=&amp;quot;button&amp;quot; value=&amp;quot;Cancel&amp;quot; ng-click=&amp;quot;cancel()&amp;quot;\/&amp;gt;&amp;lt;\/td&amp;gt;<br \/>\n        &amp;lt;td&amp;gt;&amp;lt;input type=&amp;quot;button&amp;quot; value=&amp;quot;Update&amp;quot; ng-click=&amp;quot;update()&amp;quot;\/&amp;gt;&amp;lt;\/td&amp;gt;<br \/>\n        &amp;lt;td&amp;gt;&amp;lt;input type=&amp;quot;button&amp;quot; value=&amp;quot;Remove&amp;quot; ng-click=&amp;quot;remove(user.id)&amp;quot; \/&amp;gt;&amp;lt;\/td&amp;gt;<br \/>\n        &amp;lt;!&#8211;<br \/>\n        Here also Remove function is not defined in ShowUserController, rather injected by<br \/>\n        remove-user-functionality directive.<br \/>\n        &#8211;&amp;gt;<br \/>\n    &amp;lt;\/tr&amp;gt;<br \/>\n&amp;lt;\/table&amp;gt;<br \/>\n[\/html]<\/p>\n<p><strong>partials\/list.html:<\/strong><br \/>\n[html]<br \/>\n&amp;lt;!&#8211; We are using remove-user-functionality directive to inject remove function into scope &#8211;&amp;gt;<br \/>\n&amp;lt;table remove-user-functionality&amp;gt;<br \/>\n    &amp;lt;tr&amp;gt;<br \/>\n        &amp;lt;td&amp;gt;Id&amp;lt;\/td&amp;gt;<br \/>\n        &amp;lt;td&amp;gt;Name&amp;lt;\/td&amp;gt;<br \/>\n        &amp;lt;td&amp;gt;Age&amp;lt;\/td&amp;gt;<br \/>\n        &amp;lt;td&amp;gt;&amp;lt;\/td&amp;gt;<br \/>\n        &amp;lt;td&amp;gt;&amp;lt;\/td&amp;gt;<br \/>\n    &amp;lt;\/tr&amp;gt;<br \/>\n    &amp;lt;tr ng-repeat=&amp;quot;user in users&amp;quot;&amp;gt;<br \/>\n        &amp;lt;td&amp;gt;&amp;lt;a ng-href=&amp;quot;#\/user\/show\/{{user.id}}&amp;quot;&amp;gt;{{user.id}}&amp;lt;\/a&amp;gt;&amp;lt;\/td&amp;gt;<br \/>\n        &amp;lt;td&amp;gt;{{user.name}}&amp;lt;\/td&amp;gt;<br \/>\n        &amp;lt;td&amp;gt;{{user.age}}&amp;lt;\/td&amp;gt;<br \/>\n        &amp;lt;td&amp;gt;&amp;lt;a ng-href=&amp;quot;#\/user\/edit\/{{user.id}}&amp;quot;&amp;gt;Edit&amp;lt;\/a&amp;gt;&amp;lt;\/td&amp;gt;<br \/>\n        &amp;lt;td&amp;gt;&amp;lt;input type=&amp;quot;button&amp;quot; value=&amp;quot;Remove&amp;quot; ng-click=&amp;quot;remove(user.id)&amp;quot; \/&amp;gt;&amp;lt;\/td&amp;gt;<br \/>\n        &amp;lt;!&#8211;<br \/>\n        Again Remove function is not defined in UserListController, it is injected by<br \/>\n        remove-user-functionality directive.<br \/>\n        &#8211;&amp;gt;<br \/>\n    &amp;lt;\/tr&amp;gt;<br \/>\n&amp;lt;\/table&amp;gt;<br \/>\n[\/html]<\/p>\n<p>After this, if any change is required, we have to make it only in removeUserFunctionality <strong>Directive<\/strong>, and we can use it everywhere. \ud83d\ude42<\/p>\n<p><strong>NOTE:<\/strong> You can checkout full working source code from this <a href=\"https:\/\/github.com\/AmitThakkar\/AngularDemo\" target=\"_blank\">link<\/a>.<\/p>\n<p>Amit Kumar<br \/>\n<a href=\"http:\/\/www.tothenew.com\/blog\/author\/amit.kumar\/\">amit.kumar@intelligrape.com<\/a><br \/>\nin.linkedin.com\/in\/amitkumar0110<br \/>\ntwitter.com\/amit_kumar0110<br \/>\n<strong><a href=\"http:\/\/www.tothenew.com\/blog\/author\/amit-kumar\/\">More Blogs by Me<\/a><\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Many a times, we see a requirement, where we have to write same functions in multiple controllers just to share a common functionality among them, which is a bad approach, because in future, if any changes are required to that function, we\u2019ll have to make the changes manually in all the copies of that function [&hellip;]<\/p>\n","protected":false},"author":52,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":5,"footnotes":""},"categories":[1],"tags":[955,1419,1420,867,1300,456],"class_list":["post-13296","post","type-post","status-publish","format-standard","hentry","category-technology","tag-angularjs","tag-common","tag-controller","tag-multiple","tag-scope","tag-sharing"],"aioseo_notices":[],"aioseo_head":"\n\t\t<!-- All in One SEO 5.0.0.1 - aioseo.com -->\n\t<meta name=\"description\" content=\"Many a times, we see a requirement, where we have to write same functions in multiple controllers just to share a common functionality among them, which is a bad approach, because in future, if any changes are required to that function, we\u2019ll have to make the changes manually in all the copies of that function\" \/>\n\t<meta name=\"robots\" content=\"max-image-preview:large\" \/>\n\t<meta name=\"author\" content=\"Amit Kumar\"\/>\n\t<link rel=\"canonical\" href=\"https:\/\/www.tothenew.com\/blog\/common-functionality-among-multiple-controllers\/\" \/>\n\t<meta name=\"generator\" content=\"All in One SEO (AIOSEO) 5.0.0.1\" \/>\n\t\t<meta property=\"og:locale\" content=\"en_US\" \/>\n\t\t<meta property=\"og:site_name\" content=\"TO THE NEW BLOG\" \/>\n\t\t<meta property=\"og:type\" content=\"blog\" \/>\n\t\t<meta property=\"og:title\" content=\"Common functionality among Multiple Controllers | TO THE NEW Blog\" \/>\n\t\t<meta property=\"og:description\" content=\"Many a times, we see a requirement, where we have to write same functions in multiple controllers just to share a common functionality among them, which is a bad approach, because in future, if any changes are required to that function, we\u2019ll have to make the changes manually in all the copies of that function\" \/>\n\t\t<meta property=\"og:url\" content=\"https:\/\/www.tothenew.com\/blog\/common-functionality-among-multiple-controllers\/\" \/>\n\t\t<meta property=\"og:image\" content=\"https:\/\/www.tothenew.com\/blog\/wp-content\/themes\/ttn\/images\/social-logo.png\" \/>\n\t\t<meta property=\"og:image:secure_url\" content=\"https:\/\/www.tothenew.com\/blog\/wp-content\/themes\/ttn\/images\/social-logo.png\" \/>\n\t\t<meta name=\"twitter:card\" content=\"summary\" \/>\n\t\t<meta name=\"twitter:site\" content=\"@tothenew\" \/>\n\t\t<meta name=\"twitter:title\" content=\"Common functionality among Multiple Controllers | TO THE NEW Blog\" \/>\n\t\t<meta name=\"twitter:description\" content=\"Many a times, we see a requirement, where we have to write same functions in multiple controllers just to share a common functionality among them, which is a bad approach, because in future, if any changes are required to that function, we\u2019ll have to make the changes manually in all the copies of that function\" \/>\n\t\t<meta name=\"twitter:image\" content=\"https:\/\/www.tothenew.com\/blog\/wp-content\/themes\/ttn\/images\/social-logo.png\" \/>\n\t\t<script type=\"application\/ld+json\" class=\"aioseo-schema\">\n\t\t\t{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/common-functionality-among-multiple-controllers\\\/#article\",\"name\":\"Common functionality among Multiple Controllers | TO THE NEW Blog\",\"headline\":\"Common functionality among Multiple Controllers\",\"author\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/author\\\/amit-kumar\\\/#author\"},\"publisher\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/#organization\"},\"datePublished\":\"2014-05-02T13:28:30+05:30\",\"dateModified\":\"2017-02-12T19:21:12+05:30\",\"inLanguage\":\"en-US\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/common-functionality-among-multiple-controllers\\\/#webpage\"},\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/common-functionality-among-multiple-controllers\\\/#webpage\"},\"articleSection\":\"Technology, AngularJS, common, controller, multiple, scope, sharing\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/common-functionality-among-multiple-controllers\\\/#breadcrumblist\",\"itemListElement\":[{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog#listItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.tothenew.com\\\/blog\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/category\\\/technology\\\/#listItem\",\"name\":\"Technology\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/category\\\/technology\\\/#listItem\",\"position\":2,\"name\":\"Technology\",\"item\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/category\\\/technology\\\/\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/common-functionality-among-multiple-controllers\\\/#listItem\",\"name\":\"Common functionality among Multiple Controllers\"},\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog#listItem\",\"name\":\"Home\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/common-functionality-among-multiple-controllers\\\/#listItem\",\"position\":3,\"name\":\"Common functionality among Multiple Controllers\",\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/category\\\/technology\\\/#listItem\",\"name\":\"Technology\"}}]},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/#organization\",\"name\":\"TO THE NEW Blog\",\"url\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/author\\\/amit-kumar\\\/#author\",\"url\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/author\\\/amit-kumar\\\/\",\"name\":\"Amit Kumar\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/common-functionality-among-multiple-controllers\\\/#authorImage\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/859356966acd3c3879759369c7ac72cfb81228287bfc78e99c3080bee9b6b9ba?s=96&d=mm&r=g\",\"width\":96,\"height\":96,\"caption\":\"Amit Kumar\"}},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/common-functionality-among-multiple-controllers\\\/#webpage\",\"url\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/common-functionality-among-multiple-controllers\\\/\",\"name\":\"Common functionality among Multiple Controllers | TO THE NEW Blog\",\"description\":\"Many a times, we see a requirement, where we have to write same functions in multiple controllers just to share a common functionality among them, which is a bad approach, because in future, if any changes are required to that function, we\\u2019ll have to make the changes manually in all the copies of that function\",\"inLanguage\":\"en-US\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/#website\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/common-functionality-among-multiple-controllers\\\/#breadcrumblist\"},\"author\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/author\\\/amit-kumar\\\/#author\"},\"creator\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/author\\\/amit-kumar\\\/#author\"},\"datePublished\":\"2014-05-02T13:28:30+05:30\",\"dateModified\":\"2017-02-12T19:21:12+05:30\"},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/\",\"name\":\"TO THE NEW Blog\",\"inLanguage\":\"en-US\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/#organization\"}}]}\n\t\t<\/script>\n\t\t<!-- All in One SEO -->\n\n","aioseo_head_json":{"title":"Common functionality among Multiple Controllers | TO THE NEW Blog","description":"Many a times, we see a requirement, where we have to write same functions in multiple controllers just to share a common functionality among them, which is a bad approach, because in future, if any changes are required to that function, we\u2019ll have to make the changes manually in all the copies of that function","canonical_url":"https:\/\/www.tothenew.com\/blog\/common-functionality-among-multiple-controllers\/","robots":"max-image-preview:large","keywords":"","webmasterTools":{"miscellaneous":""},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.tothenew.com\/blog\/common-functionality-among-multiple-controllers\/#article","name":"Common functionality among Multiple Controllers | TO THE NEW Blog","headline":"Common functionality among Multiple Controllers","author":{"@id":"https:\/\/www.tothenew.com\/blog\/author\/amit-kumar\/#author"},"publisher":{"@id":"https:\/\/www.tothenew.com\/blog\/#organization"},"datePublished":"2014-05-02T13:28:30+05:30","dateModified":"2017-02-12T19:21:12+05:30","inLanguage":"en-US","mainEntityOfPage":{"@id":"https:\/\/www.tothenew.com\/blog\/common-functionality-among-multiple-controllers\/#webpage"},"isPartOf":{"@id":"https:\/\/www.tothenew.com\/blog\/common-functionality-among-multiple-controllers\/#webpage"},"articleSection":"Technology, AngularJS, common, controller, multiple, scope, sharing"},{"@type":"BreadcrumbList","@id":"https:\/\/www.tothenew.com\/blog\/common-functionality-among-multiple-controllers\/#breadcrumblist","itemListElement":[{"@type":"ListItem","@id":"https:\/\/www.tothenew.com\/blog#listItem","position":1,"name":"Home","item":"https:\/\/www.tothenew.com\/blog","nextItem":{"@type":"ListItem","@id":"https:\/\/www.tothenew.com\/blog\/category\/technology\/#listItem","name":"Technology"}},{"@type":"ListItem","@id":"https:\/\/www.tothenew.com\/blog\/category\/technology\/#listItem","position":2,"name":"Technology","item":"https:\/\/www.tothenew.com\/blog\/category\/technology\/","nextItem":{"@type":"ListItem","@id":"https:\/\/www.tothenew.com\/blog\/common-functionality-among-multiple-controllers\/#listItem","name":"Common functionality among Multiple Controllers"},"previousItem":{"@type":"ListItem","@id":"https:\/\/www.tothenew.com\/blog#listItem","name":"Home"}},{"@type":"ListItem","@id":"https:\/\/www.tothenew.com\/blog\/common-functionality-among-multiple-controllers\/#listItem","position":3,"name":"Common functionality among Multiple Controllers","previousItem":{"@type":"ListItem","@id":"https:\/\/www.tothenew.com\/blog\/category\/technology\/#listItem","name":"Technology"}}]},{"@type":"Organization","@id":"https:\/\/www.tothenew.com\/blog\/#organization","name":"TO THE NEW Blog","url":"https:\/\/www.tothenew.com\/blog\/"},{"@type":"Person","@id":"https:\/\/www.tothenew.com\/blog\/author\/amit-kumar\/#author","url":"https:\/\/www.tothenew.com\/blog\/author\/amit-kumar\/","name":"Amit Kumar","image":{"@type":"ImageObject","@id":"https:\/\/www.tothenew.com\/blog\/common-functionality-among-multiple-controllers\/#authorImage","url":"https:\/\/secure.gravatar.com\/avatar\/859356966acd3c3879759369c7ac72cfb81228287bfc78e99c3080bee9b6b9ba?s=96&d=mm&r=g","width":96,"height":96,"caption":"Amit Kumar"}},{"@type":"WebPage","@id":"https:\/\/www.tothenew.com\/blog\/common-functionality-among-multiple-controllers\/#webpage","url":"https:\/\/www.tothenew.com\/blog\/common-functionality-among-multiple-controllers\/","name":"Common functionality among Multiple Controllers | TO THE NEW Blog","description":"Many a times, we see a requirement, where we have to write same functions in multiple controllers just to share a common functionality among them, which is a bad approach, because in future, if any changes are required to that function, we\u2019ll have to make the changes manually in all the copies of that function","inLanguage":"en-US","isPartOf":{"@id":"https:\/\/www.tothenew.com\/blog\/#website"},"breadcrumb":{"@id":"https:\/\/www.tothenew.com\/blog\/common-functionality-among-multiple-controllers\/#breadcrumblist"},"author":{"@id":"https:\/\/www.tothenew.com\/blog\/author\/amit-kumar\/#author"},"creator":{"@id":"https:\/\/www.tothenew.com\/blog\/author\/amit-kumar\/#author"},"datePublished":"2014-05-02T13:28:30+05:30","dateModified":"2017-02-12T19:21:12+05:30"},{"@type":"WebSite","@id":"https:\/\/www.tothenew.com\/blog\/#website","url":"https:\/\/www.tothenew.com\/blog\/","name":"TO THE NEW Blog","inLanguage":"en-US","publisher":{"@id":"https:\/\/www.tothenew.com\/blog\/#organization"}}]},"og:locale":"en_US","og:site_name":"TO THE NEW BLOG","og:type":"blog","og:title":"Common functionality among Multiple Controllers | TO THE NEW Blog","og:description":"Many a times, we see a requirement, where we have to write same functions in multiple controllers just to share a common functionality among them, which is a bad approach, because in future, if any changes are required to that function, we\u2019ll have to make the changes manually in all the copies of that function","og:url":"https:\/\/www.tothenew.com\/blog\/common-functionality-among-multiple-controllers\/","og:image":"https:\/\/www.tothenew.com\/blog\/wp-content\/themes\/ttn\/images\/social-logo.png","og:image:secure_url":"https:\/\/www.tothenew.com\/blog\/wp-content\/themes\/ttn\/images\/social-logo.png","twitter:card":"summary","twitter:site":"@tothenew","twitter:title":"Common functionality among Multiple Controllers | TO THE NEW Blog","twitter:description":"Many a times, we see a requirement, where we have to write same functions in multiple controllers just to share a common functionality among them, which is a bad approach, because in future, if any changes are required to that function, we\u2019ll have to make the changes manually in all the copies of that function","twitter:image":"https:\/\/www.tothenew.com\/blog\/wp-content\/themes\/ttn\/images\/social-logo.png"},"aioseo_meta_data":{"post_id":"13296","title":null,"description":null,"keywords":null,"keyphrases":null,"primary_term":null,"canonical_url":null,"og_title":null,"og_description":null,"og_object_type":"default","og_image_type":"default","og_image_url":null,"og_image_width":null,"og_image_height":null,"og_image_custom_url":null,"og_image_custom_fields":null,"og_video":null,"og_custom_url":null,"og_article_section":null,"og_article_tags":null,"twitter_use_og":false,"twitter_card":"default","twitter_image_type":"default","twitter_image_url":null,"twitter_image_custom_url":null,"twitter_image_custom_fields":null,"twitter_title":null,"twitter_description":null,"schema":{"blockGraphs":[],"customGraphs":[],"default":{"data":{"Article":[],"Course":[],"Dataset":[],"FAQPage":[],"Movie":[],"Person":[],"Product":[],"ProductReview":[],"Car":[],"Recipe":[],"Service":[],"SoftwareApplication":[],"WebPage":[]},"graphName":"Article","isEnabled":true},"graphs":[]},"schema_type":null,"schema_type_options":null,"pillar_content":false,"robots_default":true,"robots_noindex":false,"robots_noarchive":false,"robots_nosnippet":false,"robots_nofollow":false,"robots_noimageindex":false,"robots_noodp":false,"robots_notranslate":false,"robots_max_snippet":null,"robots_max_videopreview":null,"robots_max_imagepreview":"large","priority":null,"frequency":null,"local_seo":null,"limit_modified_date":false,"created":"2021-04-29 12:17:44","updated":"2024-02-29 08:28:08","focus_keyword":null,"additional_keywords":null,"truseo_locale":null,"ai":null,"breadcrumb_settings":null,"seo_analyzer_scan_date":null},"aioseo_breadcrumb":"<div class=\"aioseo-breadcrumbs\"><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/www.tothenew.com\/blog\" title=\"Home\">Home<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">&raquo;<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/www.tothenew.com\/blog\/category\/technology\/\" title=\"Technology\">Technology<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">&raquo;<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\tCommon functionality among Multiple Controllers\n\t\t<\/span><\/div>","aioseo_breadcrumb_json":[{"label":"Home","link":"https:\/\/www.tothenew.com\/blog"},{"label":"Technology","link":"https:\/\/www.tothenew.com\/blog\/category\/technology\/"},{"label":"Common functionality among Multiple Controllers","link":"https:\/\/www.tothenew.com\/blog\/common-functionality-among-multiple-controllers\/"}],"_links":{"self":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/13296","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/users\/52"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/comments?post=13296"}],"version-history":[{"count":0,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/13296\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/media?parent=13296"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/categories?post=13296"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/tags?post=13296"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}