
Отзыв о книге: Объектно-ориентированное программирование в С++ Р. Лафоре
Jan 12 2016, 21:39:23

<select id="multiple" class="form-control select2-multiple" multiple name="tags[]" >
{foreach $labels as $label}
<option value="{$label->id}" {if !empty($exists.{$label->id})}selected{/if} >{$label->title}</option>
{/foreach}
</select>
<script>
$(document).ready(function () {
$("#multiple").select2({
placeholder: "Select or add tags",
tags: true,
tokenSeparators: [",", " "],
createSearchChoice:function(term, data) {
if ( $(data).filter( function() {
return this.text.localeCompare(term)===0;
}).length===0)
{
return { id: term, text:term };
}
}
});
</script>
//...
//материал
$record = Linkedin_GroupLabel::find($id);
//...
//Сбрасываем связи с тегами
$record->tags()->detach();
$rtags = array();
foreach ($request->input('tags') as $tag){
//если значение элемента селекта число, значит это id
if (is_numeric($tag)){
$rtags[] = $tag;
}
else //в противном случае это новое значение
{
$new = Linkedin_Label::where('title','=',trim($tag))->first();
if (empty($new->id)){
$new = new Linkedin_Label();
}
$new->title = trim($tag);
$new->save();
$rtags[] = $new->id;
}
}
//аттачим айдишники между записями
$record->tags()->attach($rtags);
php -m
php -a
<?php
$url = file_get_contents('your-xml-file.xml');
//именно эти строчки и выравнивают всю кривость кодировки
$url = mb_convert_encoding($url, 'utf-8', mb_detect_encoding($string));
$url = mb_convert_encoding($url, 'html-entities', 'utf-8');
$dom = new DOMDocument();
$dom->loadHTML($url);
$page_content = $dom->saveHTML();
//...
public function render($request, Exception $e)
{
//customize 404 page
if ($this->isHttpException($e)) {
$statusCode = $e->getStatusCode();
switch ($statusCode) {
case '404':
//путь к файлу с HTML разметкой
return response()->view('front/notfound');
}
}
return parent::render($request, $e);
}
//...
#php artisan make:console XMLSitemap
Console command created successfully.
#php artisan make:middleware RedirectTrailingSlash
Middleware created successfully.
<?php namespace App\Http\Middleware;
use Closure;
use Illuminate\Support\Facades\Redirect;
use Illuminate\Support\Str;
class RedirectTrailingSlash {
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
if (preg_match('/.+\/$/', $request->getRequestUri()))
{
//в исходном коде использовалась другая функция редиректа, выбивало ошибку
return redirect(rtrim($request->getRequestUri(), '/'), 301);
}
return $next($request);
}
}
'front.trailingslash'=>'App\Http\Middleware\RedirectTrailingSlash',
//...
class BaseController extends Controller {
//...
public function __construct()
{
$this->middleware('front.trailingslash');
//...
}
//...
}
watch -n 2 gearadmin --status
watch -n 3 tail -10 /var/log/php-cli.log
dbpass="pass"
DATE_DIR=$(date +%Y-%m-%d-%H)
mkdir /home/nelex/MySQL_BKP/${DATE_DIR}
for dbname in `echo show databases| mysql -u root -p$dbpass`; do
echo "Dump $dbname..."
mysqldump -u root -p$dbpass $dbname > "~/MySQL_BKP/${DATE_DIR}/$dbname.sql"
mkdir ~/MySQL_BKP
chmod +x mysqlbackup.sh
#!/bin/bash
indir=$1
dblogin="root"
dbpass="pass"
postfix=".sql"
prefix="./"
cd $indir
for file in `find ./ -type f -name "*$postfix"`
do
table_tmp=${file%$postfix}
table_tmp=${table_tmp#$prefix}
table=${table_tmp,,}
mysql -u$dblogin -p$dbpass -e "create database $table default charset utf8"
mysql -u$dblogin -p$dbpass $table < $file
chmod +x mysqlbackup.sh
import_from_dir.sh ~/MySQL_BKP/2015-06-02-14
dpkg: unrecoverable fatal error, aborting:
files list file for package 'imagemagick-6.q16' is missing final newline
# mkdir /var/lib/dpkg/info/old
#mv /var/lib/dpkg/info/imagemagick-6.q16.* \ /var/lib/dpkg/info/old/
bash: /usr/bin/apt-get: cannot execute binary file: Exec format error
dpkg -i apt.deb
Unpacking libapt-pkg-dev:amd64 (1.0.9.10) over (1.0.9.7) ...
dpkg: dependency problems prevent configuration of libapt-pkg-dev:amd64:
libapt-pkg-dev:amd64 depends on libapt-pkg4.12 (= 1.0.9.10); however:
Version of libapt-pkg4.12:amd64 on system is 1.0.9.7.
libapt-pkg-dev:amd64 depends on libapt-inst1.5 (= 1.0.9.10); however:
Version of libapt-inst1.5:amd64 on system is 1.0.9.7.
dpkg: error processing package libapt-pkg-dev:amd64 (--install):
dependency problems - leaving unconfigured
Errors were encountered while processing:
libapt-pkg-dev:amd64
Table 'sources_template_fields_value' doesn't exist in engine
alter table sources_template_fields_value discard tablespace;
alter table sources_template_fields_value import tablespace;