We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

How can I find out more about method arguments?

How can I find out what arguments can be passed to the methods of various classes provided by Phalcon, what the effect is, and what the default is?

I searched from the API Index, but I don't know what I can do even if it says "array $options" etc.

It seems that you can pass string even though the argument is shown as array.

https://docs.phalcon.io/3.4/en/api/phalcon_tag

public static string javascriptInclude ([array $parameters], [boolean $local])

Builds a SCRIPT[type=”javascript”] tag

<?php
echo Phalcon\Tag::javascriptInclude("https://ajax.googleapis.com/ajax/libs/jquery/2.2.3/jquery.min.js", false);
edited Nov '19

It's mean you can using syntax that what you preffer for. Like you can

    <?php
    echo Phalcon\Tag::javascriptInclude('https://blabla.com/blabla.js', false):

Even you can use

    <?php
    echo Phalcon\Tag::javascriptInclude(
        [
            'https://blabla.com/blabla.js',
            false
        ]);

That useful while you using Volt template engine, you just write like as

    {{assets.outputJs()}}

Or

    {{assets.outputJs('header')}}


4.2k

Thank you for your reply. And I'm sorry that I couldn't tell you what I wanted to say.

I want to know where you get information from what you have taught me.

I am glad that it was officially announced rather than looking at the C source, not the empirical knowledge gained from the experimental results, or collecting samples scattered in various places.

It's mean you can using syntax that what you preffer for. Like you can

  <?php
  echo Phalcon\Tag::javascriptInclude('https://blabla.com/blabla.js', false):

Even you can use

  <?php
  echo Phalcon\Tag::javascriptInclude(
      [
          'https://blabla.com/blabla.js',
          false
      ]);

That useful while you using Volt template engine, you just write like as

  {{assets.outputJs()}}

Or

  {{assets.outputJs('header')}}

The javascriptInclude () is just an example, so I don't find many other methods that can easily find information about "what values can be given" (maybe somewhere). I think.

Admittedly the documentation is poor in this respect. I recommend the first place you should look is the main documentation. Often the documentation explains various uses for the functionality you're trying to use - which includes examples for the various arguments. In this case: https://docs.phalcon.io/3.4/en/tag

I see that page has a note directing people to look at the API documentation. That type of note is an exception and honestly, I've never seen it before.

Have a look at this also

https://docs.phalcon.io/4.0/en/tag#javascriptinclude

The method really accepts an array and a boolean. Boolean is the local or not local. The array contains the same elements as you would expect in a <script> tag. If the first parameter is a string, it is treated as the src. If you pass an array you can specify other attributes for the tag such as src, type, class or whatever you need.



4.2k

Thank you.

I didn't look at the API Index “first”, I also saw the page you pointed out.

For example, lintTo().

A sample is shown, but not all of the argument examples are there, and no one expects that in the sample. The argument that can be specified seems to be all the attributes that can be specified as HTML, but is it described somewhere?

<a href="path/to/link"> <img src="path/to/image" alt="image of link"> </a>

If I want to do this, how do I use it?

So I read the description page about the method but there is no more information than the sample. (The display is confused, but I guess it means the contents of the sample. However, it is inappropriate to type array as it can be specified as either a string or an array.)

I don't know if this (is it possible to specify all HTML attributes?) Is limited to linkTo () or common to all Phalcon \ Tag methods.

I would like to know more about validators as well.

Since people can add any attributes they want per element, especially when utilizing javascript (for instance data-id, data-something etc.

https://docs.phalcon.io/4.0/en/tag#links

If you want to "add" an image inside a link you will need to do it in two steps. Assign a variable to your image tag and then add the tag in the link

echo Tag::linkTo(
    'https://phalcon.io/',
    Tag::image(
        [
            'img/hello.gif',
            'alt' => 'alternative text',
        ]
    ), 
    false
);

The general rule is that the first parameter (if it is a string) will be the main attribute for the tag. For image that would be src, for link it will be href etc. The easiest way for you to set things up without worrying about the syntax is to pass an array where the key of each element is the name of the attribute and the value is the value.



4.2k

The 4.0 page may be helpful, but isn't it RC at the moment?

I would like to avoid relying on a description of the version that is different from the one I use, as it may be partially new.

Yes it is but the Tag component has not changed at all. It is the same as the one in v3. The v4 docs are a bit more thorough.

It is relatively safe to be looking at v4 documentation. If in doubt, check the upgrade page https://docs.phalcon.io/4.0/en/upgrade to ensure that the component you are reading about has not changed



4.2k

Thank you for the supplement. I can read the document quite safely.

Please tell me a little more. Can each method of Phalcon\Tag specify all the attributes allowed in HTML? Where should I read to understand it (all possible or partly possible)?

And I don't think there's any information about validation (arguable arguments, default values, etc.), but is that somewhere overlooked in my oversight?

Validation: https://docs.phalcon.io/3.4/en/validation

As for the attributes for Phalcon\Tag it is up to the developer. Whatever you pass in the array will come up. Really there is no way that we can set presets of all potential attributes that a specific HTML tag would have.



4.2k

That's a shame. It is because even if there is something personally examined, it cannot be confirmed officially (partial confirmation is possible with a sample).

I am not sure I understand what you are saying. What do you expect to see that is not there? A method (say linkTo) as I mentioned accepts an array with the tags that you need in your <a> tag. Were you expecting something like this:

linkTo($href, $class, $othertag, $title, ....) ?

If that is the case, it is not feasible because we do not know what attributes each developer wants. So we add the core ones (href in this instance for the first parameter if passed by string) and then allow the array syntax for additional parameters that each developer needs.



4.2k

So we add the core ones (href in this instance for the first parameter if passed by string) and then allow the array syntax for additional parameters that each developer needs.

Looking at the sample, when there is an argument it is a string, but at another time it is an array.

string javascriptInclude ([array $parameters], [boolean $local])

So, I looked for what elements can be specified in $parameters, but it didn't seem to be specified.

And, I thought it was not mandatory because it was [], so I wondered what the default is. Of course, if try each one, I'll know what is the default, but I'm hesitant to try everything, and I wanted to have a documented thing.

Were you expecting something like this: linkTo($href, $class, $othertag, $title, ....) ?

No. I didn't notice it because I didn't read the v4.0 documentation, but I was expecting a description like that in the API description.

If it is clear what you want to do, it's faster to search from the API Index, but in "mixed $parameters" I don't know the specific thing and I will look for an explanation somewhere.

So we add the core ones (href in this instance for the first parameter if passed by string) and then allow the array syntax for additional parameters...

As I gradually realized that was the case, I thought I would have overlooked somewhere written. So I wanted to know where it was written.