RSS   Twitter   Copiny   Copiny
Нашел ошибку? 

Выдели фрагмент текста с ошибкой или неточностью и нажми Ctrl+Enter!

Взаимодействие с глобальными объектами Joomla

Преобразуем пример модуля Hello World! Для этого просто впишем новый php код в соответствующий файл.

<?php
    defined('_JEXEC') or die('Restricted access');
    $user = JFactory::getUser();
    if ($user->guest) {
        echo "<p>Добро пожаловать!</p>";
    } else {
        echo "<p>Имя пользователь: $user->username</p>";
        echo "<p>Пользователь: $user->name</p>";
        echo "<p>E-mail: $user->email</p>";
    }
?>

JFactory - это один из основных классов Joomla, содержащий в себе методы для вызова различных глобальных объектов. В данном примере он возвращает ссылку на объект класса JUser. Выведем с помощью модуля все возможные свойства о пользователе

<?php
    defined('_JEXEC') or die('Restricted access');
    $user = JFactory::getUser();
    print "\n Текущий пользователь \n";
    foreach ($user as $key => $value) {
        if (is_string($value)) {
            print "<p> Свойство пользователя $key = $value</p>\n";
        } else {
            print "<p> Свойство $key - это не строка</p>\n";
        }
    }
?>

Функция is_string() здесь необходима для того чтобы выводить только строковые свойства объекта. С помощью цикла foreach мы перебираем все свойства класса.

В качестве дополнительного примера попробуем использовать класс JURI.

<?php
    defined('_JEXEC') or die('Restricted access');
    $uri = JFactory::getURI();
    print "\nТекущий URI Запрос\n";
    foreach ($uri as $key => $value) {
        if (is_string($value)) {
            print "<p> Свойство $key = $value </p>\n";
        } else {
            print "<p> Свойство $key - не строка </p>\n";
        }
    }
?>

А вот еще один пример с использованием класса для формирования даты и времени - JDate:

<?php
    defined('_JEXEC') or die('Restricted access');
   
    // Получаем дату
    $date = JFactory::getDate();
 
    // Вызов метода toMySQL
    $datemysql = $date->toMySQL();
    echo "\n<p> Дата представлена в формате базы данных MySQL $datemysql </p>\n";
 
    // Используем метод класса toUNIX
    $dateunix = $date->toUNIX();
    echo "\n<p> Текущая дата в UNIX формате - $dateunix </p>\n";
 
    // Используя метод toFormat, преобразуем текущую дату к желаемому виду.
    $datestr = $date->toFormat ('%H:%M:%S - %d %b %Y');
    echo "\n<p> Текущая дата $datestr </p>\n";
 
    // используя внутренний метод _monthToString переведем номер месяца в слово
    echo "\n<p>" . JDate::_monthToString(4) . " or " . $date->_monthToString(4) . "</p>\n";
?>

Смотрите также:
Комментарии (23) Добавить комментарий
  • Артём
    Артём
    26 Декабря 2013, 13:09
     ↑  +1  ↓     ответ

    getUser() есть подскажите как вывести материалы либо из категори либо популярные там вроде document()

  • http://tinyurl.com
    http://tinyurl.com
    24 Ноября 2019, 00:24
     ↑  0  ↓     ответ

    I don't even know how I ended up here, but I thought this post was great.

    I don't know who you are but definitely you are going to a famous blogger if you are not already ;

    ) Cheers!

  • and coconut oil
    and coconut oil
    26 Ноября 2019, 01:28
     ↑  0  ↓     ответ

    obviously like your web site but you have to take a look at the spelling on several of your posts.

    Many of them are rife with spelling problems and

    I in finding it very bothersome to inform the truth however I'll definitely come back

    again.

  • plenty of fish dating site
    plenty of fish dating site
    26 Ноября 2019, 08:17
     ↑  0  ↓     ответ

    Hey there! I just wanted to ask if you ever have any

    trouble with hackers? My last blog (wordpress) was hacked and

    I ended up losing months of hard work due to no back up.

    Do you have any methods to protect against hackers?

  • plenty of fish dating site
    plenty of fish dating site
    27 Ноября 2019, 00:30
     ↑  0  ↓     ответ

    I go to see day-to-day some web sites and information sites to read content, but this weblog gives feature based

    writing.

  • http://tinyurl.com
    http://tinyurl.com
    26 Марта 2022, 15:20
     ↑  0  ↓     ответ

    Nice post. I learn something new and challenging on websites I stumbleupon everyday.

    It will always be useful to read content from other writers and use a little something from other sites.

  • tinyurl.com
    tinyurl.com
    27 Марта 2022, 04:52
     ↑  0  ↓     ответ

    Can I simply just say what a relief to find somebody that really understands what they're

    discussing on the web. You definitely realize how to bring an issue to light and make it important.

    More and more people have to check this out and understand this

    side of the story. I can't believe you're not more popular given that you certainly have the gift.

  • tinyurl.com
    tinyurl.com
    27 Марта 2022, 08:54
     ↑  0  ↓     ответ

    Excellent blog you have here but I was wondering

    if you knew of any community forums that cover the same topics talked about in this article?

    I'd really love to be a part of online community

    where I can get suggestions from other experienced individuals that share the same interest.

    If you have any suggestions, please let me know.

    Bless you!

  • tinyurl.com
    tinyurl.com
    31 Марта 2022, 08:04
     ↑  0  ↓     ответ

    Good day! I know this is somewhat off topic but I was wondering which blog platform are you using for this site?

    I'm getting tired of Wordpress because I've had problems with

    hackers and I'm looking at alternatives for another platform.

    I would be awesome if you could point me in the direction of a good platform.

  • http://tinyurl.com/y8nzud99
    http://tinyurl.com/y8nzud99
    31 Марта 2022, 23:15
     ↑  0  ↓     ответ

    I blog often and I seriously thank you for your

    information. This great article has truly peaked my interest.

    I am going to book mark your blog and keep checking for new details about

    once a week. I subscribed to your RSS feed as well.

  • cheap fly
    cheap fly
    02 Апреля 2022, 16:48
     ↑  0  ↓     ответ

    Hi there! I could have sworn I've been to this blog before but after browsing

    through some of the post I realized it's new to me. Anyways,

    I'm definitely delighted I found it and I'll be book-marking

    and checking back frequently!

  • flights
    flights
    02 Апреля 2022, 23:30
     ↑  0  ↓     ответ

    I do trust all of the ideas you have introduced

    on your post. They're very convincing and will definitely work.

    Nonetheless, the posts are too brief for newbies.

    May just you please lengthen them a little from next time?

    Thanks for the post.

  • cheap flights now
    cheap flights now
    03 Апреля 2022, 11:41
     ↑  0  ↓     ответ

    I simply couldn't go away your website prior to suggesting that I really loved the standard info a person supply for your guests?

    Is going to be back frequently to investigate cross-check new posts

  • cheapest airline tickets guaranteed
    cheapest airline tickets guaranteed
    04 Апреля 2022, 04:49
     ↑  0  ↓     ответ

    It's very easy to find out any matter on net as compared to books,

    as I found this post at this web page.

  • flights tickets cheap
    flights tickets cheap
    04 Апреля 2022, 13:13
     ↑  0  ↓     ответ

    Fantastic beat ! I would like to apprentice even as you amend your site,

    how could i subscribe for a blog site? The account aided me a appropriate deal.

    I were a little bit acquainted of this your broadcast offered vivid clear concept

  • super cheap flights
    super cheap flights
    04 Апреля 2022, 13:23
     ↑  0  ↓     ответ

    A fascinating discussion is worth comment. I do believe that you should

    publish more about this topic, it might not be a taboo subject but generally people

    don't talk about these topics. To the next! Many thanks!!

  • cheap flights domestic
    cheap flights domestic
    05 Апреля 2022, 04:46
     ↑  0  ↓     ответ

    Whats up are using Wordpress for your blog platform?

    I'm new to the blog world but I'm trying to get started and set up my own. Do you need

    any coding knowledge to make your own blog? Any help would be

    greatly appreciated!

  • extremely cheap flight tickets
    extremely cheap flight tickets
    05 Апреля 2022, 06:44
     ↑  0  ↓     ответ

    Thanks for sharing your thoughts. I really appreciate your efforts and I am waiting for your next write ups thanks once

    again.

  • how to find cheap flights
    how to find cheap flights
    05 Апреля 2022, 14:20
     ↑  0  ↓     ответ

    My programmer is trying to convince me to move to .net from PHP.

    I have always disliked the idea because of the expenses.

    But he's tryiong none the less. I've been using Movable-type on a

    number of websites for about a year and am worried about switching to another platform.

    I have heard excellent things about blogengine.net.

    Is there a way I can transfer all my wordpress posts into it?

    Any kind of help would be really appreciated!

  • absolutely cheapest airfare possible
    absolutely cheapest airfare possible
    05 Апреля 2022, 20:38
     ↑  0  ↓     ответ

    Do you have a spam issue on this blog; I also am a blogger, and I was curious

    about your situation; many of us have created some nice practices and we are looking to trade techniques with others,

    be sure to shoot me an e-mail if interested.

  • tracfone special coupon 2022
    tracfone special coupon 2022
    30 Ноября 2022, 13:13
     ↑  0  ↓     ответ

    Spot on with this write-up, I honestly believe that this amazing site needs much more attention. I'll probably be back again to read more,

    thanks for the info!

  • tracfone special coupon 2022
    tracfone special coupon 2022
    01 Декабря 2022, 06:55
     ↑  0  ↓     ответ

    I simply couldn't leave your site prior to suggesting that

    I really enjoyed the standard info an individual provide on your guests?

    Is going to be back often in order to investigate cross-check new posts

  • Victor
    Victor
    28 Января 2023, 09:44
     ↑  0  ↓     ответ

    Hello joomla-book.ru webmaster, Thanks for the well-structured and well-presented post!

Оставить комментарий




* обязательно для заполнения

1 введенный почтовый адрес используется только для обратной связи при ответах в комментариях и сервиса gravatar.com
.