controller.php file is not working

221 views
Skip to first unread message

gopijack

unread,
May 14, 2012, 7:28:18 AM5/14/12
to Joomla! General Development, pas...@gmail.com, ma...@betweenbrain.com, davida...@gmail.com, khoui...@gmail.com, tomfu...@gmail.com
Hi,

I am creating one component in Joomla2.5 , Right now the
controller.php file is not calling.

<?php

defined('_JEXEC') or die;

jimport('joomla.application.component.controller');

class mycomponentController extends JController
{

public function display($cachable = false)
{
$view = JRequest::getCmd('view', 'orders');
$layout = JRequest::getCmd('layout', 'default');
$id = JRequest::getInt('id');
parent::display($cachable);
//sub menu will start here
}
}

?>
here the display() function is not working,
I put echo here,and also used exit() but no action in controller file

its only calling admin.mycomponent.php file

may i knew the reason ?

Thanks in advanced

Prasit Gebsaap

unread,
May 14, 2012, 8:27:49 AM5/14/12
to joomla-de...@googlegroups.com
What is name of your component? Mycomponent?

Can you post mycomponent.php? I have no information to help you.


--
You received this message because you are subscribed to the Google Groups "Joomla! General Development" group.
To post to this group, send an email to joomla-de...@googlegroups.com.
To unsubscribe from this group, send email to joomla-dev-gene...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/joomla-dev-general?hl=en-GB.




--
Prasit Gebsaap
 
Nonthaburi, Thailand
 

gopi gopi

unread,
May 14, 2012, 8:29:56 AM5/14/12
to joomla-de...@googlegroups.com
Hi,

 Thanks for reply,component name :  mycomponent

I have already paste the code of  mycomponent.php

here it is 

<?php

defined('_JEXEC') or die;

jimport('joomla.application.component.controller');

class mycomponentController extends JController
{

       public function display($cachable = false)
       {
                 $view         = JRequest::getCmd('view', 'orders');
                 $layout       = JRequest::getCmd('layout', 'default');
                 $id           = JRequest::getInt('id');
                parent::display($cachable);
       //sub menu will start here
       }
}

?>
Regards

Gopi.A

Individual source from Adodis Technology,India.

 (Working for www.chillcreations.com)

Alan Hartless

unread,
May 14, 2012, 9:44:26 AM5/14/12
to joomla-de...@googlegroups.com
I think you are getting two files mixed up.  See http://docs.joomla.org/Developing_a_Model-View-Controller_(MVC)_Component_for_Joomla!2.5_-_Part_07

There is the file that is called mycomponent.php that calls up your controller file.

From that doc above (where helloworld is the name of your component):

admin/helloworld.php


<?php
// No direct access to this file
defined('_JEXEC') or die('Restricted access');
 
// import joomla controller library
jimport('joomla.application.component.controller');
 
// Get an instance of the controller prefixed by HelloWorld
$controller = JController::getInstance('HelloWorld');
 
// Perform the Request task
$controller->execute(JRequest::getCmd('task'));
 
// Redirect if set by the controller
$controller->redirect();

And then in your controller file admin/controller.php:


<?php
// No direct access to this file
defined('_JEXEC') or die('Restricted access');
 
// import Joomla controller library
jimport('joomla.application.component.controller');
 
/**
 * General Controller of HelloWorld component
 */
class HelloWorldController extends JController
{
	/**
	 * display task
	 *
	 * @return void
	 */
	function display($cachable = false) 
	{
		// set default view if not set
		JRequest::setVar('view', JRequest::getCmd('view', 'HelloWorlds'));
 
		// call parent behavior
		parent::display($cachable);
	}
}

Thanks,
Alan

Prasit Gebsaap

unread,
May 14, 2012, 10:12:56 AM5/14/12
to joomla-de...@googlegroups.com
That one shall be controller.php, it is a master controller for your component. Please look at my document at docs.joomla.org, it is about how controller works?

This is a normal dispatcher of component.


defined('_JEXEC') or die('Restricted access');

// Access check.
if (!JFactory::getUser()->authorise('core.manage', 'com_jongman')) {
    return JError::raiseWarning(404, JText::_('JERROR_ALERTNOAUTHOR'));

}
// import joomla controller library
jimport('joomla.application.component.controller');
// Get an instance of the controller prefixed by Jongman, assign default view 's name in case of no view or task
$controller = JController::getInstance('Jongman', array('default_view'=>'cpanel'));
// Perform the Request task, default task performed if none specified

$controller->execute(JRequest::getCmd('task'));
// Redirect if set by the controller
$controller->redirect();


On 14 May 2012 19:29, gopi gopi <gop...@gmail.com> wrote:
Hi,

 Thanks for reply,component name :  mycomponent

I have already paste the code of  mycomponent.php

here it is 

<?php

defined('_JEXEC') or die;

jimport('joomla.application.component.controller');

class mycomponentController extends JController
{

       public function display($cachable = false)
       {
                 $view         = JRequest::getCmd('view', 'orders');
                 $layout       = JRequest::getCmd('layout', 'default');
                 $id           = JRequest::getInt('id');
                parent::display($cachable);
       //sub menu will start here
       }
}

?>

Please confirm your post.

gopi gopi

unread,
May 15, 2012, 12:46:00 AM5/15/12
to joomla-de...@googlegroups.com
Hi,

 My controller name is : mycomponent
 
 in admin/controller.php i have place the above controller code.

 in admin/admin.mycomponent.php this is for executing the class and controller file.

controller.php file must call automatically,but for me not working,

If i place exit() function outside of the class,the action begins and showing empty screen,if  i place exit() inside the display() function,no action is there :-(

Prasit Gebsaap

unread,
May 15, 2012, 3:13:31 AM5/15/12
to joomla-de...@googlegroups.com
Please turn on debugging in Joomla gloabal configuration, and we what is the result?

gopi gopi

unread,
May 15, 2012, 7:42:50 AM5/15/12
to joomla-de...@googlegroups.com
Hi,

 For me its worked,

in admin/mycomponent.php ,

I have call the controller class name and its file by using require_once

so for me two times controller file called,now i just removed the require_once,

now automatically admin/controller.php file called.

Thanks for your valid suggestions.
Reply all
Reply to author
Forward
0 new messages