{"id":3248,"date":"2014-05-18T19:51:53","date_gmt":"2014-05-18T19:51:53","guid":{"rendered":"https:\/\/www.inmotionhosting.com\/support\/2014\/05\/18\/add-new-task\/"},"modified":"2023-06-07T14:28:57","modified_gmt":"2023-06-07T18:28:57","slug":"add-new-task","status":"publish","type":"post","link":"https:\/\/www.inmotionhosting.com\/support\/edu\/joomla\/joomla-3\/add-new-task\/","title":{"rendered":"How to add a New Task to your Joomla 3 Component"},"content":{"rendered":"<p class=\"alert alert-danger\">This tutorial series, <a href=\"https:\/\/www.inmotionhosting.com\/support\/edu\/joomla\/joomla-3\/joomla-search-component\/\">Joomla 3 component development<\/a>, is currently in progress\u2026<\/p>\n<p>So far in this tutorial series for creating a component in Joomla 3, we\u2019ve created <a href=\"https:\/\/www.inmotionhosting.com\/support\/edu\/joomla\/joomla-3\/add-new-view\/\">views<\/a> and we\u2019ve created <a href=\"https:\/\/www.inmotionhosting.com\/support\/edu\/joomla\/joomla-3\/formats\/\">formats<\/a>. The next feature of components we\u2019re going to review is tasks.<\/p>\n<h2>What is a task?<\/h2>\n<p>A task is, well\u2026 something that can be done. The usage of \u201c<em>tasks<\/em>\u201d when developing components in Joomla is what it sounds like.<\/p>\n<h3>display() is the default task<\/h3>\n<p>If you do not specify a task, the default task <em>display()<\/em> will be executed. The screenshot below demonstrates this in action. When we echo the <strong>task<\/strong> to the screen, it is blank (meaning it is not set). Because there is no task set, the <strong>default()<\/strong> task \/ function is then executed.<\/p>\n<p><a href=\"\/support\/images\/stories\/edu\/joomla-3\/create-component\/display-is-default-task.png\" rel=\"lightbox-0\"><img decoding=\"async\" class=\"std_ss\" style=\"max-width: 100%;\" src=\"\/support\/images\/stories\/edu\/joomla-3\/create-component\/display-is-default-task.png\" alt=\"Default task execution\"><\/a><\/p>\n<div style=\"clear: both;\"><\/div>\n<h2>How to add a new task<\/h2>\n<p>Adding a new task to your component is actually quite easy. Here are the steps.<\/p>\n<ol class=\"article_list\">\n<li><strong>Decide on a task name<\/strong>In our testing, we are going to create a task named <em>shout<\/em>.<\/li>\n<li><strong>Add a function named after your task within your component\u2019s controller class<\/strong>Since we\u2019re creating a <em>shout<\/em> task, we need to create a function named <strong>shout()<\/strong> and add it to our controller\u2019s class. Below is our controller.php file, with the new code we added to it highlighted in red.\n<pre class=\"code_block\">&lt;?php \/\/ No direct access to this file defined('_JEXEC') or die('Restricted access');   \/\/ import Joomla controller library <a href=\"https:\/\/www.inmotionhosting.com\/support\/edu\/joomla\/joomla-3\/jimport\/\">jimport<\/a>('joomla.application.component.controller');   \/**  * Hello World Component Controller  *\/ class HelloWorldController extends JControllerLegacy {   <span style=\"color: red;\">function <strong>shout()<\/strong>   {     echo \"&lt;p&gt;THIS IS ME SHOUTING!&lt;\/p&gt;\";   }<\/span> }<\/pre>\n<\/li>\n<\/ol>\n<h2>Testing your new task<\/h2>\n<p>We\u2019re testing our new task by calling it in the URL. To do this, we\u2019re passing the task variable via the URL and setting it to <em>shout<\/em>, as in:<\/p>\n<p class=\"white_box\">https:\/\/example.com\/index.php?option=com_helloworld&amp;<span style=\"color: red;\">task=<strong>shout<\/strong><\/span><\/p>\n<p>In the screenshot below, you can see our new task in action:<\/p>\n<p><a href=\"\/support\/images\/stories\/edu\/joomla-3\/create-component\/executing-our-new-task.png\" rel=\"lightbox-0\"><img decoding=\"async\" class=\"std_ss\" style=\"max-width: 100%;\" src=\"\/support\/images\/stories\/edu\/joomla-3\/create-component\/executing-our-new-task.png\" alt=\"New task execution\"><\/a><\/p>\n<div style=\"clear: both;\"><\/div>\n","protected":false},"excerpt":{"rendered":"<p>This tutorial series, Joomla 3 component development, is currently in progress\u2026 So far in this tutorial series for creating a component in Joomla 3, we\u2019ve created views and we\u2019ve created formats. The next feature of components we\u2019re going to review is tasks. What is a task? A task is, well\u2026 something that can be done.<a class=\"moretag\" href=\"https:\/\/www.inmotionhosting.com\/support\/edu\/joomla\/joomla-3\/add-new-task\/\"> Read More ><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[4403,94],"tags":[4404],"class_list":["post-3248","post","type-post","status-publish","format-standard","hentry","category-joomla","category-joomla-3","tag-joomla-v3"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.1.1 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>How to add a New Task to your Joomla 3 Component | InMotion Hosting<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.inmotionhosting.com\/support\/edu\/joomla\/joomla-3\/add-new-task\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to add a New Task to your Joomla 3 Component | InMotion Hosting\" \/>\n<meta property=\"og:description\" content=\"This tutorial series, Joomla 3 component development, is currently in progress\u2026 So far in this tutorial series for creating a component in Joomla 3, we\u2019ve created views and we\u2019ve created formats. The next feature of components we\u2019re going to review is tasks. What is a task? A task is, well\u2026 something that can be done. Read More &gt;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.inmotionhosting.com\/support\/edu\/joomla\/joomla-3\/add-new-task\/\" \/>\n<meta property=\"og:site_name\" content=\"InMotion Hosting Support Center\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/inmotionhosting\/\" \/>\n<meta property=\"article:published_time\" content=\"2014-05-18T19:51:53+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-06-07T18:28:57+00:00\" \/>\n<meta name=\"author\" content=\"Brad Markle\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@InMotionHosting\" \/>\n<meta name=\"twitter:site\" content=\"@InMotionHosting\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Brad Markle\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/edu\/joomla\/joomla-3\/add-new-task\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/edu\/joomla\/joomla-3\/add-new-task\/\"},\"author\":{\"name\":\"Brad Markle\",\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/#\/schema\/person\/5ae05d1210b0ef63c437ccedce2799bf\"},\"headline\":\"How to add a New Task to your Joomla 3 Component\",\"datePublished\":\"2014-05-18T19:51:53+00:00\",\"dateModified\":\"2023-06-07T18:28:57+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/edu\/joomla\/joomla-3\/add-new-task\/\"},\"wordCount\":282,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/#organization\"},\"keywords\":[\"Joomla v3\"],\"articleSection\":[\"Joomla\",\"Joomla 3\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.inmotionhosting.com\/support\/edu\/joomla\/joomla-3\/add-new-task\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/edu\/joomla\/joomla-3\/add-new-task\/\",\"url\":\"https:\/\/www.inmotionhosting.com\/support\/edu\/joomla\/joomla-3\/add-new-task\/\",\"name\":\"How to add a New Task to your Joomla 3 Component | InMotion Hosting\",\"isPartOf\":{\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/#website\"},\"datePublished\":\"2014-05-18T19:51:53+00:00\",\"dateModified\":\"2023-06-07T18:28:57+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/edu\/joomla\/joomla-3\/add-new-task\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.inmotionhosting.com\/support\/edu\/joomla\/joomla-3\/add-new-task\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/edu\/joomla\/joomla-3\/add-new-task\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.inmotionhosting.com\/support\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to add a New Task to your Joomla 3 Component\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/#website\",\"url\":\"https:\/\/www.inmotionhosting.com\/support\/\",\"name\":\"InMotion Hosting Support Center\",\"description\":\"Web Hosting Support &amp; Tutorials\",\"publisher\":{\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.inmotionhosting.com\/support\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/#organization\",\"name\":\"InMotion Hosting\",\"url\":\"https:\/\/www.inmotionhosting.com\/support\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.inmotionhosting.com\/support\/wp-content\/uploads\/2023\/02\/inmotion-hosting-logo-yoast.jpg\",\"contentUrl\":\"https:\/\/www.inmotionhosting.com\/support\/wp-content\/uploads\/2023\/02\/inmotion-hosting-logo-yoast.jpg\",\"width\":696,\"height\":696,\"caption\":\"InMotion Hosting\"},\"image\":{\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/inmotionhosting\/\",\"https:\/\/x.com\/InMotionHosting\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/#\/schema\/person\/5ae05d1210b0ef63c437ccedce2799bf\",\"name\":\"Brad Markle\",\"url\":\"https:\/\/www.inmotionhosting.com\/support\/author\/bradm\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to add a New Task to your Joomla 3 Component | InMotion Hosting","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.inmotionhosting.com\/support\/edu\/joomla\/joomla-3\/add-new-task\/","og_locale":"en_US","og_type":"article","og_title":"How to add a New Task to your Joomla 3 Component | InMotion Hosting","og_description":"This tutorial series, Joomla 3 component development, is currently in progress\u2026 So far in this tutorial series for creating a component in Joomla 3, we\u2019ve created views and we\u2019ve created formats. The next feature of components we\u2019re going to review is tasks. What is a task? A task is, well\u2026 something that can be done. Read More >","og_url":"https:\/\/www.inmotionhosting.com\/support\/edu\/joomla\/joomla-3\/add-new-task\/","og_site_name":"InMotion Hosting Support Center","article_publisher":"https:\/\/www.facebook.com\/inmotionhosting\/","article_published_time":"2014-05-18T19:51:53+00:00","article_modified_time":"2023-06-07T18:28:57+00:00","author":"Brad Markle","twitter_card":"summary_large_image","twitter_creator":"@InMotionHosting","twitter_site":"@InMotionHosting","twitter_misc":{"Written by":"Brad Markle","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.inmotionhosting.com\/support\/edu\/joomla\/joomla-3\/add-new-task\/#article","isPartOf":{"@id":"https:\/\/www.inmotionhosting.com\/support\/edu\/joomla\/joomla-3\/add-new-task\/"},"author":{"name":"Brad Markle","@id":"https:\/\/www.inmotionhosting.com\/support\/#\/schema\/person\/5ae05d1210b0ef63c437ccedce2799bf"},"headline":"How to add a New Task to your Joomla 3 Component","datePublished":"2014-05-18T19:51:53+00:00","dateModified":"2023-06-07T18:28:57+00:00","mainEntityOfPage":{"@id":"https:\/\/www.inmotionhosting.com\/support\/edu\/joomla\/joomla-3\/add-new-task\/"},"wordCount":282,"commentCount":0,"publisher":{"@id":"https:\/\/www.inmotionhosting.com\/support\/#organization"},"keywords":["Joomla v3"],"articleSection":["Joomla","Joomla 3"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.inmotionhosting.com\/support\/edu\/joomla\/joomla-3\/add-new-task\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.inmotionhosting.com\/support\/edu\/joomla\/joomla-3\/add-new-task\/","url":"https:\/\/www.inmotionhosting.com\/support\/edu\/joomla\/joomla-3\/add-new-task\/","name":"How to add a New Task to your Joomla 3 Component | InMotion Hosting","isPartOf":{"@id":"https:\/\/www.inmotionhosting.com\/support\/#website"},"datePublished":"2014-05-18T19:51:53+00:00","dateModified":"2023-06-07T18:28:57+00:00","breadcrumb":{"@id":"https:\/\/www.inmotionhosting.com\/support\/edu\/joomla\/joomla-3\/add-new-task\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.inmotionhosting.com\/support\/edu\/joomla\/joomla-3\/add-new-task\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.inmotionhosting.com\/support\/edu\/joomla\/joomla-3\/add-new-task\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.inmotionhosting.com\/support\/"},{"@type":"ListItem","position":2,"name":"How to add a New Task to your Joomla 3 Component"}]},{"@type":"WebSite","@id":"https:\/\/www.inmotionhosting.com\/support\/#website","url":"https:\/\/www.inmotionhosting.com\/support\/","name":"InMotion Hosting Support Center","description":"Web Hosting Support &amp; Tutorials","publisher":{"@id":"https:\/\/www.inmotionhosting.com\/support\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.inmotionhosting.com\/support\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.inmotionhosting.com\/support\/#organization","name":"InMotion Hosting","url":"https:\/\/www.inmotionhosting.com\/support\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.inmotionhosting.com\/support\/#\/schema\/logo\/image\/","url":"https:\/\/www.inmotionhosting.com\/support\/wp-content\/uploads\/2023\/02\/inmotion-hosting-logo-yoast.jpg","contentUrl":"https:\/\/www.inmotionhosting.com\/support\/wp-content\/uploads\/2023\/02\/inmotion-hosting-logo-yoast.jpg","width":696,"height":696,"caption":"InMotion Hosting"},"image":{"@id":"https:\/\/www.inmotionhosting.com\/support\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/inmotionhosting\/","https:\/\/x.com\/InMotionHosting"]},{"@type":"Person","@id":"https:\/\/www.inmotionhosting.com\/support\/#\/schema\/person\/5ae05d1210b0ef63c437ccedce2799bf","name":"Brad Markle","url":"https:\/\/www.inmotionhosting.com\/support\/author\/bradm\/"}]}},"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"primary_category":null,"_links":{"self":[{"href":"https:\/\/www.inmotionhosting.com\/support\/wp-json\/wp\/v2\/posts\/3248","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.inmotionhosting.com\/support\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.inmotionhosting.com\/support\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.inmotionhosting.com\/support\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.inmotionhosting.com\/support\/wp-json\/wp\/v2\/comments?post=3248"}],"version-history":[{"count":6,"href":"https:\/\/www.inmotionhosting.com\/support\/wp-json\/wp\/v2\/posts\/3248\/revisions"}],"predecessor-version":[{"id":104831,"href":"https:\/\/www.inmotionhosting.com\/support\/wp-json\/wp\/v2\/posts\/3248\/revisions\/104831"}],"wp:attachment":[{"href":"https:\/\/www.inmotionhosting.com\/support\/wp-json\/wp\/v2\/media?parent=3248"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.inmotionhosting.com\/support\/wp-json\/wp\/v2\/categories?post=3248"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.inmotionhosting.com\/support\/wp-json\/wp\/v2\/tags?post=3248"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}