Skip to content

Instantly share code, notes, and snippets.

View bitkorn's full-sized avatar
💭
do not pull or push

Torsten Brieskorn bitkorn

💭
do not pull or push
View GitHub Profile
@bitkorn
bitkorn / zf2_routeName-and-route-in-Controller.php
Last active October 31, 2016 16:16
In ZF2 Controller: Get the route from URL and look at database for content to show it in view.
<?php
/**
* Get the route from URL and look at database for content to show it in view.
* @return ViewModel
*/
public function routesCmsAction()
{
$routeMatch = $this->serviceLocator->get('Application')->getMvcEvent()->getRouteMatch();
$routeName = $routeMatch->getMatchedRouteName();
@bitkorn
bitkorn / toggleW3.CSS-dropdown.js
Last active October 27, 2016 10:14
toggle W3.CSS dropdown with jQuery
function toggleW3(id) {
var toggleme = $("#" + id);
toggleme.css("z-index", 5);
if (!toggleme.hasClass("w3-show")) {
$("#" + id).addClass("w3-show");
$("#" + id).css("z-index", "1");
$("#" + id).removeClass("w3-hide");
var elementId = "";
$(".w3-dropdown-content").each(function (index, element) {
elementId = $(element).attr("id");
@bitkorn
bitkorn / db.local.php
Last active October 27, 2016 09:46
ZF2 multiple database conf
<?php
/**
* first DBConfig
*/
$dbParamsGlobal = array(
'hostname' => 'localhost',
'database' => 'somedbname',
'username' => 'root',
'password' => 'secretpasswd',
@bitkorn
bitkorn / mysql_enum_values.sql
Last active October 29, 2016 09:26
get possible ENUM values from a MySQL table column
-- @return(raw) ('firstenumvalue','secondenumvalue','...')
SELECT
-- cut the word 'enum'
SUBSTRING(COLUMN_TYPE, 5)
FROM
information_schema.COLUMNS
WHERE
TABLE_SCHEMA = 'schemaname'
AND TABLE_NAME = 'tablename'
AND COLUMN_NAME = 'columnname';
@bitkorn
bitkorn / Module-PHP-getViewHelperConfig_ViewHelper-with-URL-ViewHelper.php
Last active January 4, 2018 10:56
Use the ZF2 URL ViewHelper in my ViewHelper
<?php
class Module implements Zend\ModuleManager\Feature\ViewHelperProviderInterface
{
public function getViewHelperConfig()
{
return array(
'factories' => [
'simpleAnchor' => function(\Zend\View\HelperPluginManager $hpm) {
$sm = $hpm->getServiceLocator();
@bitkorn
bitkorn / shop_article_join_with_count.sql
Created November 4, 2016 07:59
SELECT tables and JOIN over other and COUNT some table rows
-- without DISTINCT comes false results
SELECT
sa.*,
sac.*,
COUNT(DISTINCT sagr.shop_article_group_relation_id) AS count_group_relation,
COUNT(DISTINCT sai.shop_article_image_id) AS count_image,
COUNT(DISTINCT sar.shop_article_relation_id) AS count_relation,
sasd.*,
COUNT(DISTINCT sasi.shop_article_size_item_id) AS count_size_item,
COUNT(DISTINCT sacomm.shop_article_comment_id) AS count_comment
@bitkorn
bitkorn / call_invoke_method_of_a_class_member.php
Created November 26, 2016 17:50
call __invoke() of a class member
<?php
class A
{
/**
*
* @var \SomeNamespace\SomeMember
*/
private $someMember;
<?php
$uri = $this->getRequest()->getUri();
$base = sprintf('%s://%s', $uri->getScheme(), $uri->getHost());
// or
$serverUrlHelper = $this->getServiceLocator()->get('ViewHelperManager')->get('ServerUrl');
$url = $serverUrlHelper($this->url()->fromRoute('some_routename'));
// or in view
echo $this->serverUrl($this->url('some_routename'))
<?php
/**
*
* @param array $data
* @return int
*/
public function insertSomeAndGetLastInsertValue(array $data)
{
$insert = $this->sql->insert();
$insert->values($data);
@bitkorn
bitkorn / zf2_short_fetch_all_tablex.php
Last active February 24, 2017 09:37
Short way to fetch all from SQL database with ZF2 \Zend\Db\Adapter\Adapter (no ZF2 \Zend\Db\TableGateway\AbstractTableGateway).
<?php
namespace Foo;
use Zend\Db\Adapter\Adapter;
use Zend\Db\Adapter\ParameterContainer;
class A
{