Giter Site home page Giter Site logo

phpmv / phpmv-ui Goto Github PK

View Code? Open in Web Editor NEW
32.0 6.0 4.0 1.18 MB

Visual components library (jQuery, Bootstrap, Semantic-UI) for php & php MVC Frameworks

License: Apache License 2.0

PHP 99.77% JavaScript 0.23%
jquery php-mvc-framework semantic-ui twitter-bootstrap php-framework component-library phpmv php ui php-library

phpmv-ui's Introduction

php-mv-UI

Visual components library (JQuery UI, Twitter Bootstrap, Semantic-UI) for php and php MVC frameworks

phpMv-UI website

Build Status Latest Stable Version Total Downloads License Scrutinizer Code Quality Documentation

What's phpMv-UI ?

phpMv-UI is a visual components library for php : a php wrapper for jQuery and UI components (jQuery, Twitter Bootstrap, Semantic-UI).

Using the dependency injection, the jQuery object can be injected into php framework container, allowing for the generation of jQuery scripts in controllers, respecting the MVC design pattern.

Requirements/Dependencies

  • PHP >= 7.0
  • JQuery >= 2.0.3
  • JQuery UI >= 1.10 [optional]
  • Twitter Bootstrap >= 3.3.2 [optional]
  • Semantic-UI >= 2.2 or Fomantic-UI >= 2.7 [optional]

Resources

I - Installation

Installing via Composer

Install Composer in a common location or in your project:

curl -s http://getcomposer.org/installer | php

Create the composer.json file in the app directory as follows:

{
    "require": {
        "phpmv/php-mv-ui": "^2.3"
    }
}

In the app directory, run the composer installer :

php composer.phar install

Installing via Github

Just clone the repository in a common location or inside your project:

git clone https://github.com/phpMv/phpMv-UI.git

II PHP frameworks configuration

Library loading

phpMv-UI complies with PSR-4 recommendations for auto-loading classes. Whatever the php framework used, with "composer", it is enough to integrate the Composer autoload file.

require_once("vendor/autoload.php");

Ubiquity configuration

Library loading

The library is already loaded by default in the config file app/config/config.php :

	"di"=>array(
			"@exec"=>array("jquery"=>function ($controller){
						return \Ajax\php\ubiquity\JsUtils::diSemantic($controller);
					})
			),

Use in controllers

Example of creating a Semantic-UI button

/**
 * @property \Ajax\php\ubiquity\JsUtils $jquery
 */
class ExempleController extends Controller{
	public function index(){
		$semantic=$this->jquery->semantic();
		$button=$semantic->htmlButton("btTest","Test Button");
		echo $button;
	}
}

Phalcon configuration

Library loading

Without Composer, It is possible to load the library with the app/config/loader.php file :

$loader = new \Phalcon\Loader();
$loader->registerNamespaces(array(
		'Ajax' => __DIR__ . '/../vendor/phpmv/php-mv-ui/Ajax/'
))->register();

Injection of the service

It is necessary to inject the JQuery service at application startup, in the service file app/config/services.php, and if necessary instantiate Semantic, Bootstrap or Jquery-ui :

$di->set("jquery",function(){
    $jquery= new Ajax\php\phalcon\JsUtils();
    $jquery->semantic(new Ajax\Semantic());//for Semantic UI
    return $jquery;
});

Use in controllers

Example of creating a Semantic-UI button

use Phalcon\Mvc\Controller;
use Ajax\php\phalcon\JsUtils;
/**
 * @property JsUtils $jquery
 */
class ExempleController extends Controller{
	public function indexAction(){
		$semantic=$this->jquery->semantic();
		$button=$semantic->htmlButton("btTest","Test Button");
		echo $button;
	}
}

CodeIgniter configuration

Library loading

If you want CodeIgniter to use a Composer auto-loader, just set $config['composer_autoload'] to TRUE or a custom path in application/config/config.php.

Then, it's necessary to create a library for the JsUtils class

Library creation

Create the library XsUtils (the name is free) in the folder application/libraries

use Ajax\php\ci\JsUtils;
class XsUtils extends Ajax\php\ci\JsUtils{
	public function __construct(){
		parent::__construct(["semantic"=>true,"debug"=>false]);
	}
}

Injection of the service

Add the loading of the XsUtils library in the file application/config/autoload.php

The jquery member will be accessible in the controllers

$autoload['libraries'] = array('XsUtils' => 'jquery');

Once loaded you can access your class in controllers using the $jquery member:

$this->jquery->some_method();

Laravel configuration

Library loading

If you do not use the Composer autoloader file, you can also load phpMv-UI with composer.json :

"autoload": {
    "classmap": [
        ...
    ],
    "psr-4": {
        "Ajax\\": "vendor/phpmv/php-mv-ui/Ajax"
    }
},

Injection of the service

Register a Singleton in bootstrap/app.php file :

$app->singleton(Ajax\php\laravel\JsUtils::class, function($app){
	$result= new Ajax\php\laravel\JsUtils();
	$result->semantic(new Ajax\Semantic());
	return $result;
});

Then it is possible to inject the JsUtils class in the base class controllers constructor :

use Ajax\php\laravel\JsUtils;
class Controller extends BaseController{
    use AuthorizesRequests, AuthorizesResources, DispatchesJobs, ValidatesRequests;
    protected $jquery;

    public function __construct(JsUtils $js){
    	$this->jquery = $js;
    }

    public function getJquery() {
    	return $this->jquery;
    }
}

Yii configuration

Library loading

The classes in the installed Composer packages can be autoloaded using the Composer autoloader. Make sure the entry script of your application contains the following lines to install the Composer autoloader:

require(__DIR__ . '/../vendor/autoload.php');
require(__DIR__ . '/../vendor/yiisoft/yii2/Yii.php');

In the same file, register a new dependency :

\Yii::$container->setSingleton("Ajax\php\yii\JsUtils",["bootstrap"=>new Ajax\Semantic()]);

Injection of the service

The JsUtils singleton can then be injected into controllers

namespace app\controllers;

use yii\web\Controller;
use Ajax\php\yii\JsUtils;

class SiteController extends Controller{
	protected $jquery;

	public function __construct($id, $module,JsUtils $js){
		parent::__construct($id, $module);
		$this->jquery=$js;
	}
}

Symfony configuration

Library loading

If you do not use the Composer autoloader file, you can also load phpMv-UI with Ps4ClassLoader :

use Symfony\Component\ClassLoader\Psr4ClassLoader;

require __DIR__.'/lib/ClassLoader/Psr4ClassLoader.php';

$loader = new Psr4ClassLoader();
$loader->addPrefix('Ajax\\', __DIR__.'/lib/phpmv/php-mv-ui/Ajax');
$loader->register();

Symfony 4

Create a service inheriting from JquerySemantic

namespace App\Services\semantic;

use Ajax\php\symfony\JquerySemantic;

class SemanticGui extends JquerySemantic{
}

Check that autowiring is activated in config/services.yml:

services:
    # default configuration for services in *this* file
    _defaults:
        autowire: true      # Automatically injects dependencies in your services.

You can then use dependency injection on properties, constructors or setters:

namespace App\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use App\Services\semantic\SemanticGui;

BarController extends AbstractController{
	/**
	 * @var SemanticGui
	 */
	protected $gui;

    public function loadViewWithAjaxButtonAction(){
    	$bt=$this->gui->semantic()->htmlButton('button1','a button');
    	$bt->getOnClick("/url",'#responseElement');
    	return $this->gui->renderView("barView.html.twig");
    }
}

Symfony 3

Injection of the service

Create 2 services in the app/config/services.yml file :

  • The first for the JsUtils instance
  • The second for the controller
parameters:
    jquery.params:
        semantic: true
services:
    jquery:
        class: Ajax\php\symfony\JsUtils 
        arguments: [%jquery.params%,'@router']
        scope: request
    app.default_controller:
        class: AppBundle\Controller\DefaultController 
        arguments: ['@service_container','@jquery']

It is then possible to inject the Symfony container and the JsUtils service in the controller constructor :

namespace AppBundle\Controller;

use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Ajax\php\symfony\JsUtils;
use AppBundle\AppBundle;

/**
 * @Route(service="app.default_controller")
 */
class DefaultController extends Controller{
	/**
	 * @var Ajax\php\symfony\JsUtils
	 */
	protected $jquery;

	public function __construct(ContainerInterface $container,JsUtils $js){
		$this->container=$container;
		$this->jquery= $js;
	}
}

CakePhp configuration

Component creation

Copy the file JsUtilsComponent.php located in vendor/phpmv/php-mv-ui/Ajax/php/cakephp to the src/controller/component folder of your project

Component loading in controllers

Add the JsUtils component loading in the initialize method of the base controller AppController, located in src/controller/appController.php

    public function initialize(){
        parent::initialize();

        $this->loadComponent('RequestHandler');
        $this->loadComponent('Flash');
        $this->loadComponent('JsUtils',["semantic"=>true]);
    }

Usage

the jquery object in controller will be accessible on $this->JsUtils->jquery

Code completion in IDE

With most IDEs (such as Eclipse or phpStorm), to get code completion on the $jquery instance, you must add the following property in the controller documentation:

/**
  * @property Ajax\JsUtils $jquery
  */
class MyController{
}

phpmv-ui's People

Contributors

jcheron avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

phpmv-ui's Issues

Phalcon autoload does not work?

Hi there,
i am looking for a way to use the semantic-ui with phalcon (Version: 3.3.2). I cant get it working following the docs.

Error i got:

[Sat Mar 31 09:59:17 2018] PHP Fatal error:  Uncaught Error: Class 'Ajax\php\phalcon\JsUtils' not found in /home/workspace/hours/app/config/services.php:116
Stack trace:
#0 [internal function]: Closure->{closure}()
#1 [internal function]: Phalcon\Di\Service->resolve(NULL, Object(Phalcon\Di\FactoryDefault))
#2 [internal function]: Phalcon\Di->get('jquery', NULL)
#3 [internal function]: Phalcon\Di->getShared('jquery')
#4 /home/workspace/hours/app/controllers/IndexController.php(13): Phalcon\Di\Injectable->__get('jquery')
#5 [internal function]: IndexController->indexAction()
#6 [internal function]: Phalcon\Dispatcher->callActionMethod(Object(IndexController), 'indexAction', Array)
#7 [internal function]: Phalcon\Dispatcher->dispatch()
#8 /home/workspace/hours/public/index.php(42): Phalcon\Mvc\Application->handle()
#9 /home/workspace/hours/.htrouter.php(30): require_once('/home/wor...')
#10 {main}
  thrown in /home/workspace/hours/app/config/services.php on line 116

I installed phpmv via composer:
composer.phar require phpmv/php-mv-ui 2.3.x-dev
composer.json was created, files are there:
screenshot_20180331_100311

I have to add the documented code to the service/loader.php AND i have to change the path to be an absolute one.

<?php

$loader = new \Phalcon\Loader();

/**
 * We're a registering a set of directories taken from the configuration file
 */
$loader->registerDirs(
    [
        $config->application->controllersDir,
        $config->application->modelsDir
    ]
)->register();

$loader->registerNamespaces(array(
		'Ajax' => '/home/workspace/hours/vendor/phpmv/php-mv-ui/Ajax/'
))->register();

Is there anything i did wrong?

Widgets

jsCallback with fieldAs methods has a strange behavior

fromDatabaseObjects

Replace fromDatabaseObjects by forEach
make fromDatabaseObjects deprecated

[form] Input file parameters

[HtmlFormInput] addToProperty Input type file parameters

I am trying to set up an upload form like this:

$importFrm = $this->sGui->htmlForm('import_frm', [
	$this->sGui->htmlHeader('', 3, $this->i18n->trans('mMenu.action.import')),
	$this->sGui->htmlDivider(''),
	$this->sGui->htmlInput('data_file', 'file'),
	$this->sGui->htmlButton('snd', $this->i18n->trans('btn.upload'))->asSubmit()
]);
$importFrm->getItem(2)
		  ->addToProperty('accept', 'application/csv;text/csv');

Steps

See code above

Expected Result

An input element with the accept attribute set.

Actual Result

The attributes go to the div containing the input tag.

image

Also, $importFrm->addPropertyValues('method', 'POST'); sets the method to the div inside the form and not to the form tag.


EDIT: OK, I solved the method by using addToProperty(), which is what should happen with the Input tag.

Versions

Current; current Semantic/Fomantic; php 7.2.

Semantic-UI Failed to configure for Symfony 4.2.8

Semantic-UI Failed to configure for Symfony 4.2.8

YAML syntax error.

Steps

I put the following in the config/services.yaml file:

parameters:
    locale: 'en'

    jquery.params:
        semantic: true
        defer: true

services:
    # ... Symfony stuff ...
    # PhpMV-UI (https://phpmv-ui.kobject.net/Index/semantic/31)
    jquery:
        class: Ajax\php\symfony\JsUtils
        arguments: ['%jquery.params%','@router']
        scope: request

    app.default_controller:
        class: AppBundle\Controller\DefaultController
        arguments: ['@service_container','@jquery']

    Ajax\php\symfony\JsUtils: '@jquery'

Expected Result

Loading of the dependencies.

Actual Result

image

Versions

phpMv 7.2.17
php 7.2.17
php framework Symfony 4.2.8

[Bootstrap][HtmlModal] Ajax\bootstrap\html\HtmlModal::setDraggable($value) should be compatible with Ajax\common\html\BaseHtml::setDraggable

Steps

$dialog2=$this->jquery->bootstrap()->htmlModal("boite1","Titre de la boîte de dialogue","test");
$form=$this->jquery->semantic()->htmlForm("frm1");
$form->addInput("login","Login");
$form->addButton("","Submit")->asSubmit();
$dialog2->setContent($form->getContent());
echo $dialog2->compile($this->jquery);

Expected Result

No warning

Actual Result

Warning: Declaration of Ajax\bootstrap\html\HtmlModal::setDraggable($value) should be compatible with Ajax\common\html\BaseHtml::setDraggable($attr = 'id', $dropZone = NULL, $parameters = Array) in C:\www\appweb\vendor\phpMv-UI-2.2.6\Ajax\bootstrap\html\HtmlModal.php on line 14

Versions

phpMv 2.2.6
Semantic-ui 2.4.1
jQuery 3.4.1

[semantic-ui][menu] Semantic sub-menus, is it possible?

[semantic-ui][menu] Semantic sub-menus, is it possible?

[RANT] I don't know why Bootstrap removed submenus in v3, but it is the main reason I do not use it anymore (if I can avoid it). [END RANT]

I am trying to set up a sub-menu, but I fail to see how can I do it programmatically.

Something like this

I tried using

$subMenu = $gui->semantic()->htmlDropdown('submenu1', 'Menu Item 2');
$submenu->addItem('Option 1');
$submenu->addItem('Option 2');

$menu->addDropdownAsItem('Menu Title', [
  'Menu Item 1',
  $submenu,
  'Menu Item 3'
]);

But it does not show as expected.

Any clue? Thank you.

support for Fomantic-ui 2.8

Hi, how can i turn to FOMANTIC 2.8 becouse semantic is out of update from 2018, and FOMANTIC is fork from it and now has new features

setup and confguration

Hi, I try use library in my joomla component. The elements are generated correctly, but does not work with the interactivity using jquery.
I connected jquery, semantic.css, semantic.js.

Could you explain to me what am I doing wrong or where I can read more about it?
Thanks!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.