Develop Modules without using the MVC model

Hello,
i try to develop a module for FreePBX but the Coding with the MVC Modell is really hard to understand for me.

I already investigated a lot of time and do not come forward with it.

I created some public functions to the Helloword module and tried to add some simple forms in the views but i cannot get it working in all views.
Its frustrating for one who never had done anything like this with a controller and a view model.

Is it also possible to develop a FreePBX module with simple PHP,HTML,CSS,JS mix without using the FreePBX Framework behind?
I try to develop and extend freepbx but the knowledge stopped after a single database form when i use the MVC. Its a headburner…:cry:

You can do whatever you want within the limits of FreePBX. You don’t have to do an MVC model and no one is forcing you to do so. If you want to mix everything in one page then it’s your module.

Do you have some usefull ressources to investigate more MVC for freepbx which i can use with BMO? Maybe i understand it anytime with some more examples and article about it. There are so many articles about it and when i open FreePBX then everything feels like …omg i dont understand it. I already looked over the FreepBX wiki but this wasnt enough to understand it :smiley:

What are you using right now? You say you are using a hello world module?

Yes i was extending the helloworld module with my own database table and views, forms. Renamed it and customized the page names and classes to get it working.

I also was looking over the code in other modules like “Sound Languages” or so to investigate myself a bit more.

A simple form with add.edit.remove works already. But “update” forms with tables like “endpoint_global” has (key,value) is too hard for me to include into my helloworld.

https://wiki.freepbx.org/display/FOP/FreePBX+Development

https://wiki.freepbx.org/display/FOP/BMO+DB_Helper

https://wiki.freepbx.org/pages/viewpage.action?pageId=19498386

Thank you,
but i think my problem is the ground knowledge of MVC with PHP howto use it. There is many about it to find in google but nothing i can use with FreePBX except the Helloworld examples :frowning:
The wiki is really good but i’m one step before at the moment. I need to learn before i can use it

Don’t over think it. You don’t need a deep understanding of the design pattern.

The basics in FreePBX is seperating the logic from the view. Nothing more, nothing less.

You do all your “processing” in the class and push the view.

So in your page you have

<?php
$thisUser = FreePBX::Mymodule()->getUser($_GET['id');
extract($thisUser);
?>
Hello <?php echo $username ?>

instead in your class you have

public function showPage(){
  $vars = $this->getUser($_GET['id']);
  return load_view(__DIR__.'/views/page.php',$vars);
}

Then in your page.mymodule.php

<?php
echo FreePBX::Mymodule()->showPage();

then views/page.php

Hello <?php echo $username ?>

So MVC Is nothing fancy it is just how you organize your code. The code is essentially the same.
Keep views as views
Keep logic out of views.
etc.

Furthermore since you want to go modify a Commercial Module’s database you should learn about PDO

$sth = FreePBX::Database()->prepare($sql);

$sth == http://php.net/manual/en/class.pdostatement.php