what is $this
Moderators: ooffick, General Support Moderators
Forum rules
-
- Joomla! Apprentice
- Posts: 5
- Joined: Mon Sep 25, 2017 8:56 am
what is $this
Hi everyone
it's 1st time to me posting in joomla forum
normally i like to search for the answer which i'm seeking but for that question i didn't find anything .
days after days and can't figure out .
maybe this been asked a lot of time
what is $this ?
specially how does joomla use $this ?
i know $this is a reserved word in php
but how does joomla use $this outside the scope of class?
how do i know the referrer of $this
thanks
it's 1st time to me posting in joomla forum
normally i like to search for the answer which i'm seeking but for that question i didn't find anything .
days after days and can't figure out .
maybe this been asked a lot of time
what is $this ?
specially how does joomla use $this ?
i know $this is a reserved word in php
but how does joomla use $this outside the scope of class?
how do i know the referrer of $this
thanks
Last edited by imanickam on Wed Nov 22, 2017 2:41 am, edited 1 time in total.
Reason: Moved the topic from the forum General Questions/New to Joomla! 3.x to the forum Joomla! 3.x Coding
Reason: Moved the topic from the forum General Questions/New to Joomla! 3.x to the forum Joomla! 3.x Coding
-
- Joomla! Virtuoso
- Posts: 4025
- Joined: Mon Nov 25, 2013 4:35 pm
- Location: Montreal, Canada
- Contact:
Re: what is $this
$this points to a method/attribute in the current class. If you have a PHP class, and you have a method called "subtract" for example, then, in order to use this method (function) in another method, then you will need to call $this->subtract.
http://www.itoctopus.com - Joomla consulting at its finest
https://twitter.com/itoctopus - Follow us on Twitter
https://twitter.com/itoctopus - Follow us on Twitter
-
- Joomla! Apprentice
- Posts: 5
- Joined: Mon Sep 25, 2017 8:56 am
Re: what is $this
Hi itoctopus
yes you are right if using it ($this) inside the scope of class
but for example at components\com_users\views\login\tmpl
there are three files (default, default_login, default_logout)
what is the class that $this refer to ?
yes you are right if using it ($this) inside the scope of class
but for example at components\com_users\views\login\tmpl
there are three files (default, default_login, default_logout)
what is the class that $this refer to ?
Last edited by ahmed_mmm on Tue Nov 28, 2017 1:57 pm, edited 1 time in total.
-
- Joomla! Enthusiast
- Posts: 172
- Joined: Mon Jul 29, 2013 8:25 pm
Re: what is $this
$this will reference the current instance (object) of the class you are using at any given time.
-
- Joomla! Apprentice
- Posts: 5
- Joined: Mon Sep 25, 2017 8:56 am
Re: what is $this
Hi Achaa
yes you are right
take this example and tell me what class or object $this refer to ?
it's the default.php in com_users
yes you are right
take this example and tell me what class or object $this refer to ?
it's the default.php in com_users
Code: Select all
defined('_JEXEC') or die;
$cookieLogin = $this->user->get('cookieLogin');
if (!empty($cookieLogin) || $this->user->get('guest'))
{
// The user is not logged in or needs to provide a password.
echo $this->loadTemplate('login');
}
else
{
// The user is already logged in.
echo $this->loadTemplate('logout');
}
-
- Joomla! Enthusiast
- Posts: 172
- Joined: Mon Jul 29, 2013 8:25 pm
Re: what is $this
Hi,
I'm not familiar with Joomla code, but a quick Google leads me to JView.
https://docs.joomla.org/API17:JView::loadTemplate
Class page: https://docs.joomla.org/API17:JView
I'm not familiar with Joomla code, but a quick Google leads me to JView.
https://docs.joomla.org/API17:JView::loadTemplate
Class page: https://docs.joomla.org/API17:JView
-
- Joomla! Apprentice
- Posts: 5
- Joined: Mon Sep 25, 2017 8:56 am
Re: what is $this
Thanks
does JView::loadTemplate relate to this topic ?
anyway i think the loadTemplate method is deprecated
anyone knows how the joomla code been organized????
OR
how joomla uses $this in a multi file php ?
i think i'm not the only one who want to know answers for these questions .
please someone explain
does JView::loadTemplate relate to this topic ?
anyway i think the loadTemplate method is deprecated
anyone knows how the joomla code been organized????
OR
how joomla uses $this in a multi file php ?
i think i'm not the only one who want to know answers for these questions .
please someone explain
-
- Joomla! Enthusiast
- Posts: 172
- Joined: Mon Jul 29, 2013 8:25 pm
Re: what is $this
I don't think you understand the concept of $this.
I would politely suggest you do some reading on Object-oriented programming.
I would politely suggest you do some reading on Object-oriented programming.
-
- Joomla! Apprentice
- Posts: 5
- Joined: Mon Sep 25, 2017 8:56 am
Re: what is $this
Code: Select all
<?php
class Person {
public $name;
function __construct( $name ) {
$this->name = $name;
}
}
anything else you suggest to understand