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

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

Создание своего типа поля

Создание типа

Бывают ситуации, когда стандартные типы полей для формы не подходят. В Joomla можно создавать свои типы параметров в расширениях.

Основной код для создания типа будет, примерно, такой:

// Защита от прямого доступа к файлу
defined('_JEXEC') or die('Restricted access');
// Подключение требуемых файлов
 * Создаем класс. Fieldname - имя типа
class JFormFieldFieldname extends JFormField
     * @var $type    Имя типа
    protected $type = 'Fieldname';
     * Метод, определяющий что будет выводить параметр
     * @return    Результат вывода типа
    protected function getInput()
        $html = '';
        // ...
        // Какой-то код, в котором определяется что нужно выводить
        // ...
        return $html;

Получение атрибутов

Как видно из кода выше в данном случае используется родительский класс JFormField, для получения атрибутов достаточно взять родительский объект $element:

    protected function getInput()
        // Получение атрибута some-attr
        // ...

Получение потомков

Если предполагается использовать сложный тип, состоящий из нескольких элементов, например:

<field name="some-name" type="fieldname">
   <some-action value="1">One</some-action>
   <some-action value="2">Two</some-action>

Общий код для получения потомков будет примерно такой:

protected function getInput()
    foreach ($this->element->children() as $action) {
        // Берем только нужные элементы, в данном случае some-action
        if ($action->getName() != 'some-action') {
        // Здесь будут значения value
        // Здесь будут значения содержащиеся между тегов some-action

Расширение или изменение стандартных типов

Бывают ситуации, когда нужно дополнить или изменить стандартный тип, используемый в Joomla. Для этого не стоит заново переписывать нужный тип, можно просто его расширить. Допустим, нужно изменить стандартный тип list, это будет выглядеть так:

// Защита от прямого доступа к файлу
defined('_JEXEC') or die('(@)|(@)');
// Подключение требуемых файлов
 * Создаем класс. Fieldname - имя типа
class JFormFieldFieldname extends JFormFieldList
     * @var $type    Имя типа
    protected $type = 'Fieldname';
     * Метод, заменяющий родительский JFormFieldList::getOptions()
     * @return    $options;
    protected function getOptions()
        // ...
        // Какой-то код, в котором определяется что нужно выводить
        // ...
        return $options;

Подключение в Компоненте

Допустим, в модели компонента подключается форма:


И в форме (some-form.xml) нужно добавить свой тип для поля. Для этого достаточно создать файл /com_component/models/fields/fieldname.php, где fieldname — это имя нужного типа.
После того как данный файл будет создан, можно добавлять этот тип в форму (/com_component/models/forms/some-form.xml)

<field name="some_name" type="fieldname"  />

Подключение в Модуле или Плагине

Если нужно добавить нужный тип поля в модуле или плагине, то для этого достаточно указать в XML файле директорию, в которой надо искать нужный тип.

Допустим, в модуле есть группа параметров:

<fieldset name="Some-Name">
    <field name="name1" type="text" />
    <field name="name2" type="fieldname" />

Чтобы определить тип fieldname, нужно указать путь в fieldset, где искать данный тип. И Joomla автоматически найдет данный файл, если такой будет существовать.


<fieldset name="Some-Name" ad...
    <fieldset name="Some-Name" addfieldpath="/administrator/components/com_component/models/fields">
        <field name="name1" type="text" />
        <field name="name2" type="fieldname" />

Смотрите также:
Комментарии (63) Добавить комментарий
  • Galen
    05 Февраля 2017, 22:09
     ↑  0  ↓     ответ

    I have been surfing online more than three hours today, yet I never

    found any interesting article like yours. It's pretty worth enough for me.

    In my view, if all webmasters and bloggers made good content as you did, the internet will be a lot more useful than ever before.

  • ??????????????
    13 Февраля 2017, 14:30
     ↑  0  ↓     ответ

    Right away I am going to do my breakfast, afterward having

    my breakfast coming again to read additional news.

  • reviews reviews
    28 Февраля 2017, 15:59
     ↑  0  ↓     ответ

    Thanks for ones marvelous posting! I really enjoyed reading it,

    you may be a great author. I will ensure that I bookmark your blog and

    will often come back from now on. I want to encourage one to continue your

    great job, have a nice weekend!

  • 4rx
    07 Марта 2017, 07:07
     ↑  0  ↓     ответ

    fantastic points altogether, you simply gained a new reader.

    What might you recommend in regards to your post that you simply made a few days ago?

    Any certain?

  • Jimmy
    27 Апреля 2017, 05:07
     ↑  0  ↓     ответ

    Good write-up. I certainly love this website. Continue the good work!

  • free mixtape downloads,rap mixtapes,street mixtapes,hip hop music, new mixtapes
    free mixtape downloads,rap mixtapes,street mixtapes,hip hop music, new mixtapes
    03 Мая 2017, 07:07
     ↑  0  ↓     ответ

    I love this post I read your blog fajrly often and you're always comming out with some great stuff.

    I share this on my Fcebook and myy followers looved it.

    Keep up thee good work.

  • clash of clans cheats
    clash of clans cheats
    06 Мая 2017, 16:15
     ↑  0  ↓     ответ

    I am in fact grateful to the holder of this web site who has

    shared this impressive paragraph at at this time.

    07 Мая 2017, 04:56
     ↑  0  ↓     ответ

    I'm not sure where you are getting your info, but good topic.

    I needs to spend some time learning more or understanding more.

    Thanks for wonderful info I was looking for this information for my mission.

  • Copmymusic.Com
    07 Мая 2017, 09:13
     ↑  0  ↓     ответ

    I'm not sure exactly why but this weblog is loading incredibly

    slow for me. Is anyone else having this issue or is it a issue on my end?

    I'll check back later on and see if the problem still exists.

    07 Мая 2017, 10:49
     ↑  0  ↓     ответ

    I visited a lot of website but I think this one contains something special

    in it.

  • tin nong
    tin nong
    10 Мая 2017, 06:28
     ↑  0  ↓     ответ

    I waas able to find ood informatіon fгom youг сontent.

  • tin tuc nong
    tin tuc nong
    10 Мая 2017, 06:29
     ↑  0  ↓     ответ

    ?o?'re so cool! I don't ?elieve I've re?d thгough anyt?ing likke t?iѕ beforе.

    So greаt tto find ?nother person wіth genuine th?ughts on t?is subject matter.

    ?eally.. t?ank you fоr starting this up. T?іs website

    іs one thing that's neede? on the web, someone witth a lіttle originality!

  • dich vu quan tri fanpage
    dich vu quan tri fanpage
    12 Мая 2017, 05:39
     ↑  0  ↓     ответ

    With havin so much content do you ever run into any issues

    of plagorism or copyright infringement? My site has a lot of

    completely unique content I've either created myself

    or outsourced but it appears a lot of it is popping

    it up all over the web without my agreement. Do you know any solutions to help stop content from being stolen? I'd really appreciate it.

  • giay nu
    giay nu
    13 Мая 2017, 12:53
     ↑  0  ↓     ответ

    Yo?r method of tellinng the ?hole thіng in this

    piece of writing is actually go?d, all ?an effortlessly understand іt,

    ?hanks a l?t.

  • tin tuc giai tri
    tin tuc giai tri
    14 Мая 2017, 16:25
     ↑  0  ↓     ответ

    Hel?? there, I disc?vered yo?r wеb

    site bby the use of Google еven as looking foor a similar topic,

    yo?r web site came up, it looks great. I have bоokmarked it in myy google b?okmarks.

    Hello there, juѕt becme aware ?f your wеblog vіa Google, and located

    that it iѕ truly informative. I amm gonna watch

    out foг brusse?s. I will be gratefu? in case you рropceed this in future.

    Numerouhs оther people wil? likely bbe benefited from y?ur writing.


  • king of avalon astuce
    king of avalon astuce
    15 Мая 2017, 07:01
     ↑  0  ↓     ответ

    It is appropriate time to make some plans for the future and it is time to be happy.

    I have read this post and if I could I desire to suggest you few interesting things or tips.

    Perhaps you could write next articles referring to

    this article. I want to read more things about it!

  • buy rosemary
    buy rosemary
    16 Мая 2017, 06:30
     ↑  0  ↓     ответ

    What's up mates, its impressive article on the topic of tutoringand entirely explained, keep it up all the time.

  • buy rosemary oil online
    buy rosemary oil online
    16 Мая 2017, 06:30
     ↑  0  ↓     ответ

    Asking questions are actually good thing if you are not understanding anything fully, but this paragraph provides fastidious understanding even.

  • asics gel lyte 3 женские купить
    asics gel lyte 3 женские купить
    17 Мая 2017, 22:58
     ↑  0  ↓     ответ

    asics gel lyte 3 женские купить

  • tin tuc
    tin tuc
    18 Мая 2017, 01:59
     ↑  0  ↓     ответ

    Hi there! This article could not be written any better!

    Looking at this article reminds me of my previous roommate!

    He constantly kept preaching about this. I will forward this post to him.

    Fairly certain he'll have a good read. Many thanks for


  • tin t?c
    tin t?c
    18 Мая 2017, 02:19
     ↑  0  ↓     ответ

    I am regular reader, how are you everybody? This paragraph posted

    at this web page is in fact pleasant.

    18 Мая 2017, 08:45
     ↑  0  ↓     ответ

    I always spent my half an hour to read this webpage's articles

    or reviews daily along with a cup of coffee.

  • workshop manuals
    workshop manuals
    18 Мая 2017, 08:47
     ↑  0  ↓     ответ

    Write more, thats all I have to say. Literally, it seems as though you relied on the video

    to make your point. You obviously know what youre talking

    about, why waste your intelligence on just posting videos to

    your weblog when you could be giving us something enlightening to


  • parts catalogs by CoolManuals
    parts catalogs by CoolManuals
    19 Мая 2017, 07:55
     ↑  0  ↓     ответ

    Actually no matter if someone doesn't understand after that its up to other visitors that they

    will help, so here it occurs.

  • truck maintenance manuals ford
    truck maintenance manuals ford
    19 Мая 2017, 07:57
     ↑  0  ↓     ответ

    Your means of telling everything in this article is genuinely nice, all can effortlessly understand it, Thanks a lot.

  • продление рабочей визы вкс екатеринбург
    продление рабочей визы вкс екатеринбург
    19 Мая 2017, 17:53
     ↑  0  ↓     ответ

    продление рабочей визы вкс екатеринбург

  • белые женские найк хуарачи
    белые женские найк хуарачи
    23 Мая 2017, 06:05
     ↑  0  ↓     ответ

    белые женские найк хуарачи

  • b?ng ??
    b?ng ??
    24 Мая 2017, 04:08
     ↑  0  ↓     ответ

    You are so awesome! I do not think I've truly read

    a single thing like that before. So good

    to discover another person with genuine thoughts on this topic.

    Seriously.. thanks for starting this up. This web site is one thing that is required on the internet,

    someone with some originality!

  • tin n?ng
    tin n?ng
    24 Мая 2017, 04:21
     ↑  0  ↓     ответ

    Wonderful website you have here but I was curious if you knew of any forums that cover the same topics talked about

    in this article? I'd really like to be a part of community where I can get

    opinions from other experienced individuals that share the same interest.

    If you have any recommendations, please let

    me know. Bless you!

  • xem them tai day
    xem them tai day
    27 Мая 2017, 04:25
     ↑  0  ↓     ответ

    I conceive other website proprietors should take this

    site as an example, very clean and fantastic user pleasant layout.

  • ?????? ????????? ??????????? 3 ????? Online Asfalistra
    ?????? ????????? ??????????? 3 ????? Online Asfalistra
    27 Мая 2017, 21:32
     ↑  0  ↓     ответ

    hello!,I love your writing so a lot! share we keep in touch extra about your article on AOL?

    I need an expert on this space to unravel my problem. May be that is you!

    Having a look ahead to see you.

  • Twila
    29 Мая 2017, 22:08
     ↑  0  ↓     ответ

    Aw, this was an incredibly nice post. Taking a few minutes and actual effort to

    generate a very good article… but what can I

    say… I put things off a lot and never seem to get anything done.

  • Marvin
    29 Мая 2017, 22:13
     ↑  0  ↓     ответ

    whoah this blog is great i like reading your posts. Stay up the

    good work! You already know, a lot of individuals are searching round for this info, you

    could help them greatly.

  • ???????? ???
    ???????? ???
    31 Мая 2017, 23:38
     ↑  0  ↓     ответ

    Hi there colleagues, pleasant piece off wriging and

    pleasant arguments commented at this place, I am truly enjoying by these.

  • Cough & Cold
    Cough & Cold
    06 Июня 2017, 04:49
     ↑  0  ↓     ответ

    Valuable info. Fortunate me I discovered your web site unintentionally, and I am surprised why this twist of fate did not happened in advance!

    I bookmarked it.

  • ?????? ????????
    ?????? ????????
    12 Июня 2017, 06:11
     ↑  0  ↓     ответ

    ?????? ??? ????????, ?????

    ?????? , ????? ?? ???'?, ???'? ??????, ???? ??????, ????? ??????, ????? ????, ???????? ????????, ?????? ????, ?????, ????? ????, ????? ???????, ?????? ????????, ????? ?????? ????? ,

    ???? ?????? ????? , ?????? ???????? ????? , ?????? ???????? ?????, ?????? ???????? ?????, ?????? ???????? ??????

    , ???? ?????? ?????, ???? ?????? ????? , ???? ??????? ??? ????, ???? ?????? ????, ?????? ??????? , ????

    ?????, ???? ??????, ???? ?????? ????, ????

    ?'??, ???? ????, ???? ??'??, ???? ??????, ???? ??? ?????, ???? ??? ?????, ???????

    ????????, ?????? ????????, ??????? ????????,

    ????? ????, ??? ??? , ??????

    ???? ??????

  • ???????? ??????????? ??????? asfalistra
    ???????? ??????????? ??????? asfalistra
    28 Июня 2017, 19:57
     ↑  0  ↓     ответ

    Attractive section of content. I simply stumbled upon your web

    site and in accession capital to assert that I acquire in fact loved account your weblog posts.

    Anyway I'll be subscribing for your augment or even I achievement you access consistently quickly.

    15 Июля 2017, 19:35
     ↑  0  ↓     ответ

    Hello, this weekend is nice for me, because this time i am reading this impressive educational paragraph here at my home.

    20 Июля 2017, 01:45
     ↑  0  ↓     ответ

    Attractive component of content. I simply stumbled upon your web site and

    in accession capiital to claim that I acquire actually enjoyed account your blog posts.

    Any way I will be subscribing tto your feeds or even I fulfillment you

    get right oof entry to constantly rapidly.

    20 Июля 2017, 01:45
     ↑  0  ↓     ответ

    Its such as you learn my thoughts! You seem to grasp a lot about this,

    such as you wrote the book in it or something.

    I feel that youu simply cann do with some p.c. to force the message home a bit, but instead of that, this is magnificent blog.

    An excellent read. I'll definitely bee back.

  • ???????????? ?????????
    ???????????? ?????????
    21 Августа 2017, 11:40
     ↑  0  ↓     ответ

    Hi there i am kavin, its my first occasion to commenting

    anyplace, whhen i read this article i thought i could allso make commen due

    too this goood paragraph.

  • Christi
    22 Ноября 2017, 19:40
     ↑  0  ↓     ответ

    At ClickDo Ltd. We appear forward to speaking quickly.

  • сбивание сосулек расценка
    сбивание сосулек расценка
    06 Декабря 2017, 16:42
     ↑  0  ↓     ответ

    сбивание сосулек расценка

  • judi online terbaik
    judi online terbaik
    07 Декабря 2017, 09:22
     ↑  0  ↓     ответ

    Excellent beat ! I would like to apprentice while you amend your website, how can i subscribe for a blog website?

    The account helped me a acceptable deal. I had been a

    little bit acquainted of this your broadcast offered bright clear


  • ?????? ???????
    ?????? ???????
    20 Декабря 2017, 22:20
     ↑  0  ↓     ответ

    Hi friends, its enormous pidce of writing on the topic of cultureand entirely explained, kep iit up all the time.

  • болезнь суставов перечень
    болезнь суставов перечень
    23 Декабря 2017, 01:49
     ↑  0  ↓     ответ

    Hurrah, that's what I was seeking for, what a information! present here at

    this weblog, thanks admin of this website.

  • lineage2 Revolution cheats
    lineage2 Revolution cheats
    10 Января 2018, 02:05
     ↑  0  ↓     ответ

    Great blo?! Is yur theme cstоm made or did you download

    it from ѕomewhere? A t?eme like yourѕ with a few simple tweeks ?ould гeally make

    my blog stand out. Pl?ase let me know where you got your design. Blesѕ you

  • outdoors
    05 Февраля 2018, 01:09
     ↑  0  ↓     ответ

    I d? not know if it's just me or if per?aps ever?one еlse experiencing issues with y?ur sitе.

    It seems like some of the text within your content are running off the

    screen. Can somebody else please comment and let me know if this is happening

    to thеm too? This may be a issuе with my web browser

    because I've had this happen previously. Appreci?te it

  • jual kaos polos giordano
    jual kaos polos giordano
    10 Февраля 2018, 01:11
     ↑  0  ↓     ответ

    My spouse and I stumbled over here different website aand thought I might check things out.

    I like what I see so now i aam folliwing you. Look forward to looking into your web pae again.

  • lam vo dien thoai vertu
    lam vo dien thoai vertu
    10 Февраля 2018, 18:45
     ↑  0  ↓     ответ

    Asking questions are really good thing if you are

    not understanding anything fully, but this paragraph gives

    fastidious understanding yet.

  • I Need Help Writing My Personal Statement
    I Need Help Writing My Personal Statement
    12 Февраля 2018, 20:31
     ↑  0  ↓     ответ

    I have been browsing on-line greater than 3 hours lately, but I never discovered any attention-grabbing article like yours.

    It is lovely price sufficient for me. Personally, if all site owners and bloggers made excellent content material as you

    probably did, the internet will likely be a lot more helpful

    than ever before.

  • sea shore flags
    sea shore flags
    13 Февраля 2018, 16:58
     ↑  0  ↓     ответ

    Great article, totally what I wanted to find.

  • Syracuse virus removal
    Syracuse virus removal
    18 Февраля 2018, 04:05
     ↑  0  ↓     ответ

    Douglas Computing offers technical services and solutions for all residential,

    home offices, and business customers. Our mission is to service our clients’

    needs with exceptional service and utilize all of our resources to ensure cost effective

    repair options. Douglas Computing is a company that values honesty and integrity and is dedicated to helping the community with their computer, laptops, and any

    other electronic issues. We promise to always treat our customers with

    the respect they deserve, always remember that our customer’s time is valuable to them, always respond quickly, politely and honest, and to always perform to the best of our ability for our clients

  • casino online
    casino online
    22 Февраля 2018, 05:25
     ↑  0  ↓     ответ

    Great post! We are linking to this particularly great post on our website.

    Keep up the good writing.

  • daftar agen bola piala dunia 2018
    daftar agen bola piala dunia 2018
    28 Февраля 2018, 12:58
     ↑  0  ↓     ответ

    My spouse and I stumbled over here different page and thought I might as well check things out.

    I like what I see so now i'm following you. Look forward to exploring your

    web page yet again.

  • cheap sporting goods online
    cheap sporting goods online
    01 Марта 2018, 10:12
     ↑  0  ↓     ответ

    Greetings! I know this is kind of 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 options for another platform. I would be fantastic

    if you could point me in the direction of a good platform.

  • Agen Judi Piala Dunia
    Agen Judi Piala Dunia
    17 Марта 2018, 01:04
     ↑  0  ↓     ответ

    Hmm it appears like your website ate my first comment (it was extremely long) so I guess I'll just sum it up what

    I had written and say, I'm thoroughly enjoying your blog.

    I as well am an aspiring blog writer but I'm still new

    to everything. Do you have any recommendations for newbie blog writers?

    I'd definitely appreciate it.

  • Bsl Level 2 Homework Practice 2-1
    Bsl Level 2 Homework Practice 2-1
    25 Марта 2018, 04:59
     ↑  0  ↓     ответ

    Hello there, You have done a great job. I will

    definitely digg it and personally suggest to my friends.

    I'm confident they will be benefited from this site.

    10 Апреля 2018, 01:31
     ↑  0  ↓     ответ

    Wollte Dir einfach mal in diesem Buch einen Gruss

    hinterlassen. :)

  • лучшее казино
    лучшее казино
    12 Апреля 2018, 14:10
     ↑  0  ↓     ответ

    Год назад Я поднял кэш в этом надежном казино

  • agen s128 terpercaya
    agen s128 terpercaya
    13 Апреля 2018, 01:34
     ↑  0  ↓     ответ

    Can you tell us more about this? I'd care to find out more details.

  • Khanna Vision Cataract surgery
    Khanna Vision Cataract surgery
    16 Апреля 2018, 05:11
     ↑  0  ↓     ответ

    Thanks for onss marvelous posting! I quite enjoyed reading

    it, you might bee a great author. I will

    make csrtain too bookmark your blog and will often come back at some point.

    Iwasnt to encourage you to ultimately continue your great job, have a nice weekend!

  • Khanna Vision Cataract surgery
    Khanna Vision Cataract surgery
    16 Апреля 2018, 05:11
     ↑  0  ↓     ответ

    I'd like to thank yyou for the efforts you have put iin writing this

    website. I am hoping to seee the same high-grade content from

    you in the future as well. In fact, your creative writing abilities has inspired me to get my own website now ;)

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

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

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