How to extend wappler with php functions

Just made a quick test with a simple php echo and it works. Here is the code I used

<!doctype html>
<html><head>
<meta charset="UTF-8">
<title>Untitled Document</title>
  <script type="text/javascript" src="../dmxAppConnect/dmxAppConnect.js"></script>
  </head>
  <body is="dmx-app">
    <div dmx-repeat:repeat1="serverconnect1.data.query1">
       <p dmx-show="comunidad_id!=3">{{comunidad_name_gr}}</p>
      <p dmx-show="comunidad_id==3"><?php echo 'ok';?> {{comunidad_name_gr}}</p> 
    </div>
    <dmx-serverconnect id="serverconnect1" url="../dmxConnect/api/frontend/franchisees_locations/get_active_communidades.php"></dmx-serverconnect>
     </body></html>

Here is the result in the browser (you will see that ‘ok’ is only displayed when the id of the record is equal to 3)

Hi Tina,

Just to start from the beginning: Wappler is not a PHP editor. if you are just a PHP coder that wants to write everything in code - you can better use a regular code only editor.

That said - Wappler do has all the powers of server side development. But we made them much more easier to access and made you even more productive, so you don’t have to write all this PHP code by yourself each time.

This is done by the integrated Server Connect framework - which gives you a full blown runtime generator of all the PHP or other server side code you will ever need.

It is also works on on much higher level - so instead of writing you code line by line - you are now creating a server side workflow actions containing multiple steps of all the work that you need to do server side.

So you can have multi step actions like querying a database, looping through the records, sending mail for each record or just do an extra formatting before returning the data to the client where it is nicely displayed with the front-end framework App Connect.

So Server Connect might have a small learning curve to find our about all the available actions and data formatting options, but believe me it is nothing like learning all the PHP that you have done and also it will make you hugely productive.

You can read all about it here:

https://wappler.io/docs/#Server-Side-Components

As for your data formatting question - you can do it indeed server side with the integrated Data Formatter there - it has tons of usefull strings and number formatting functions - that you might have written in PHP yourself indeed, but now with the data formatter it is much easier and integrated.

It is however more advisable and a better way to do data formatting on the client side. So you just keep your server actions data retrieval and processing while on the client side with the App Connect Data Formatter - you do the needed formatting for the display. This is also explained in the docs here:

https://wappler.io/docs/#Formatting-Data

So check it out and give the docs a good reading and you will see that with Wappler you have a tool that even PHP coders you will be gaining a huge amount of productivity boost.

3 Likes

George so cool that you are here listening to us. Means a lot!

1 Like

100% agree with George. Wappler needs a bit of time to understand how it works. But once you get the idea of how things are accomplished you will get 1000% more productive. It is unbelievable what it can be created within Wappler (ServerConnect & AppConnect) in a few hours. The best part is that the debugging proccess almost disappears. If you are new to Wappler I would suggest the following.

Try to implement any functionality you want through Serverconnect and Appconnect.
If you find yourself stuck post it here.
If still not possible try to handcode it and integrate into your Wappler code. (like the simple example posted above)
btw if it is a good idea for everyone then very possible that this functionality will be intergrated in Wappler in one of the next updates.

Think of Wappler as a Photoshop for developers. Believe it or not there are only a few things (if any) that can not be done with Wappler using Server and App Connect.

1 Like

He want to implement an external php library
and its not mentioned in the documentation

for example we use Hiri calendar like this one
how can i do that in wappler

Well you should read the external php API and call relative functions from Wappler when needed. I once did this with an external js API. Had to find the functions from the API and call them from Wappler when I wanted to. Dont know how this php calendar works but you should use as much as possible interaction with it through ServerConnect and update the frontend with Appconnect calling calendar actions when needed.

back at the original question :slightly_smiling_face:

how can you call a php function from server connect
or js function from app connect

1 Like

:slight_smile: well basically you should create the functionality in serverconnect. For example if you want to format days, use the formatter. But also please let me try something. This is interesting.

Well Server Connect is pretty much runtime server side language generator, so it runs a=on PHP servers just as easy as it runs on others like ASP and ASP.NET

This means that all the functions and data filters we create have to be compatible with all the server languages we support.

So you can’t just “hack-in” a PHP function in server connect, we have to make it available as data filter for all the languages.

well that isn’t good news.

you should add an action that we can supply with a function and return a value.

well we actually get over 70 formatting functions and a full blown javascript expressions evaluation engine, so there is nothing you can’t do in the current data expressions. So is really no need to do any custom functions in PHP.

But i just mentioned the use case

Formatting is not the issue or tge needed results.
We need to get the current date in Hijri calendar by supplying the current Georgian date.

We already have a lot of date formatting functions and you can write a simple calculation expression ( as javascript expression which is evaluated in PHP) to convert the date.

If that is much requested we can also add the function to the standard date conversion functions. Its just that nobody requested this before.

Sometimes it is faster to write a php function that returns a value to a variable.
Add it to the current page and call that variable in the query builders conditions tab.
But if I understand you correctly, this is not possible?

In your current PHP page you can do whatever you want with php. I was only referring to the Server Connect generated actions

I understand but I still wonder about my initial question.
Can I use a variable in the condition in the query builder?
Or enter the name of a function that returns a value?

And how do I envoke a php function on form submit or on click event?
There are things not supported (yet) such as payments.
I use Stripe and have a custom integration.

Yes you can use variables in Server Connect. As you discover more and more Server Connect and its powers you will see that its visual action builder is actually a visual programming tool! So there are variables, expressions, loops, conditional statements, repeaters and steps to execute - so much power and all visually for you!

So I suggest you explore it more and invest a bit more time in learning and you will then benefit of its full powers!

We already started covering the base of Server Connect in the documentation:
https://wappler.io/docs/#Server-Side-Components

But there is so much to cover as it is really a very large server side framework.
We have it also available fro Dreamweaver and are in process of converting the docs to Wappler as well but the usage and base is the same, so for even more extended docs and videos you can still check the DMXzone Server Connect page:

and its manual:

2 Likes

2 posts were split to a new topic: How to Round a number with decimals with Server Data Formatter

2 posts were merged into an existing topic: How to Round a number with decimals with Server Data Formatter

@Tina_Hammar: I am glad I am not alone on this. I have been on the verge of giving up on Wappler as well, but now I cancelled my Dreamweaver subscription instead. If you get stuck just post your problem as a “How To” and users will come to the rescue as well as the DMXZone team will. No worries. If I can get a learning curve at my age, you most certainly can too. :grinning::wink:

1 Like