IT-Solutions for Special Requirements

Schlagwort: php

Joomla, Laravel, JoomLavel und camelCase

Ein kleiner Überblick:

  • snake_case / lowercase => C / C++, (my favorite)
  • camelCase
  • PascalCase
  • kebab-case
FrameworkKlassenMethodenAttribute
LaravelPascalCasecamelCasecamelCase
WordPress CMSsnake_case
Joomla CMSPascalCasecamelCasecamelCase
Übersicht der Frameworks und der Schreibstile

In unserem JoomLavel Projekt halten wir uns an die Joomla und Laravel Stile. Es gibt bei Laravel natürlich folgendes zu bedenken:

By convention, the „snake case“, plural name of the class will be used as the table name unless another name is explicitly specified.

https://laravel.com/docs/7.x/eloquent#eloquent-model-conventions

Somit wird der Tabellenname in der Datenbank im snake_case im plural angegeben. Das entsprechde Model im Laravelcode aber im PascalCase

Im Eloquent Beispiel sieht das so aus:

DB Tabelle: my_flights, Model: MyFlight

Im Frontend in HTML sollten Attribute im kebap-case geschrieben werden. Wenn wir z.B. das data-attribute nutzen.

data-user-id="121"

make configuration.php beautiful

Joomla has a quite ugly configuration file. configuration.php is cluttered and sorted i a very strange way?

<?php
class JConfig {
	public $offline = '1';
	public $offline_message = 'Wartungsmodus';
	public $display_offline_message = '1';
	public $offline_image = '';
	public $sitename = 'joomlavel-joomla-dev';
	public $editor = 'tinymce';
	public $captcha = '0';
	public $list_limit = '20';
	public $access = '1';
	public $debug = '0';
	...
	...
	...
	public $feed_email = 'none';
	public $log_path = '/logs';
	public $tmp_path = '/tmp';
	public $lifetime = '15';
	public $session_handler = 'database';
	public $shared_session = '0';
}

I really like https://12factor.net/ and its twelve-factor app approach. configuration recommendation is to seperate config in a way that they are language- and OS-agnostic. But how to do this? Here is our approach:

    public function __construct(){
		if (file_exists(SELF::JoomLavelApiDirectory.'.env')) {
			$env = parse_ini_file (SELF::JoomLavelApiDirectory.'.env',false, INI_SCANNER_RAW);
			$this->sitename = $env['APP_NAME'];
			$this->debug = (int)filter_var($env['APP_DEBUG'], FILTER_VALIDATE_BOOLEAN);;
			$this->live_site = $env['APP_URL'];
			$this->dbtype = $env['DB_CONNECTION'].'i';
			$this->host = $env['DB_HOST'];
			$this->db = $env['DB_DATABASE'];
			$this->user = $env['DB_USERNAME'];
			$this->password = $env['DB_PASSWORD'];
			
			$this->mailfrom = $env['MAIL_FROM_ADDRESS'];
			$this->fromname = $env['MAIL_FROM_NAME'];
			$this->smtpport = $env['MAIL_PORT'];
			$this->smtphost = $env['MAIL_HOST'];
			$this->smtpuser = $env['MAIL_USERNAME'];
			$this->smtppass = $env['MAIL_PASSWORD'];	
		}
		
    }

The configuration.php could also be seperated in blocks:

	#APP
	public $live_site = '';
	public $sitename = "joomla";
	
	#DB
	public $dbtype = 'mysqli';
	public $host = 'localhost';
	public $user = 'groot';
	public $password = '';
	public $db = 'joomlavel-dev';
	public $dbprefix = 'f862e_';
	
	#SESSION
	public $session_handler = 'database';
	public $shared_session = '0';
	public $lifetime = '15';

You can see the files in our Github::JoomLavel project.

We have a baby, we have called it: JoomLavel,

In the last 2 years we have worked in complicated Joomla CMS project. The project has grown and we hit joomla limitations.

How to leave a vendor-lockin and joomla limitations? A REST API might be the solution. The Separation_of_concerns principle describes a seperation of a computer program in distinct sections.

JoomLavel allows you to use a modern laravel API backend in combination with your own joomla application. You can easily add functionalities in the laravel api to enchance joomla functionalities without changing the joomla framework code or joomla components or plugins.

joomLavel name creation

Checkout our Github documentation page:

https://github.com/getit-berlin/JoomLavel-documentation

More informations will be published the next days:

Wir haben DataTables entdeckt

DataTables von https://datatables.net/

Wir wollten eine einfache schlanke Lösung um tabellarisch Informationen anzuzeigen.

Uns wurde https://datatables.net/ empfohlen. Wie setzen wir es ein?

Im Frontend reicht eine generische View. Einzelnen Views werden nur über eine einzelne .js Datei und den entsprechenden Backen-Endpoint definiert.

Wie sieht die generische View aus in einer Joomla componenten aus?

<?php

defined('_JEXEC') or die();

$application = JFactory::getApplication();
$document = JFactory::getDocument();

$document->addScript("https://cdn.datatables.net/v/dt/jszip-2.5.0/dt-1.10.18/b-1.5.6/b-colvis-1.5.6/b-html5-1.5.6/b-print-1.5.6/sl-1.3.0/datatables.min.js"); 
$document->addStyleSheet("https://cdn.datatables.net/v/dt/jszip-2.5.0/dt-1.10.18/b-1.5.6/b-colvis-1.5.6/b-html5-1.5.6/b-print-1.5.6/sl-1.3.0/datatables.min.css");

if (isset($this->scriptfilename)) {
    $document->addScript(JURI::base().'components/com_js/assets/js/'.$this->scriptfilename.'.js');
}

if (isset($this->title)) {echo "<h2>".$this->title."</h2>";}
?>

<table cellpadding="0" cellspacing="0" border="0" dataid="<?php echo $this->dataid; ?>" class="display mydatatable" id="<?php echo $this->scriptfilename; ?>" width="100%">
</table>

...

Die muss mir dem Parameter: „scriptfilename“ und ggf. dem „title“ definiert werden. „dataid“ ist ein Parameter mit dem wir ggf. im .js weiterarbeiten können.

Das entsprechende .js mit der DataTables definition wird über „addScript“ geladen.

Präsentiert von WordPress & Theme erstellt von Anders Norén