create function

72 views
Skip to first unread message

frankz

unread,
Jan 2, 2017, 9:49:57 AM1/2/17
to f3-fra...@googlegroups.com
you can get some help, to create and use functions in fat free ?

Thanks

ved

unread,
Jan 2, 2017, 9:54:18 AM1/2/17
to Fat-Free Framework
What exactly do you mean?

F3 is plain php so to create functions you use:

function myFunction() {
    echo
'This is a function';
}

Somehow I guess this is not what you're asking? 

frankz

unread,
Jan 2, 2017, 10:09:28 AM1/2/17
to f3-fra...@googlegroups.com
I said that badly.
for variables use F3-> set ( 'var', 'fair') and are global, and for functions?

ikkez

unread,
Jan 2, 2017, 10:24:51 AM1/2/17
to Fat-Free Framework
it's the same:

$f3->set('var', function(){ return "value"; });

$val = $f3->var();

ved

unread,
Jan 2, 2017, 10:33:06 AM1/2/17
to Fat-Free Framework
Try:

$f3->set('myfunc', function($a,$b) {
   
return $a+$b;
});

And on your templates:

{{ @myfunc(2,3) }}


Summer White

unread,
Jan 2, 2017, 6:56:36 PM1/2/17
to Fat-Free Framework
This can't be used in the template language though can it?

$f3->set('var', function() { return 1+1; });

{{ var() }}

bcosca

unread,
Jan 2, 2017, 7:37:54 PM1/2/17
to Fat-Free Framework
Yes you can:

{{ @var() }}

Franco Zenatti

unread,
Jan 3, 2017, 12:47:04 AM1/3/17
to bcosca via Fat-Free Framework
thanks

--
-- You've received this message because you are subscribed to the Google Groups group. To post to this group, send an email to f3-fra...@googlegroups.com. To unsubscribe from this group, send an email to f3-framework+unsubscribe@googlegroups.com. For more options, visit this group at https://groups.google.com/d/forum/f3-framework?hl=en
---
You received this message because you are subscribed to a topic in the Google Groups "Fat-Free Framework" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/f3-framework/Lkjb66G7PpM/unsubscribe.
To unsubscribe from this group and all its topics, send an email to f3-framework+unsubscribe@googlegroups.com.
To post to this group, send email to f3-fra...@googlegroups.com.
Visit this group at https://groups.google.com/group/f3-framework.
To view this discussion on the web visit https://groups.google.com/d/msgid/f3-framework/cff1ad28-f211-4d24-9894-bfd7349485fe%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Anatol Buchholz

unread,
Jan 3, 2017, 2:45:42 AM1/3/17
to f3-fra...@googlegroups.com
If you like to encapsule everything in a class this should work as well:

{{ \helper\toolbox::instance()->dosomething(@foo) }}


namespace helper;
class toolbox extends \prefab
{

...

   
/**
     * Send bar to client
     */

   
public function dosomething($foo) {
       
return $bar

   
}

frankz

unread,
Jan 8, 2017, 1:59:52 AM1/8/17
to Fat-Free Framework
and if the function does not return void ?


Il giorno lunedì 2 gennaio 2017 15:49:57 UTC+1, frankz ha scritto:

Anatol

unread,
Jan 8, 2017, 4:47:25 AM1/8/17
to f3-fra...@googlegroups.com
hmmm unsure if I understand your question correctly.
  • For php 7.1 void as return type was accepted 
  • before 7.1 you return just NULL
  • if you have something to return than return it ;) return ($my_new_converted_array)

Reply all
Reply to author
Forward
0 new messages