Skip to Content Skip to Menu

Taking baby steps - $database $my

  • bjraines
  • bjraines
  • OFFLINE
  • Posts: 87
  • Thanks: 0
  • Karma: 2
17 years 11 months ago #25080 by bjraines
Taking baby steps - $database $my was created by bjraines
I am studying several plugins and php simultaneously. I am getting by. I am curious.

Sometimes $database and $my are used and sometimes just $database.

What do they variable stand for and what do they do in the overall scheme of things?

Please Log in or Create an account to join the conversation.

  • mikko
  • mikko
  • OFFLINE
  • Posts: 703
  • Thanks: 0
  • Karma: 115
17 years 11 months ago #25081 by mikko
Replied by mikko on topic Re:Taking baby steps - $database $my
Joomla documentation is the best place to find more details.

$my is a joomla user object of the current user.

$database is a joomla database object which can be used to execute database queries.

api.joomla.org describes these in detail.


mikko

Please Log in or Create an account to join the conversation.

  • bjraines
  • bjraines
  • OFFLINE
  • Posts: 87
  • Thanks: 0
  • Karma: 2
17 years 11 months ago #25086 by bjraines
Replied by bjraines on topic Re:Taking baby steps - $database $my
Hey thanks! I did look at the api but i thought it was only relevant to 1.5

Ill check it out again. I guess I am trying to figure out when someone would use $my and when they would not need it.

Please Log in or Create an account to join the conversation.

  • mikko
  • mikko
  • OFFLINE
  • Posts: 703
  • Thanks: 0
  • Karma: 115
17 years 10 months ago #25102 by mikko
Replied by mikko on topic Re:Taking baby steps - $database $my
You need $my only when the thing that you display depends on the user. Even if the api is for joomla 1.5, $database and $my seem to be the same. (If they weren't, Joomla would break a lot of components)

mikko

Please Log in or Create an account to join the conversation.

  • trail
  • trail
  • OFFLINE
  • Posts: 232
  • Thanks: 21
  • Karma: 813
17 years 10 months ago #25124 by trail
Replied by trail on topic Re:Taking baby steps - $database $my
if you code in a function you'd wanna globalise those variables with 'global $my, $database;', else you dont need to globalise them because they will be already available inside any joomla component.

then you can just grab the current userid or gid or name with

$my->username;
$my->id;
$my->gid;

and ofcourse with this info you can do a lot of fun stuff in your component :)

DJ Trail.
CB Co-Founder & Test-Lead.
Plugins: My Age , Starsign Matchmaking Horoscope , My Visitor , My Highscores , My ProfileID ,
My Components: Import & Invite Karma Casino (Use Test / Test)
My Modules: Many :)

Please Log in or Create an account to join the conversation.

  • bjraines
  • bjraines
  • OFFLINE
  • Posts: 87
  • Thanks: 0
  • Karma: 2
17 years 10 months ago #25379 by bjraines
Replied by bjraines on topic Re:Taking baby steps - $database $my
Thanks.

I just note that the Author/articles tab does not use the global $my.

I had thought before reading this that I would need $my to display only my articles.

Please Log in or Create an account to join the conversation.

Moderators: beatnantkrileon
Powered by Kunena Forum