2

Hello All Actually I'm learning joomla component designing and also Writing my own component in which i want to add a custom function. but i have two confusion

  1. I saw there is a publish function in joomla that can be found in Admin Controller This functions do some checking on id's and call the same function in model and in model this function calls for same function in table class. why they do so as we can get the Db object in controller using JFactory::getDbo() and can insert, update data in table using it. then why the go so long
  2. Second this is the below code
$data = array('publish' => 1, 'unpublish' => 0, 'archive' => 2, 'trash' => -2, 'report' => -3);
$task = $this->getTask();
$value = JArrayHelper::getValue($data, $task, 0, 'int');

this code can be found in publish function of controller but I'm still confused about the above line of code why the do it.?

Please Help Me

1

why they do so as we can get the Db object in controller using JFactory::getDbo() and can insert, update data in table using it. then why the go so long

This is the MVC. It theory we could do everything in the controller, but should we? I do not think so. Why so long? This is the CMS and it has to do various checks.

this code can be found in publish function of controller but I'm still confused about the above line of code why the do it.?

This coded ensures that the task coming from the request is in array of predefined tasks. JArrayHelper::getValue() also allows to use the default value if it was not found and filter it.

  • which means when a user click on publish button a task variable is passed to specified controller using content.publish, in which WHAT WILL BE OUR TASK VARIABLE ?... It is publish and using that variable cms will call to specified function in controller which is publish then why we are checking what task is called in publish function.? SIR I"M CONFUSED ABOUT THAT MATH CAN YOU CLEAR THIS TO ME – Sumer Raj Chouhan Apr 16 '15 at 5:31
  • Because publish() function is also used for unpublish, archive, trash and report tasks. See the constructor of the controller class. – Dmitry Rekun Apr 16 '15 at 6:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.