Skip to content

Instantly share code, notes, and snippets.

Avatar
💭
do not pull or push

Torsten Brieskorn bitkorn

💭
do not pull or push
View GitHub Profile
@bitkorn
bitkorn / db.local.php
Last active Oct 27, 2016
ZF2 multiple database conf
View db.local.php
<?php
/**
* first DBConfig
*/
$dbParamsGlobal = array(
'hostname' => 'localhost',
'database' => 'somedbname',
'username' => 'root',
'password' => 'secretpasswd',
@bitkorn
bitkorn / toggleW3.CSS-dropdown.js
Last active Oct 27, 2016
toggle W3.CSS dropdown with jQuery
View toggleW3.CSS-dropdown.js
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 / mysql_enum_values.sql
Last active Oct 29, 2016
get possible ENUM values from a MySQL table column
View mysql_enum_values.sql
-- @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 / zf2_routeName-and-route-in-Controller.php
Last active Oct 31, 2016
In ZF2 Controller: Get the route from URL and look at database for content to show it in view.
View zf2_routeName-and-route-in-Controller.php
<?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 / shop_article_join_with_count.sql
Created Nov 4, 2016
SELECT tables and JOIN over other and COUNT some table rows
View shop_article_join_with_count.sql
-- 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
View call_invoke_method_of_a_class_member.php
<?php
class A
{
/**
*
* @var \SomeNamespace\SomeMember
*/
private $someMember;
View zf2_table_lastInsertValue.php
<?php
/**
*
* @param array $data
* @return int
*/
public function insertSomeAndGetLastInsertValue(array $data)
{
$insert = $this->sql->insert();
$insert->values($data);
View zf2_base-url_in_controller_and_view.php
<?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'))
@bitkorn
bitkorn / zf2_short_fetch_all_tablex.php
Last active Feb 24, 2017
Short way to fetch all from SQL database with ZF2 \Zend\Db\Adapter\Adapter (no ZF2 \Zend\Db\TableGateway\AbstractTableGateway).
View zf2_short_fetch_all_tablex.php
<?php
namespace Foo;
use Zend\Db\Adapter\Adapter;
use Zend\Db\Adapter\ParameterContainer;
class A
{
@bitkorn
bitkorn / ZF2_log-SQL-string-with-driver-support.php
Created Jul 23, 2017
ZF2 log SQL string with driver-support
View ZF2_log-SQL-string-with-driver-support.php
<?php
namespace BitkornShop\Table\Basket;
use Zend\Db\Adapter\Adapter;
use Zend\Db\ResultSet\HydratingResultSet;
use Zend\Db\TableGateway\AbstractTableGateway;
use Zend\Db\Adapter\AdapterAwareInterface;
/**
You can’t perform that action at this time.