controller

Locked
ilovephp
Joomla! Intern
Joomla! Intern
Posts: 62
Joined: Tue May 06, 2008 7:20 am
Location: Italia - Treviso
Contact:

controller

Post by ilovephp » Wed Aug 20, 2008 2:05 pm

why JController costruttor is function __construct( $config = array() ) ? and not function JController( $config = array() ) ?

and than what 's the function of $config = array()? it's not very clear.
w joomla

User avatar
pe7er
Joomla! Master
Joomla! Master
Posts: 21971
Joined: Thu Aug 18, 2005 8:55 pm
Location: Nijmegen, The Netherlands
Contact:

Re: controller

Post by pe7er » Thu Aug 21, 2008 11:03 am

[MOD note: moving from Joomla! 1.5.x_Dev to Joombie Coding Q/A]
Kind Regards,
Peter Martin, Global Moderator
https://db8.nl - Joomla specialist, Nijmegen, Nederland
Co-founder of data2.eu GDPR Tool https://data2.eu/en/gdpr-tool

ilovephp
Joomla! Intern
Joomla! Intern
Posts: 62
Joined: Tue May 06, 2008 7:20 am
Location: Italia - Treviso
Contact:

Re: controller

Post by ilovephp » Thu Aug 21, 2008 11:23 am

thanks for your help!!!
w joomla

secteur
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 146
Joined: Tue Nov 08, 2005 9:32 am
Location: Malaysia

Re: controller

Post by secteur » Sun Aug 24, 2008 6:06 am

Hi,

__construct is the PHP5 version of constructors. See here:
http://my.php.net/manual/en/language.oop5.decon.php
All constructors in Joomla 1.5 are like this. It is compatible with PHP4 though.

As for the $config array, it allows you to set some of the parameters of your controller: from the code of
libraries/joomla/application/component/controller.php:

Code: Select all

//set the view name // <- probably a typo, should be set the controller name
		if (empty( $this->_name ))
		{
			if (array_key_exists('name', $config))  {
				$this->_name = $config['name'];
			} else {
				$this->_name = $this->getName();
			}
		}

		// Set a base path for use by the controller
		if (array_key_exists('base_path', $config)) {
			$this->_basePath	= $config['base_path'];
		} else {
			$this->_basePath	= JPATH_COMPONENT;
		}

		// If the default task is set, register it as such
		if ( array_key_exists( 'default_task', $config ) ) {
			$this->registerDefaultTask( $config['default_task'] );
		} else {
			$this->registerDefaultTask( 'display' );
		}

		// set the default model search path
		if ( array_key_exists( 'model_path', $config ) ) {
			// user-defined dirs
			$this->addModelPath($config['model_path']);
		} else {
			$this->addModelPath($this->_basePath.DS.'models');
		}

		// set the default view search path
		if ( array_key_exists( 'view_path', $config ) ) {
			// user-defined dirs
			$this->_setPath( 'view', $config['view_path'] );
		} else {
			$this->_setPath( 'view', $this->_basePath.DS.'views' );
		}
So if you pass an array:
- $config['name'] = thatsMyName; // Name of the controller is thatsMyName
- $config['default_task'] = editTask; // Task is editTask if not specified (default would be display)
etc...

If your $config array is empty, you will get the default values

Hope this helps

ilovephp
Joomla! Intern
Joomla! Intern
Posts: 62
Joined: Tue May 06, 2008 7:20 am
Location: Italia - Treviso
Contact:

Re: controller

Post by ilovephp » Sun Aug 24, 2008 8:12 am

thanks 1000000000000..........
now is very clear.

I like to develop with joomla and I am studying the framewrok. is correct?
w joomla

secteur
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 146
Joined: Tue Nov 08, 2005 9:32 am
Location: Malaysia

Re: controller

Post by secteur » Tue Aug 26, 2008 1:14 am

Hi,

studying the framework might give you a headache ;)
Maybe you should consider the tutorials on MVC development.
Also a good idea would be to look at (or even to base your new components on) the com_weblinks (admin side). It's in my opinion the most MVC component on the Joomla basic installation. Really helps.

Have fun!


Locked

Return to “Joombie Coding Q/A”