问:
edit action similar to tutorial doesn't work
I followed the ZF3 tutorial and I'm quite satisfied, but I'm something missing with the edit action in my controller. the add action works fine while the edit action doesn't. Probably I don't see it by myself, so I post it here, asking for help, even if it is really basic.

My model is nearly the same as in the tutorial, here a part of it:

```<code>public function exchangeArray(array $data)
{
    $this->ProjectID= !empty($data['ProjectID']) ? $data['ProjectID'] : null;
    $this->CI_Number= !empty($data['CI_Number']) ? $data['CI_Number'] : null;
    $this->Description= !empty($data['Description']) ? $data['Description'] : null;
    $this->Projectname= !empty($data['Projectname']) ? $data['Projectname'] : null;
    $this->Shortcut= !empty($data['Shortcut']) ? $data['Shortcut'] : null;
    $this->Component_Class= !empty($data['Component_Class']) ? $data['Component_Class'] : null;
}

public function getArrayCopy()
{
//      echo var_dump(get_object_vars($this)
//              );

        //return get_object_vars($this);
        return [
                'ProjectID'     => $this->ProjectID,
                'CI_Number' => $this->CI_Number,
                'Description'  => $this->Description,
                'Projectname'     => $this->Projectname,
                'Shortcut' => $this->Shortcut,
                'Component_Class'  => $this->Component_Class,
        ];
    }
</code>```

and here also my controlleraction:

```<code>    public function editAction()
{
    $id = (int) $this->params()->fromRoute('id', 0);
    echo $id;
    if (0 === $id) {
        return $this->redirect()->toRoute('project', ['action' => 'add']);
    }
    else {
        try {
            $project = $this->projectTable->getProject($id);
        } catch (\Exception $e) {
            return $this->redirect()->toRoute('project', ['action' => 'index']);
        }
        $form = new ProjectForm();
        $form->bind($project);
        //$form->bind($project->current());
        $form->get('submit')->setAttribute('value', 'save changes');

        $request = $this->getRequest();
        $viewData = ['ProjectID' => $id, 'form' => $form];
        if (! $request->isPost()) {
            return $viewData;
        }
        $form->setInputFilter($project->getInputFilter());
        $form->setData($request->getPost());

        if (! $form->isValid()) {
            echo "nicht valide";
            return $viewData;
        }
        else{
        echo $project;
        $this->projectTable->saveProject($project);
        }
    }
    // Redirect to album list
//  return $this->redirect()->toRoute('project', ['action' => 'index']);
}
</code>```

here for completion reasons my view edit.phtml:

```<code>    <?php
$title = 'projects';
$this->headTitle($title);
?>
<h1><?= $this->escapeHtml($title) ?></h1>
<?php

// This provides a default CSS class and placeholder text for the artist element:

$ProjectID= $form->get('ProjectID');
$ProjectID->setAttribute('class', 'form-control');
$ProjectID->setAttribute('placeholder', 'ProjectID');

$Projectname= $form->get('Projectname');
$Projectname->setAttribute('class', 'form-control');
$Projectname->setAttribute('placeholder', 'Projectname');

$CI_Number= $form->get('CI_Number');
$CI_Number->setAttribute('class', 'form-control');
$CI_Number->setAttribute('placeholder', 'CI_number');

$Shortcut= $form->get('Shortcut');
$Shortcut->setAttribute('class', 'form-control');
$Shortcut->setAttribute('placeholder', 'Shortcut');

$Description= $form->get('Description');
$Description->setAttribute('class', 'form-control');
$Description->setAttribute('placeholder', 'Description');

$Component_Class= $form->get('Component_Class');
$Component_Class->setAttribute('class', 'form-control');
$Component_Class->setAttribute('placeholder', 'Component_Class');
// This provides CSS classes for the submit button:
$submit = $form->get('submit');
$submit->setAttribute('class', 'btn btn-primary');

//$form->setAttribute('action', $this->url('project', ['action' => 'edit',]));  //,'id'=> $id
$form->setAttribute('action', $this->url('project', [
    'action' => 'edit',
    'ProjectID'     => $id,
]));
$form->prepare();

echo $this->form()->openTag($form);
?>
<?php // Wrap the elements in divs marked as form groups, and render the
      // label, element, and errors separately within ?>

<div class="form-group">

    <?= $this->formElement($ProjectID) ?>
    <?= $this->formElementErrors()->render($ProjectID, ['class' => 'help-block']) ?>
</div>

<div class="form-group">
    <?= $this->formLabel($CI_Number) ?>
    <?= $this->formElement($CI_Number) ?>
    <?= $this->formElementErrors()->render($CI_Number, ['class' => 'help-block']) ?>
</div>
<div class="form-group">
    <?= $this->formLabel($Description) ?>
    <?= $this->formElement($Description) ?>
    <?= $this->formElementErrors()->render($Description, ['class' => 'help-block']) ?>
</div>
<div class="form-group">
    <?= $this->formLabel($Projectname) ?>
    <?= $this->formElement($Projectname) ?>
    <?= $this->formElementErrors()->render($Projectname, ['class' => 'help-block']) ?>
</div>
<div class="form-group">
    <?= $this->formLabel($Shortcut) ?>
    <?= $this->formElement($Shortcut) ?>
    <?= $this->formElementErrors()->render($Shortcut, ['class' => 'help-block']) ?>
</div>
<div class="form-group">
    <?= $this->formLabel($Component_Class) ?>
    <?= $this->formElement($Component_Class) ?>
    <?= $this->formElementErrors()->render($Component_Class, ['class' => 'help-block']) ?>
</div>

<?php
echo $this->formSubmit($submit);
//echo $this->form->get('DCLID');
echo $this->formHidden($form->get('ProjectID'));
echo $this->form()->closeTag();
</code>```

It will show the recordset properly, but won't save the changes to the database and afterwards redirects to my add action. I hope somebody sees what I'm missing, even it might be a stupid error.

EDIT1: Here is my routing link from index.phtml

```<code>  <a href="<?= $this->url('project', ['action' => 'edit', 'id' => $project->ProjectID]) ?>">Edit</a>
</code>```

EDIT2: Screenshot to show the routing parameter

EDIT3: describing test issues

here again my controller edit action, to follow up:

```<code>public function editAction()
{
    $id = (int) $this->params()->fromRoute('id', 0);
    echo "variable id: ". $id;
    if (0 === $id) {
        //return $this->redirect()->toRoute('project', ['action' => 'index']);
        echo "id = 0";
    }
    else {
        try {
            $project = $this->projectTable->getProject($id);
        } catch (\Exception $e) {
            return $this->redirect()->toRoute('project', ['action' => 'index']);
        }
        $form = new ProjectForm();
        $form->bind($project);
        //$form->bind($project->current());
        $form->get('submit')->setAttribute('value', 'save changes');
        var_dump(get_object_vars($project));
        $request = $this->getRequest();
        $viewData = ['ProjectID' => $id, 'form' => $form];
        if (!$request->isPost()) {
            return $viewData;
        }
        else {

            $form->setInputFilter($project->getInputFilter());
            $form->setData($request->getPost());

            if (!$form->isValid()) {
                echo "nicht valide";
                return $viewData;
            }
            else{
                echo "valide";
                echo $project;
                $this->projectTable->saveProject($project);
            }
        }
    }
    // Redirect to album list
//  return $this->redirect()->toRoute('project', ['action' => 'index']);
}
</code>```

I get the output of the vardump, so the project to edit will be delivered correctly. If I send the form with the recordchanges the controller won't catch it, the controller action sees id=0 then, so the method saveProject will be never called. In my understanding it might has to do with the formvalid something, because after sending the data I come never further than if (0 === $id).

EDIT 4: After some actual tests I think it must be a routing issue. If I give the route manually via browser, I won't get the target page at all. If I dump the value, it is always NULL. So I think it could be a bracket to much/to less issue in my module.config.php I show it here because I couldn't finde the problem, I countedt the braskets several times and I won't get it. So any help is appreciated, it must be a very simple topic:

```<code>    <?php
namespace Import;

use Zend\Router\Http\Segment;
use Zend\Router\Http\Literal;
use Zend\ServiceManager\Factory\InvokableFactory;

//use Zend\ServiceManager\Factory\InvokableFactory;

return [
        /* 'controllers' => [
                'factories' => [
                        Controller\ImportController::class => InvokableFactory::class,
                ],
        ], */

        // hier die Einstellungen für die Routen
        'router' => [
                'routes' => [
                        'index' => [
                                'type'    => Segment::class,
                                'options' => [
                                        'route' => '/import[/:action[/:id]]',
                                        'constraints' => [
                                                'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
                                                'id'     => '[0-9]+',
                                                        ],
                                        'defaults' => [
                                                'controller' => Controller\IndexController::class,
                                                'action'     => 'index',
                                                        ],
                                            ],
                                    ],

                        'import' => [
                                'type'    => Segment::class,
                                'options' => [
                                        'route' => '/import[/:action[/:id]]',
                                        'constraints' => [
                                                'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
                                                'id'     => '[0-9]+',
                                        ],
                                        'defaults' => [
                                                'controller' => Controller\ImportController::class,
                                                'action'     => 'index',
                                        ],
                                ],
                        ],

                        'importdcl' => [
                                'type'    => Segment::class,
                                'options' => [
                                        'route' => '/importdcl[/:action[/:id]]',
                                        'constraints' => [
                                                'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
                                                'id'     => '[0-9]+',
                                        ],
                                        'defaults' => [
                                                'controller' => Controller\ImportdclController::class,
                                                'action'     => 'index',
                                        ],
                                ],
                        ],

                        'project' => [
                                'type'    => Segment::class,
                                'options' => [
                                        'route' => '/project[/:action[/:id]]',
                                        'constraints' => [
                                                'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
                                                'id'     => '[0-9]+',
                                        ],
                                        'defaults' => [
                                                'controller' => Controller\ProjectController::class,
                                                'action'     => 'index',
                                        ],
                                ],
                        ],
                        'unit' => [
                                'type'    => Segment::class,
                                'options' => [
                                        'route' => '/unit[/:action[/:id]]',
                                        'constraints' => [
                                                'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
                                                'id'     => '[0-9]+',
                                        ],
                                        'defaults' => [
                                                'controller' => Controller\UnitController::class,
                                                'action'     => 'index',
                                        ],
                                ],
                        ],

                        'index' => [
                                'type'    => Segment::class,
                                'options' => [
                                        'route' => '/index[/:action[/:id]]',
                                        'constraints' => [
                                                'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
                                                'id'     => '[0-9]+',
                                        ],
                                        'defaults' => [
                                                'controller' => Controller\IndexController::class,
                                                'action'     => 'index',
                                        ],
                                ],
                        ],
                        'user' => [
                                'type'    => Segment::class,
                                'options' => [
                                        'route' => '/user[/:action[/:id]]',
                                        'constraints' => [
                                                'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
                                                'id'     => '[0-9]+',
                                        ],
                                        'defaults' => [
                                                'controller' => Controller\UserController::class,
                                                'action'     => 'index',
                                        ],
                                ],
                        ],
                        'followup' => [
                                'type'    => Segment::class,
                                'options' => [
                                        'route' => '/followup[/:action[/:id]]',
                                        'constraints' => [
                                                'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
                                                'id'     => '[0-9]+',
                                        ],
                                        'defaults' => [
                                                'controller' => Controller\FollowupController::class,
                                                'action'     => 'index',
                                        ],
                                ],
                        ],
                ],
        ],

        'view_manager' => [
                'template_path_stack' => [
                        'import' => __DIR__ . '/../view',
                ],
        ],

            /* ... */

        'navigation' => [
                        'default' => [
                                [
                                        'label' => 'Dashboard',
                                        'route' => 'home',

                                ],
                                [
                                        'label' => 'Project',
                                        'route' => 'project',
                                        'pages' => [
                                                [
                                                        'label'  => 'Add',
                                                        'route'  => 'project',
                                                        'action' => 'add',
                                                ],
                                                [
                                                        'label'  => 'Edit',
                                                        'route'  => 'project',
                                                        'action' => 'edit',
                                                ],
                                                [
                                                        'label'  => 'Delete',
                                                        'route'  => 'project',
                                                        'action' => 'delete',
                                                ],
                                        ],
                                ],
                                [
                                        'label' => 'Unit',
                                        'route' => 'unit',
                                        'pages' => [
                                                [
                                                        'label'  => 'Add',
                                                        'route'  => 'unit',
                                                        'action' => 'add',
                                                ],
                                                [
                                                        'label'  => 'Edit',
                                                        'route'  => 'unit',
                                                        'action' => 'edit',
                                                ],
                                                [
                                                        'label'  => 'Delete',
                                                        'route'  => 'unit',
                                                        'action' => 'delete',
                                                ],
                                        ],
                                ],
                                [
                                        'label' => 'Importlog',
                                        'route' => 'importdcl',
                                        'action' => 'index',
                                        'pages' => [
                                                [
                                                        'label'  => 'Add',
                                                        'route'  => 'unit',
                                                        'action' => 'add',
                                                ],
                                                [
                                                        'label'  => 'Edit',
                                                        'route'  => 'unit',
                                                        'action' => 'edit',
                                                ],
                                                [
                                                        'label'  => 'Delete',
                                                        'route'  => 'unit',
                                                        'action' => 'delete',
                                                ],
                                        ],
                                ],

                                [
                                        'label' => 'Follow up',
                                        'route' => 'followup',
                                        'action' => 'index',
                                        'pages' => [
                                                [
                                                        'label'  => 'Add',
                                                        'route'  => 'unit',
                                                        'action' => 'add',
                                                ],
                                                [
                                                        'label'  => 'Edit',
                                                        'route'  => 'unit',
                                                        'action' => 'edit',
                                                ],
                                                [
                                                        'label'  => 'Delete',
                                                        'route'  => 'unit',
                                                        'action' => 'delete',
                                                ],
                                        ],
                                ],

                                [
                                        'label' => 'User',
                                        'route' => 'user',
                                        'pages' => [
                                                [
                                                        'label'  => 'Add',
                                                        'route'  => 'unit',
                                                        'action' => 'add',
                                                ],
                                                [
                                                        'label'  => 'Edit',
                                                        'route'  => 'unit',
                                                        'action' => 'edit',
                                                ],
                                                [
                                                        'label'  => 'Delete',
                                                        'route'  => 'unit',
                                                        'action' => 'delete',
                                                ],
                                        ],
                                ],

                                [
                                        'label' => 'Logout',
                                        'route' => 'user',
                                        'action' => 'logout',
                                        'pages' => [
                                                [
                                                        'label'  => 'Add',
                                                        'route'  => 'unit',
                                                        'action' => 'add',
                                                ],
                                                [
                                                        'label'  => 'Edit',
                                                        'route'  => 'unit',
                                                        'action' => 'edit',
                                                ],
                                                [
                                                        'label'  => 'Delete',
                                                        'route'  => 'unit',
                                                        'action' => 'delete',
                                                ],
                                        ],
                                ],

                        ],
                ],

        /* ... */

];
</code>```

I'm testing in the usercontroller at the moment, but I have had the same problem in others routes, so I think the error might be in this file.

答:
I at last solved it. My suggestion was right, it was a problem with the module.config.php, I have set an endbracket at the wrong place.

After writing it in parts new, tsting and complete the file, it now works.

Body:
I followed the ZF3 tutorial and I'm quite satisfied, but I'm something missing with the edit action in my controller. the add action works fine while the edit action doesn't. Probably I don't see it by myself, so I post it here, asking for help, even if it is really basic.

My model is nearly the same as in the tutorial, here a part of it:

public function exchangeArray(array $data)
{
    $this->ProjectID= !empty($data['ProjectID']) ? $data['ProjectID'] : null;
    $this->CI_Number= !empty($data['CI_Number']) ? $data['CI_Number'] : null;
    $this->Description= !empty($data['Description']) ? $data['Description'] : null;
    $this->Projectname= !empty($data['Projectname']) ? $data['Projectname'] : null;
    $this->Shortcut= !empty($data['Shortcut']) ? $data['Shortcut'] : null;
    $this->Component_Class= !empty($data['Component_Class']) ? $data['Component_Class'] : null;
}

public function getArrayCopy()
{
//      echo var_dump(get_object_vars($this)
//              );

        //return get_object_vars($this);
        return [
                'ProjectID'     => $this->ProjectID,
                'CI_Number' => $this->CI_Number,
                'Description'  => $this->Description,
                'Projectname'     => $this->Projectname,
                'Shortcut' => $this->Shortcut,
                'Component_Class'  => $this->Component_Class,
        ];
    }

and here also my controlleraction:

    public function editAction()
{
    $id = (int) $this->params()->fromRoute('id', 0);
    echo $id;
    if (0 === $id) {
        return $this->redirect()->toRoute('project', ['action' => 'add']);
    }
    else {
        try {
            $project = $this->projectTable->getProject($id);
        } catch (\Exception $e) {
            return $this->redirect()->toRoute('project', ['action' => 'index']);
        }
        $form = new ProjectForm();
        $form->bind($project);
        //$form->bind($project->current());
        $form->get('submit')->setAttribute('value', 'save changes');

        $request = $this->getRequest();
        $viewData = ['ProjectID' => $id, 'form' => $form];
        if (! $request->isPost()) {
            return $viewData;
        }
        $form->setInputFilter($project->getInputFilter());
        $form->setData($request->getPost());

        if (! $form->isValid()) {
            echo "nicht valide";
            return $viewData;
        }
        else{
        echo $project;
        $this->projectTable->saveProject($project);
        }
    }
    // Redirect to album list
//  return $this->redirect()->toRoute('project', ['action' => 'index']);
}

here for completion reasons my view edit.phtml:

    <?php
$title = 'projects';
$this->headTitle($title);
?>

<?= $this->escapeHtml($title) ?>

<?php

// This provides a default CSS class and placeholder text for the artist element:

$ProjectID= $form->get('ProjectID');
$ProjectID->setAttribute('class', 'form-control');
$ProjectID->setAttribute('placeholder', 'ProjectID');

$Projectname= $form->get('Projectname');
$Projectname->setAttribute('class', 'form-control');
$Projectname->setAttribute('placeholder', 'Projectname');

$CI_Number= $form->get('CI_Number');
$CI_Number->setAttribute('class', 'form-control');
$CI_Number->setAttribute('placeholder', 'CI_number');

$Shortcut= $form->get('Shortcut');
$Shortcut->setAttribute('class', 'form-control');
$Shortcut->setAttribute('placeholder', 'Shortcut');

$Description= $form->get('Description');
$Description->setAttribute('class', 'form-control');
$Description->setAttribute('placeholder', 'Description');

$Component_Class= $form->get('Component_Class');
$Component_Class->setAttribute('class', 'form-control');
$Component_Class->setAttribute('placeholder', 'Component_Class');
// This provides CSS classes for the submit button:
$submit = $form->get('submit');
$submit->setAttribute('class', 'btn btn-primary');

//$form->setAttribute('action', $this->url('project', ['action' => 'edit',]));  //,'id'=> $id
$form->setAttribute('action', $this->url('project', [
    'action' => 'edit',
    'ProjectID'     => $id,
]));
$form->prepare();

echo $this->form()->openTag($form);
?>
<?php // Wrap the elements in divs marked as form groups, and render the
      // label, element, and errors separately within ?>

    <?= $this->formElement($ProjectID) ?>
    <?= $this->formElementErrors()->render($ProjectID, ['class' => 'help-block']) ?>

    <?= $this->formLabel($CI_Number) ?>
    <?= $this->formElement($CI_Number) ?>
    <?= $this->formElementErrors()->render($CI_Number, ['class' => 'help-block']) ?>

    <?= $this->formLabel($Description) ?>
    <?= $this->formElement($Description) ?>
    <?= $this->formElementErrors()->render($Description, ['class' => 'help-block']) ?>

    <?= $this->formLabel($Projectname) ?>
    <?= $this->formElement($Projectname) ?>
    <?= $this->formElementErrors()->render($Projectname, ['class' => 'help-block']) ?>

    <?= $this->formLabel($Shortcut) ?>
    <?= $this->formElement($Shortcut) ?>
    <?= $this->formElementErrors()->render($Shortcut, ['class' => 'help-block']) ?>

    <?= $this->formLabel($Component_Class) ?>
    <?= $this->formElement($Component_Class) ?>
    <?= $this->formElementErrors()->render($Component_Class, ['class' => 'help-block']) ?>

<?php
echo $this->formSubmit($submit);
//echo $this->form->get('DCLID');
echo $this->formHidden($form->get('ProjectID'));
echo $this->form()->closeTag();

It will show the recordset properly, but won't save the changes to the database and afterwards redirects to my add action. I hope somebody sees what I'm missing, even it might be a stupid error.

EDIT1: Here is my routing link from index.phtml

  <a href="<?= $this->url('project', ['action' => 'edit', 'id' => $project->ProjectID]) ?>">Edit

EDIT2: Screenshot to show the routing parameter

EDIT3: describing test issues

here again my controller edit action, to follow up:

public function editAction()
{
    $id = (int) $this->params()->fromRoute('id', 0);
    echo "variable id: ". $id;
    if (0 === $id) {
        //return $this->redirect()->toRoute('project', ['action' => 'index']);
        echo "id = 0";
    }
    else {
        try {
            $project = $this->projectTable->getProject($id);
        } catch (\Exception $e) {
            return $this->redirect()->toRoute('project', ['action' => 'index']);
        }
        $form = new ProjectForm();
        $form->bind($project);
        //$form->bind($project->current());
        $form->get('submit')->setAttribute('value', 'save changes');
        var_dump(get_object_vars($project));
        $request = $this->getRequest();
        $viewData = ['ProjectID' => $id, 'form' => $form];
        if (!$request->isPost()) {
            return $viewData;
        }
        else {

            $form->setInputFilter($project->getInputFilter());
            $form->setData($request->getPost());

            if (!$form->isValid()) {
                echo "nicht valide";
                return $viewData;
            }
            else{
                echo "valide";
                echo $project;
                $this->projectTable->saveProject($project);
            }
        }
    }
    // Redirect to album list
//  return $this->redirect()->toRoute('project', ['action' => 'index']);
}

I get the output of the vardump, so the project to edit will be delivered correctly. If I send the form with the recordchanges the controller won't catch it, the controller action sees id=0 then, so the method saveProject will be never called. In my understanding it might has to do with the formvalid something, because after sending the data I come never further than if (0 === $id).

EDIT 4: After some actual tests I think it must be a routing issue. If I give the route manually via browser, I won't get the target page at all. If I dump the value, it is always NULL. So I think it could be a bracket to much/to less issue in my module.config.php I show it here because I couldn't finde the problem, I countedt the braskets several times and I won't get it. So any help is appreciated, it must be a very simple topic:

    <?php
namespace Import;

use Zend\Router\Http\Segment;
use Zend\Router\Http\Literal;
use Zend\ServiceManager\Factory\InvokableFactory;

//use Zend\ServiceManager\Factory\InvokableFactory;

return [
        /* 'controllers' => [
                'factories' => [
                        Controller\ImportController::class => InvokableFactory::class,
                ],
        ], */

        // hier die Einstellungen für die Routen
        'router' => [
                'routes' => [
                        'index' => [
                                'type'    => Segment::class,
                                'options' => [
                                        'route' => '/import[/:action[/:id]]',
                                        'constraints' => [
                                                'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
                                                'id'     => '[0-9]+',
                                                        ],
                                        'defaults' => [
                                                'controller' => Controller\IndexController::class,
                                                'action'     => 'index',
                                                        ],
                                            ],
                                    ],

                        'import' => [
                                'type'    => Segment::class,
                                'options' => [
                                        'route' => '/import[/:action[/:id]]',
                                        'constraints' => [
                                                'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
                                                'id'     => '[0-9]+',
                                        ],
                                        'defaults' => [
                                                'controller' => Controller\ImportController::class,
                                                'action'     => 'index',
                                        ],
                                ],
                        ],

                        'importdcl' => [
                                'type'    => Segment::class,
                                'options' => [
                                        'route' => '/importdcl[/:action[/:id]]',
                                        'constraints' => [
                                                'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
                                                'id'     => '[0-9]+',
                                        ],
                                        'defaults' => [
                                                'controller' => Controller\ImportdclController::class,
                                                'action'     => 'index',
                                        ],
                                ],
                        ],

                        'project' => [
                                'type'    => Segment::class,
                                'options' => [
                                        'route' => '/project[/:action[/:id]]',
                                        'constraints' => [
                                                'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
                                                'id'     => '[0-9]+',
                                        ],
                                        'defaults' => [
                                                'controller' => Controller\ProjectController::class,
                                                'action'     => 'index',
                                        ],
                                ],
                        ],
                        'unit' => [
                                'type'    => Segment::class,
                                'options' => [
                                        'route' => '/unit[/:action[/:id]]',
                                        'constraints' => [
                                                'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
                                                'id'     => '[0-9]+',
                                        ],
                                        'defaults' => [
                                                'controller' => Controller\UnitController::class,
                                                'action'     => 'index',
                                        ],
                                ],
                        ],

                        'index' => [
                                'type'    => Segment::class,
                                'options' => [
                                        'route' => '/index[/:action[/:id]]',
                                        'constraints' => [
                                                'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
                                                'id'     => '[0-9]+',
                                        ],
                                        'defaults' => [
                                                'controller' => Controller\IndexController::class,
                                                'action'     => 'index',
                                        ],
                                ],
                        ],
                        'user' => [
                                'type'    => Segment::class,
                                'options' => [
                                        'route' => '/user[/:action[/:id]]',
                                        'constraints' => [
                                                'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
                                                'id'     => '[0-9]+',
                                        ],
                                        'defaults' => [
                                                'controller' => Controller\UserController::class,
                                                'action'     => 'index',
                                        ],
                                ],
                        ],
                        'followup' => [
                                'type'    => Segment::class,
                                'options' => [
                                        'route' => '/followup[/:action[/:id]]',
                                        'constraints' => [
                                                'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
                                                'id'     => '[0-9]+',
                                        ],
                                        'defaults' => [
                                                'controller' => Controller\FollowupController::class,
                                                'action'     => 'index',
                                        ],
                                ],
                        ],
                ],
        ],

        'view_manager' => [
                'template_path_stack' => [
                        'import' => __DIR__ . '/../view',
                ],
        ],

            /* ... */

        'navigation' => [
                        'default' => [
                                [
                                        'label' => 'Dashboard',
                                        'route' => 'home',

                                ],
                                [
                                        'label' => 'Project',
                                        'route' => 'project',
                                        'pages' => [
                                                [
                                                        'label'  => 'Add',
                                                        'route'  => 'project',
                                                        'action' => 'add',
                                                ],
                                                [
                                                        'label'  => 'Edit',
                                                        'route'  => 'project',
                                                        'action' => 'edit',
                                                ],
                                                [
                                                        'label'  => 'Delete',
                                                        'route'  => 'project',
                                                        'action' => 'delete',
                                                ],
                                        ],
                                ],
                                [
                                        'label' => 'Unit',
                                        'route' => 'unit',
                                        'pages' => [
                                                [
                                                        'label'  => 'Add',
                                                        'route'  => 'unit',
                                                        'action' => 'add',
                                                ],
                                                [
                                                        'label'  => 'Edit',
                                                        'route'  => 'unit',
                                                        'action' => 'edit',
                                                ],
                                                [
                                                        'label'  => 'Delete',
                                                        'route'  => 'unit',
                                                        'action' => 'delete',
                                                ],
                                        ],
                                ],
                                [
                                        'label' => 'Importlog',
                                        'route' => 'importdcl',
                                        'action' => 'index',
                                        'pages' => [
                                                [
                                                        'label'  => 'Add',
                                                        'route'  => 'unit',
                                                        'action' => 'add',
                                                ],
                                                [
                                                        'label'  => 'Edit',
                                                        'route'  => 'unit',
                                                        'action' => 'edit',
                                                ],
                                                [
                                                        'label'  => 'Delete',
                                                        'route'  => 'unit',
                                                        'action' => 'delete',
                                                ],
                                        ],
                                ],

                                [
                                        'label' => 'Follow up',
                                        'route' => 'followup',
                                        'action' => 'index',
                                        'pages' => [
                                                [
                                                        'label'  => 'Add',
                                                        'route'  => 'unit',
                                                        'action' => 'add',
                                                ],
                                                [
                                                        'label'  => 'Edit',
                                                        'route'  => 'unit',
                                                        'action' => 'edit',
                                                ],
                                                [
                                                        'label'  => 'Delete',
                                                        'route'  => 'unit',
                                                        'action' => 'delete',
                                                ],
                                        ],
                                ],

                                [
                                        'label' => 'User',
                                        'route' => 'user',
                                        'pages' => [
                                                [
                                                        'label'  => 'Add',
                                                        'route'  => 'unit',
                                                        'action' => 'add',
                                                ],
                                                [
                                                        'label'  => 'Edit',
                                                        'route'  => 'unit',
                                                        'action' => 'edit',
                                                ],
                                                [
                                                        'label'  => 'Delete',
                                                        'route'  => 'unit',
                                                        'action' => 'delete',
                                                ],
                                        ],
                                ],

                                [
                                        'label' => 'Logout',
                                        'route' => 'user',
                                        'action' => 'logout',
                                        'pages' => [
                                                [
                                                        'label'  => 'Add',
                                                        'route'  => 'unit',
                                                        'action' => 'add',
                                                ],
                                                [
                                                        'label'  => 'Edit',
                                                        'route'  => 'unit',
                                                        'action' => 'edit',
                                                ],
                                                [
                                                        'label'  => 'Delete',
                                                        'route'  => 'unit',
                                                        'action' => 'delete',
                                                ],
                                        ],
                                ],

                        ],
                ],

        /* ... */

];

I'm testing in the usercontroller at the moment, but I have had the same problem in others routes, so I think the error might be in this file.


来源: stackexchange

问:
How to parallelize do while and while loop in openmp?
I'm trying to learn parallel programming with OpenMP and I'm interested in parallelizing the following do while loop with several while loop inside it:

```<code>do {
        while(left < (length - 1) && data[left] <= pivot) left++;
        while(right > 0 && data[right] >= pivot) right--;

        /* swap elements */
        if(left < right){
            temp = data[left];
            data[left] = data[right];
            data[right] = temp;
        }

    } while(left < right);
</code>```

I haven't actually figured out how to parallelize while and do while loops, couldn't find any resource where it specifically describes how to parallelize while and do while loops. I have found instructions for for loops, but I couldn't make any assumption for while and do while loops from that. So, could you please describe how I can parallelize this loops that I provided here?

EDIT

I have transformed the do while loop to the following code where only for loop is used.

```<code>for(i = 1; i<length-1; i++)
{
    if(data[left] > pivot)
    {
        i = length;
    }
    else
    {
        left = i;
    }

}

for(j=length-1; j > 0; j--)
{
    if(data[right] < pivot)
    {
        j = 0;
    }
    else
    {
        right = j;
    }
}

/* swap elements */
if(left < right)
{
    temp = data[left];
    data[left] = data[right];
    data[right] = temp;
}

int leftCopy = left;
int rightCopy = right;

for(int leftCopy = left; leftCopy<right;leftCopy++)
{
    for(int new_i = left; new_i<length-1; new_i++)
    {
        if(data[left] > pivot)
        {
            new_i = length;
        }
        else
        {
            left = new_i;
        }
    }

    for(int new_j=right; new_j > 0; new_j--)
    {
        if(data[right] < pivot)
        {
            new_j = 0;
        }
        else
        {
            right = new_j;
        }
    }
    leftCopy = left;
    /* swap elements */
    if(left < right)
    {
        temp = data[left];
        data[left] = data[right];
        data[right] = temp;
    }
}
</code>```

This code works fine and produces correct result, but when I tried to parallelize the parts of above stated code, by changing the first two for loops to the following:

```<code>#pragma omp parallel default(none) firstprivate(left) private(i,tid) shared(length, pivot, data)
    {
#pragma omp for
        for(i = 1; i<length-1; i++)
        {
            if(data[left] > pivot)
            {
                i = length;
            }
            else
            {
                left = i;
            }
        }
    }

#pragma omp parallel default(none) firstprivate(right) private(j) shared(length, pivot, data)
    {
#pragma omp for
        for(j=length-1; j > 0; j--)
        {
            if(data[right] < pivot)
            {
                j = 0;
            }
            else
            {
                right = j;
            }
        }
    }
</code>```

The speed is worse than the non-parallelized code. Please help me identify my problem.

Thanks

答:
First of all, sorting algorithms are very hard to parallelize with OpenMP parallel loops. This is because the loop trip count is not deterministic but depends on the input set values that are read every iteration.

I don't think having loop conditions such as data[left] <= pivot is going to work well, since OpenMP library does not know exactly how to partition the iteration space among the threads.

If you are still interested in parallel sorting algorithms, I suggest you to read the literature first, to see those algorithms that really worth implementing due to their scalability. If you just want to learn OpenMP, I suggest you start with easier algorithms such as bucket-sort, where the number of buckets is well known and does not frequently change.

Regarding the example you try to parallelize, while loops are not directly supported by OpenMP because the number of iterations (loop trip count) is not deterministic (otherwise, it is easy to transform them into for loops). Therefore, it is not possible to distribute the iterations among the threads. In addition, it is common for while loops to check for a condition using last iteration's result. This is called Read-after-Write or true-dependency and cannot be parallelized.

Your slowdown problem might be alleviated if you try to minimize the number of omp parallel clauses. In addition, try to move them out of all your loops. These clauses may create and join the additional threads that are used in the parallel parts of the code, which is expensive.

You can still synchronize threads inside parallel blocks, so that the outcome is similar. In fact, all threads wait for each other at the end of a omp for clause by default, so that this makes things even easier.

```<code>#pragma omp parallel default(none) firstprivate(right,left) private(i,j) shared(length, pivot, data)
{
    #pragma omp for
    for(i = 1; i<length-1; i++)
    {
        if(data[left] > pivot)
        {
            i = length;
        }
        else
        {
            left = i;
        }
    }

    #pragma omp for
    for(j=length-1; j > 0; j--)
    {
        if(data[right] < pivot)
        {
            j = 0;
        }
        else
        {
            right = j;
        }
    }
} // end omp parallel
</code>```

ContentLicense: CC BY-SA 3.0

Body:
I'm trying to learn parallel programming with OpenMP and I'm interested in parallelizing the following do while loop with several while loop inside it:

do {
        while(left < (length - 1) && data[left] <= pivot) left++;
        while(right > 0 && data[right] >= pivot) right--;

        /* swap elements */
        if(left < right){
            temp = data[left];
            data[left] = data[right];
            data[right] = temp;
        }

    } while(left < right);

I haven't actually figured out how to parallelize while and do while loops, couldn't find any resource where it specifically describes how to parallelize while and do while loops. I have found instructions for for loops, but I couldn't make any assumption for while and do while loops from that. So, could you please describe how I can parallelize this loops that I provided here?

EDIT

I have transformed the do while loop to the following code where only for loop is used.

for(i = 1; i<length-1; i++)
{
    if(data[left] > pivot)
    {
        i = length;
    }
    else
    {
        left = i;
    }

}

for(j=length-1; j > 0; j--)
{
    if(data[right] < pivot)
    {
        j = 0;
    }
    else
    {
        right = j;
    }
}

/* swap elements */
if(left < right)
{
    temp = data[left];
    data[left] = data[right];
    data[right] = temp;
}

int leftCopy = left;
int rightCopy = right;

for(int leftCopy = left; leftCopy<right;leftCopy++)
{
    for(int new_i = left; new_i<length-1; new_i++)
    {
        if(data[left] > pivot)
        {
            new_i = length;
        }
        else
        {
            left = new_i;
        }
    }

    for(int new_j=right; new_j > 0; new_j--)
    {
        if(data[right] < pivot)
        {
            new_j = 0;
        }
        else
        {
            right = new_j;
        }
    }
    leftCopy = left;
    /* swap elements */
    if(left < right)
    {
        temp = data[left];
        data[left] = data[right];
        data[right] = temp;
    }
}

This code works fine and produces correct result, but when I tried to parallelize the parts of above stated code, by changing the first two for loops to the following:

#pragma omp parallel default(none) firstprivate(left) private(i,tid) shared(length, pivot, data)
    {
#pragma omp for
        for(i = 1; i<length-1; i++)
        {
            if(data[left] > pivot)
            {
                i = length;
            }
            else
            {
                left = i;
            }
        }
    }

#pragma omp parallel default(none) firstprivate(right) private(j) shared(length, pivot, data)
    {
#pragma omp for
        for(j=length-1; j > 0; j--)
        {
            if(data[right] < pivot)
            {
                j = 0;
            }
            else
            {
                right = j;
            }
        }
    }

The speed is worse than the non-parallelized code. Please help me identify my problem.

Thanks

Body:
First of all, sorting algorithms are very hard to parallelize with OpenMP parallel loops. This is because the loop trip count is not deterministic but depends on the input set values that are read every iteration.

I don't think having loop conditions such as data[left] <= pivot is going to work well, since OpenMP library does not know exactly how to partition the iteration space among the threads.

If you are still interested in parallel sorting algorithms, I suggest you to read the literature first, to see those algorithms that really worth implementing due to their scalability. If you just want to learn OpenMP, I suggest you start with easier algorithms such as bucket-sort, where the number of buckets is well known and does not frequently change.

Regarding the example you try to parallelize, while loops are not directly supported by OpenMP because the number of iterations (loop trip count) is not deterministic (otherwise, it is easy to transform them into for loops). Therefore, it is not possible to distribute the iterations among the threads. In addition, it is common for while loops to check for a condition using last iteration's result. This is called Read-after-Write or true-dependency and cannot be parallelized.

Your slowdown problem might be alleviated if you try to minimize the number of omp parallel clauses. In addition, try to move them out of all your loops. These clauses may create and join the additional threads that are used in the parallel parts of the code, which is expensive.

You can still synchronize threads inside parallel blocks, so that the outcome is similar. In fact, all threads wait for each other at the end of a omp for clause by default, so that this makes things even easier.

#pragma omp parallel default(none) firstprivate(right,left) private(i,j) shared(length, pivot, data)
{
    #pragma omp for
    for(i = 1; i<length-1; i++)
    {
        if(data[left] > pivot)
        {
            i = length;
        }
        else
        {
            left = i;
        }
    }

    #pragma omp for
    for(j=length-1; j > 0; j--)
    {
        if(data[right] < pivot)
        {
            j = 0;
        }
        else
        {
            right = j;
        }
    }
} // end omp parallel


问:
JAVAME: Sort Java Vector
What would be the best and most efficient way to sort a Java Vector in JAVAME.

My object has five properties, and I would like to sort by a property called price which is of type double. In my Vector I will have a maximum of 150 items. A sample code would be appreciated.

Thanx for your time.

答: Use Collections.sort(List<T> vector, Comparator<T> c) method. If there is no such method in Java ME, just copy it from Java SE. It uses merge sort algorithm, so it will not be much to copy.</p>

ContentLicense: CC BY-SA 2.5

Title: JAVAME: Sort Java Vector


问:
In RAML, what response type (mediaType) can RAML NOT accommodate?
In the mulesoft training quiz, I came across the question
**

In RAML, what response type (mediaType) can RAML NOT accommodate?

**
The correct answer is application/text.

To verify, I edited the RAML 0.8 spec, change the response MediaType to application/text, added few Inline text lines as the output, and simulated it.
I can simulate and see the output in application/text. No errors. Why is that RAML cannot accomodate MediaType application/text ?.

答:
Dude you can't ask questions straight out of certification exams.  Rephrase your question so that is does not include the question and answer.

Now to answer your question: RAML is for specifying RESTful APIs, IMHO you gain little by returning straight text from such an API.  You can still return "text" by wrapping the text inside JSON or XML.


问:
Unable to load div using ajax
I am using a select box to navigate to a new page but the table div data will be received from another data based on the select box. Here is my code

html page

```<code><select id="works" class="btn btn-default" style="text-align:left; background-color:#FFF" onchange="getboq(this)">
<option value=""> Select Work Name</option>
<option value="1" style="text-align:left"><?= 1 ?>
<option value="2" style="text-align:left"><?= 2 ?>
</option>
</select>
</code>```

Js file

```<code>function getboq(work)
{
var boq = work.value;
$.ajax({
            url: 'data/cont_boq.php',
            type: 'post',
            dataType: 'json',
            data: {
                boq:boq,
            },
            success: function (data) {
            window.location = 'boq.php'
                $('#boq').html(data);
            },
            error: function(){
                alert('error');
            }
        });
}
</code>```

Cont.php

Its a normal table based on select box value, How ever even i made a simple table as well to check if it works but my efforts bore no fruit

boq.php

is a simple php page having the required div

```<code><div id="boq"></div>
</code>```

Interestingly i can see the response on firebug but getting alert "error"

答:
try this code

PHP and Script Code

add letest .js library:letest .js library

```<code><select id="works" class="btn btn-default" style="text-align:left; background-color:#FFF">
<option value=""> Select Work Name</option>
<option value="1" style="text-align:left"><?=1?>
<option value="2" style="text-align:left"><?=2?>
</option>
</select>
<div id="boq"></div>
<script type="text/javascript" src='.js library path'></script>
<script type="text/javascript">
$(document).ready(function(){
    $('select').change(function(){
            var boq = $('select option:selected').val();
            $.ajax({
                url: 'data/cont_boq.php',
                //url: 'cont_boq.php',
                type: 'post',
                data: {boq:boq},
                success: function (data) {
                   $('#boq').html(data);
                },
                error: function(){
                    alert('error');
                }
            });
    });

});
</script>
</code>```

cont_boq.php code

```<code><table border="2">
    <tr>
        <td>test</td><td><?=$_POST['boq'];?></td>
    </tr>
</table>
</code>```

Title: Unable to load div using ajax

Body:
I am using a select box to navigate to a new page but the table div data will be received from another data based on the select box. Here is my code

html page

<select id="works" class="btn btn-default" style="text-align:left; background-color:#FFF" onchange="getboq(this)">
<option value=""> Select Work Name</option>
<option value="1" style="text-align:left"><?= 1 ?>
<option value="2" style="text-align:left"><?= 2 ?>
</option>
</select>

Js file

function getboq(work)
{
var boq = work.value;
$.ajax({
            url: 'data/cont_boq.php',
            type: 'post',
            dataType: 'json',
            data: {
                boq:boq,
            },
            success: function (data) {
            window.location = 'boq.php'
                $('#boq').html(data);
            },
            error: function(){
                alert('error');
            }
        });
}

Cont.php

Its a normal table based on select box value, How ever even i made a simple table as well to check if it works but my efforts bore no fruit

boq.php

is a simple php page having the required div

Interestingly i can see the response on firebug but getting alert "error"

Body:
try this code

PHP and Script Code

add letest .js library:letest .js library

<select id="works" class="btn btn-default" style="text-align:left; background-color:#FFF">
<option value=""> Select Work Name</option>
<option value="1" style="text-align:left"><?=1?>
<option value="2" style="text-align:left"><?=2?>
</option>
</select>
<div id="boq"></div>
<script type="text/javascript" src='.js library path'></script>
<script type="text/javascript">
$(document).ready(function(){
    $('select').change(function(){
            var boq = $('select option:selected').val();
            $.ajax({
                url: 'data/cont_boq.php',
                //url: 'cont_boq.php',
                type: 'post',
                data: {boq:boq},
                success: function (data) {
                   $('#boq').html(data);
                },
                error: function(){
                    alert('error');
                }
            });
    });

});
</script>

cont_boq.php code

<table border="2">
    <tr>
        <td>test</td><td><?=$_POST['boq'];?></td>
    </tr>
</table>


问:
Magento 2 errors on cache:flush cache:clean | Need to set permission to 777 afterwards
Everytime I run:

```<code>php bin/magento cache:flush
php bin/magento cache:clean
</code>```

I get the following message when reloading the page:

An error has happened during application run. See exception log for
  details.

exception.log:

```<code>ain.CRITICAL: Exception: Warning: file_put_contents(/var/www/magento2/var/cache//mage-tags/mage---914_CONFIG_SCOPES): failed to open stream: Permission denied in /var/www/magento2/vendor/colinmollenhour/cache-backend-file/File.php on line 663 in /var/www/magento2/vendor/magento/framework/App/ErrorHandler.php:61
</code>```

When I then run:

```<code>sudo chmod -R 777 var/ pub/
</code>```

The error is gone.

How could this happen everytime I clean cache and what should be done to back trace/solve this issue?

答:
The root of such type of issues is same: the user that run web-server differs from the user which runs console command.

Preconditions

You should define what user run your web-server.

```<code>$ ls -la
</code>```

This command could who creates var/cache and so on.

Let's decide that web-server run under www-data user.

Solution 1

```<code>$ sudo -H -u www-data __some_command_here_
</code>```

This format allows you to run the command under web-server user. So application will have same rights as a server (user www-data).
So you command php bin/magento cache:flush transforms to

```<code>$ sudo -H -u www-data php bin/magento cache:flush
</code>```

Solution 2

Add web-server's user to your user to the same group.

```<code>$ id
uid=1001(ygl) gid=1002(ygl) groups=1002(ygl),112(nopasswdlogin)
</code>```

this one will show information about the current user.

$ sudo usermod -a -G  www-data

this command will add www-data to yourGroupName.

Body:
Everytime I run:

php bin/magento cache:flush
php bin/magento cache:clean

I get the following message when reloading the page:

An error has happened during application run. See exception log for
  details.

exception.log:

ain.CRITICAL: Exception: Warning: file_put_contents(/var/www/magento2/var/cache//mage-tags/mage---914_CONFIG_SCOPES): failed to open stream: Permission denied in /var/www/magento2/vendor/colinmollenhour/cache-backend-file/File.php on line 663 in /var/www/magento2/vendor/magento/framework/App/ErrorHandler.php:61

When I then run:

sudo chmod -R 777 var/ pub/

The error is gone.

How could this happen everytime I clean cache and what should be done to back trace/solve this issue?

Body:
The root of such type of issues is same: the user that run web-server differs from the user which runs console command.

Preconditions

You should define what user run your web-server.

$ ls -la

This command could who creates var/cache and so on.

Let's decide that web-server run under www-data user.

Solution 1

$ sudo -H -u www-data __some_command_here_

This format allows you to run the command under web-server user. So application will have same rights as a server (user www-data).
So you command php bin/magento cache:flush transforms to

$ sudo -H -u www-data php bin/magento cache:flush

Solution 2

Add web-server's user to your user to the same group.

$ id
uid=1001(ygl) gid=1002(ygl) groups=1002(ygl),112(nopasswdlogin)

this one will show information about the current user.

$ sudo usermod -a -G  www-data

this command will add www-data to yourGroupName.


问:
Requests + Proxy Servers, IP address won't change
I am using the python shell to test requests together with proxy servers.
After reading documentation (http://docs.python-requests.org/en/master/user/advanced/) and a few stackoverflow threads I am doing the following:

```<code>import requests

s = requests.session()
proxies = {'http': 'http://90.178.216.202:3128'}
s.proxies.update(proxies)
req = s.get('http://jsonip.com')
</code>```

After this, if I print req.text, I get this:
u'{"ip":"my current IP (not the proxy server IP I have inserted before)","about":"/about", ......}'

Can you please explain why I'm getting my computer's IP address and not the proxy server's IP address?
Did I go wrong somewhere or am I expecting the wrong thing to happen here?
I am new to requests + proxy servers so I would like to make sure I am understanding this.

UPDATE
I also have this in my code:

```<code>headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 6.0; WOW64; rv:24.0) Gecko/20100101 Firefox/24.0'}
s.headers.update(headers)
</code>```

Thanks
Vittorio

答:
Instead of doing this pass user-agent

requests.post(url='abc.com',header={'user-agent':'Mozila 5.0'})

Body:
I am using the python shell to test requests together with proxy servers.
After reading documentation (http://docs.python-requests.org/en/master/user/advanced/) and a few stackoverflow threads I am doing the following:

import requests

s = requests.session()
proxies = {'http': 'http://90.178.216.202:3128'}
s.proxies.update(proxies)
req = s.get('http://jsonip.com')

After this, if I print req.text, I get this:
u'{"ip":"my current IP (not the proxy server IP I have inserted before)","about":"/about", ......}'

Can you please explain why I'm getting my computer's IP address and not the proxy server's IP address?
Did I go wrong somewhere or am I expecting the wrong thing to happen here?
I am new to requests + proxy servers so I would like to make sure I am understanding this.

UPDATE
I also have this in my code:

headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 6.0; WOW64; rv:24.0) Gecko/20100101 Firefox/24.0'}
s.headers.update(headers)

Thanks
Vittorio


问:
Wildfly Swarm runs a deployed artifact using it's hash name
I have a standard clean web project that I'm using to build a Wildfly swarm artifact. My POM looks like:

```<code><?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.test.swarm</groupId>
    <artifactId>test_security_module</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>war</packaging>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.wildfly.swarm</groupId>
                <artifactId>bom-all</artifactId>
                <version>2017.6.1</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <dependencies>
        <dependency>
            <groupId>javax</groupId>
            <artifactId>javaee-api</artifactId>
            <version>7.0</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.wildfly.swarm</groupId>
            <artifactId>security</artifactId>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.wildfly.swarm</groupId>
                <artifactId>wildfly-swarm-plugin</artifactId>
                <version>2017.6.1</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>package</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>
</code>```

I also have a jboss-web.xml that is supposed to register a context root, and looks like:

```<code><?xml version="1.0" encoding="UTF-8"?>
<jboss-web xmlns="http://www.jboss.com/xml/ns/javaee"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xsi:schemaLocation="http://www.jboss.com/xml/ns/javaee http://www.jboss.org/j2ee/schema/jboss-web_6_0.xsd"
           version="6.0">

    <context-root>/Tiles</context-root>

</jboss-web>
</code>```

So after building and running the project, the /Tiles context root must be registered, and the application accessible on: http://localhost:8080/Tiles.

But then I try to run the uber jar using the standard java -jar, Swarm deploys the hash name of the project name (as opposed to the project name). It doesn't even register the context root. The snippet of the stack trace is:

2017-07-04 04:32:14,329 INFO  [org.jboss.as] (Controller Boot Thread) WFLYSRV0025: WildFly Swarm 2017.6.1 (WildFly Core 2.2.1.Final) started in 5762ms - Started 55 of 59 services (4 services are lazy, passive or on-demand)
  2017-07-04 04:32:14,383 INFO  [org.wildfly.swarm.runtime.deployer] (main) deploying 3d31f81a-29d6-4ea1-b3eb-0a2a98a3c3f5.war
  2017-07-04 04:32:14,405 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-3) WFLYSRV0027: Starting deployment of "3d31f81a-29d6-4ea1-b3eb-0a2a98a3c3f5.war" (runtime-name: "3d31f81a-29d6-4ea1-b3eb-0a2a98a3c3f5.war")
  2017-07-04 04:32:14,464 INFO  [org.jboss.as.server] (main) WFLYSRV0010: Deployed "3d31f81a-29d6-4ea1-b3eb-0a2a98a3c3f5.war" (runtime-name : "3d31f81a-29d6-4ea1-b3eb-0a2a98a3c3f5.war")
  2017-07-04 04:32:14,466 INFO  [org.wildfly.swarm] (main) WFSWARM99999: WildFly Swarm is Ready

What could cause swarm to run the application using the hash name of the project?

答:
Fixed by adding the undertow dependency</p>

```<code><dependency>
    <groupId>org.wildfly.swarm</groupId>
    <artifactId>undertow</artifactId>
</dependency>
</code>```

Body:
I have a standard clean web project that I'm using to build a Wildfly swarm artifact. My POM looks like:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.test.swarm</groupId>
    <artifactId>test_security_module</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>war</packaging>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.wildfly.swarm</groupId>
                <artifactId>bom-all</artifactId>
                <version>2017.6.1</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <dependencies>
        <dependency>
            <groupId>javax</groupId>
            <artifactId>javaee-api</artifactId>
            <version>7.0</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.wildfly.swarm</groupId>
            <artifactId>security</artifactId>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.wildfly.swarm</groupId>
                <artifactId>wildfly-swarm-plugin</artifactId>
                <version>2017.6.1</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>package</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

I also have a jboss-web.xml that is supposed to register a context root, and looks like:

<?xml version="1.0" encoding="UTF-8"?>
<jboss-web xmlns="http://www.jboss.com/xml/ns/javaee"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xsi:schemaLocation="http://www.jboss.com/xml/ns/javaee http://www.jboss.org/j2ee/schema/jboss-web_6_0.xsd"
           version="6.0">

    <context-root>/Tiles</context-root>

</jboss-web>

So after building and running the project, the /Tiles context root must be registered, and the application accessible on: http://localhost:8080/Tiles.

But then I try to run the uber jar using the standard java -jar, Swarm deploys the hash name of the project name (as opposed to the project name). It doesn't even register the context root. The snippet of the stack trace is:

2017-07-04 04:32:14,329 INFO  [org.jboss.as] (Controller Boot Thread) WFLYSRV0025: WildFly Swarm 2017.6.1 (WildFly Core 2.2.1.Final) started in 5762ms - Started 55 of 59 services (4 services are lazy, passive or on-demand)
  2017-07-04 04:32:14,383 INFO  [org.wildfly.swarm.runtime.deployer] (main) deploying 3d31f81a-29d6-4ea1-b3eb-0a2a98a3c3f5.war
  2017-07-04 04:32:14,405 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-3) WFLYSRV0027: Starting deployment of "3d31f81a-29d6-4ea1-b3eb-0a2a98a3c3f5.war" (runtime-name: "3d31f81a-29d6-4ea1-b3eb-0a2a98a3c3f5.war")
  2017-07-04 04:32:14,464 INFO  [org.jboss.as.server] (main) WFLYSRV0010: Deployed "3d31f81a-29d6-4ea1-b3eb-0a2a98a3c3f5.war" (runtime-name : "3d31f81a-29d6-4ea1-b3eb-0a2a98a3c3f5.war")
  2017-07-04 04:32:14,466 INFO  [org.wildfly.swarm] (main) WFSWARM99999: WildFly Swarm is Ready

What could cause swarm to run the application using the hash name of the project?

Body:
Fixed by adding the undertow dependency

<dependency>
    <groupId>org.wildfly.swarm</groupId>
    <artifactId>undertow</artifactId>
</dependency>


问:
How to install old SDK platform
I want to test against Android 1.3 platform instead of latest 2.2.

Here is how my Android SDK and AVD Manager look likes.

However, I was expecting (screen from http://developer.android.com/sdk/installing.html#components), so that I can select old platform.

Is there anything I had missed out?

答: Run Help > Check for Updates first, to update your Eclipse plug-in, then you can access the repository. Why would you want to test against 1.3? If anything is still on that old a version of Android (was there even a 1.3? It's not listed here), it's an insignificant portion of the market. The earliest you should even worry about is 1.5.</p>

Title: How to install old SDK platform


问:
AngularJs - allow only one item to be selected in Table
I am using smart table. I have a logic behind where I only need one item to be selected. My current table code allow multiple lines to be selected.

This is my HTML:

```<code> <table st-safe-src="flow3.dataSet" st-table="flow3.displayed" class="table table-striped">

                <thead>
                <tr>
                    <th st-sort="method">Method</th>
                    <th st-sort="sample">Sample</th>
                    <th st-sort="parameters">Parameters</th>
                </tr>
                </thead>
                <tbody ui-sortable ng-model="flow3.displayed">
                <tr ng-repeat="row in flow3.displayed track by $index" style="cursor: move;" ng-click="row.selected = !row.selected; flow3.selectRow($event, row)" ng-class="{success: row.selected}">
                    <td>{{row.method.name}}</td>
                    <td>{{row.sample}}</td>
                    <td>
                        <span ng-repeat="parameter in row.parameters">{{parameter.methodInputParameter.name}} : {{parameter.value}}<br/></span>
                    </td>
                    <td>
                        <button type="button" ng-click="flow3.removeItem(row)"
                                class="btn btn-danger btn-sm btn-round pull-right"
                                ng-disabled="flow3.confirmDisabled">
                            <i class="glyphicon glyphicon-trash"></i>
                        </button>
                    </td>
                </tr>
                </tbody>
</table>
</code>```

This is my JS:

```<code> flow3.selectRow = function($event, row) {
        flow3.selectedItem = row;
}
</code>```

答:
I'd recommend looking at the smart table github page and use guide here.

In particular the section relevant to your question is 'Select Data Rows'.

Essentially you need to use the st-select-row attribute along with the st-select-mode to configure click within your table row (tr) elements.

Body:
I am using smart table. I have a logic behind where I only need one item to be selected. My current table code allow multiple lines to be selected.

This is my HTML:

                    Method
                    Sample
                    Parameters

                    {{row.method.name}}
                    {{row.sample}}

                        {{parameter.methodInputParameter.name}} : {{parameter.value}}

                        <button type="button" ng-click="flow3.removeItem(row)"
                                class="btn btn-danger btn-sm btn-round pull-right"
                                ng-disabled="flow3.confirmDisabled">

                        </button>

This is my JS:

 flow3.selectRow = function($event, row) {
        flow3.selectedItem = row;
}


问:
Spring 4 application register as client to Eureka
I have a Spring 4 application (not Spring Boot) and I want it to register to Eureka service discovery.

Is there any way to do it? because all tutorials are tightly connected to Spring Boot.

答:
This question have been asked here before, basically you need to do something like this,

```<code> DiscoveryManager.getInstance().initComponent(new MyDataCenterInstanceConfig(), new DefaultEurekaClientConfig());

  String vipAddress = "MY-SERVICE";

    InstanceInfo nextServerInfo = null;
    try {
        nextServerInfo = DiscoveryManager.getInstance()
                .getEurekaClient()
                .getNextServerFromEureka(vipAddress, false);
    } catch (Exception e) {
        System.err.println("Cannot get an instance of example service to talk to from eureka");
        System.exit(-1);
    }

    System.out.println("Found an instance of example service to talk to from eureka: "
            + nextServerInfo.getVIPAddress() + ":" + nextServerInfo.getPort());

    System.out.println("healthCheckUrl: " + nextServerInfo.getHealthCheckUrl());
    System.out.println("override: " + nextServerInfo.getOverriddenStatus());

    System.out.println("Server Host Name "+ nextServerInfo.getHostName() + " at port " + nextServerInfo.getPort() );
</code>```

You will have to add a configuration file to the class path. Eureka client uses this file to read the information about the eureka servers.

```<code>eureka.preferSameZone=true
eureka.shouldUseDns=false
eureka.serviceUrl.default=http://localhost:8761/eureka/
eureka.decoderName=JacksonJson
</code>```

Down below are the Maven dependencies that you need. Eureka1 supports JDK7 though some part of it has been built with JDK8. However I had to provide older versions of "archaius-core" and "servo-core" to make it run with JDK7

```<code><dependency>
        <groupId>com.netflix.archaius</groupId>
        <artifactId>archaius-core</artifactId>
        <version>0.7.3</version>
    </dependency>
    <dependency>
        <groupId>com.netflix.servo</groupId>
        <artifactId>servo-core</artifactId>
        <version>0.10.0</version>
    </dependency>
</code>```

Here are links to Netflix own Eureka documentation and also a link to the original Stack Overflow thread discussing this topic
Eureka: https://github.com/Netflix/eureka/wiki
Original thread: Eureka service discovery without Spring-boot

Body:
This question have been asked here before, basically you need to do something like this,

 DiscoveryManager.getInstance().initComponent(new MyDataCenterInstanceConfig(), new DefaultEurekaClientConfig());

  String vipAddress = "MY-SERVICE";

    InstanceInfo nextServerInfo = null;
    try {
        nextServerInfo = DiscoveryManager.getInstance()
                .getEurekaClient()
                .getNextServerFromEureka(vipAddress, false);
    } catch (Exception e) {
        System.err.println("Cannot get an instance of example service to talk to from eureka");
        System.exit(-1);
    }

    System.out.println("Found an instance of example service to talk to from eureka: "
            + nextServerInfo.getVIPAddress() + ":" + nextServerInfo.getPort());

    System.out.println("healthCheckUrl: " + nextServerInfo.getHealthCheckUrl());
    System.out.println("override: " + nextServerInfo.getOverriddenStatus());

    System.out.println("Server Host Name "+ nextServerInfo.getHostName() + " at port " + nextServerInfo.getPort() );

You will have to add a configuration file to the class path. Eureka client uses this file to read the information about the eureka servers.

eureka.preferSameZone=true
eureka.shouldUseDns=false
eureka.serviceUrl.default=http://localhost:8761/eureka/
eureka.decoderName=JacksonJson

Down below are the Maven dependencies that you need. Eureka1 supports JDK7 though some part of it has been built with JDK8. However I had to provide older versions of "archaius-core" and "servo-core" to make it run with JDK7

<dependency>
        <groupId>com.netflix.archaius</groupId>
        <artifactId>archaius-core</artifactId>
        <version>0.7.3</version>
    </dependency>
    <dependency>
        <groupId>com.netflix.servo</groupId>
        <artifactId>servo-core</artifactId>
        <version>0.10.0</version>
    </dependency>

Here are links to Netflix own Eureka documentation and also a link to the original Stack Overflow thread discussing this topic
Eureka: https://github.com/Netflix/eureka/wiki
Original thread: Eureka service discovery without Spring-boot


问:
Angular Dependancy Injection
I have a quick question about Angular Dependancy Injection. I have read that if you want a service to have only a single instance across your app, it should be included as a provider in the AppModule instead of any components that use it. Would this still apply other modules imported by the AppModule. For example, I want to have an AuthService as a provider in my SharedModule. If I then import this module to the AppModule, would all the components across my app share the same instance of the service?</p>

答:
Short answer: yes

but..

Do not specify app-wide singleton providers in a shared module. A lazy-loaded module that imports that shared module makes its own copy of the service.

Source: https://angular.io/guide/ngmodule#why-userservice-isnt-shared

Title: Angular Dependancy Injection


问:
MongoDB - Sort by the maxnium number of keywords in input
I am looking to build a mongo query that would sort the documents by the number of repeated keywords specified in the input array. My document looks like the following

```<code>{
    "_id" : 1,
    "name" : "invoice",
    "rules" : [
        {
            "_any" : [
                "invoice",
                "invoices",
                "total",
                "order",
                "bill"
            ]
        }
    ]
}
{
    "_id" : 2,
    "name" : "Terms of Service",
    "rules" : [
        {
            "_any" : [
                "rule",
                "rules",
                "terms"
            ]
        }
    ]
}
</code>```

So, say if my input array contains the following keywords

```<code>[ 'invoice',
  'invoice',
  'order',
  'bill',
  'bill',
  'bill',
  'bill',
  'bill',
  'terms'
 ]
</code>```

Mongo should show the result for _id: 1 first and then  _id: 2 since the input array contains the maximum number of keywords that belongs to _id: 1

Thanks in advance

答:
You can put index in your arrays.
0: "invoice",
1: "bill",
2: "order",
3: "invoice"

Then it'll be easy with the array.length to put it in the correct order.

Body:
I am looking to build a mongo query that would sort the documents by the number of repeated keywords specified in the input array. My document looks like the following

{
    "_id" : 1,
    "name" : "invoice",
    "rules" : [
        {
            "_any" : [
                "invoice",
                "invoices",
                "total",
                "order",
                "bill"
            ]
        }
    ]
}
{
    "_id" : 2,
    "name" : "Terms of Service",
    "rules" : [
        {
            "_any" : [
                "rule",
                "rules",
                "terms"
            ]
        }
    ]
}

So, say if my input array contains the following keywords

[ 'invoice',
  'invoice',
  'order',
  'bill',
  'bill',
  'bill',
  'bill',
  'bill',
  'terms'
 ]

Mongo should show the result for _id: 1 first and then  _id: 2 since the input array contains the maximum number of keywords that belongs to _id: 1

Thanks in advance


问:
Searching for a substring in a dataframe and replacing it
I have a condition where spurious data is created and I am trying to clean it.

eg...

```<code>www.one@foxturn.com/!ut/5 #RealLink
www.one@foxturn.com/ut1/5_RTFDEERERTGFEFD # System adds junks to it
www.one@foxturn.com/ut1/5_dvkerfddfrejermsdkasmf # System adds junks to it
</code>```

I am trying to clean this up by dropping everything after !ut

So far I have tried :

```<code>SPA_MX = Mexico['Page URL'].str.startswith("http://www.www.one@foxturn.com/ut1")
</code>```

but this returns a boolean.

I would like advise on the most efficient way to achieve this.

答:
```<code>my_string="www.one@foxturn.com/!ut/5"
final =  my_string.split("!ut")[0]
</code>```

output:

www.one@foxturn.com/

Body:
I have a condition where spurious data is created and I am trying to clean it.

eg...

www.one@foxturn.com/!ut/5 #RealLink
www.one@foxturn.com/ut1/5_RTFDEERERTGFEFD # System adds junks to it
www.one@foxturn.com/ut1/5_dvkerfddfrejermsdkasmf # System adds junks to it

I am trying to clean this up by dropping everything after !ut

So far I have tried :

SPA_MX = Mexico['Page URL'].str.startswith("http://www.www.one@foxturn.com/ut1")

but this returns a boolean.

I would like advise on the most efficient way to achieve this.

Body:
my_string="www.one@foxturn.com/!ut/5"
final =  my_string.split("!ut")[0]

output:

www.one@foxturn.com/


问:
Overriding vs Virtual
What is the purpose of using the reserved word virtual in front of functions? If I want a child class to override a parent function, I just declare the same function such as void draw(){}.

```<code>class Parent {
public:
    void say() {
        std::cout << "1";
    }
};

class Child : public Parent {
public:
    void say()
    {
        std::cout << "2";
    }
};

int main()
{
    Child* a = new Child();
    a->say();
    return 0;
}
</code>```

The output is 2.

So again, why would the reserved word virtual be necessary in the header of say() ?

Thanks a bunch.

答:
Well I tested it for myself, because there are a lot of things we can think about:

```<code>#include <iostream>
using namespace std;
class A
{
public:
    virtual void v() { cout << "A virtual" << endl; }
    void f() { cout << "A plain" << endl; }
};

class B : public A
{
public:
    virtual void v() { cout << "B virtual" << endl; }
    void f() { cout << "B plain" << endl; }
};

class C : public B
{
public:
    virtual void v() { cout << "C virtual" << endl; }
    void f() { cout << "C plain" << endl; }
};

int main()
{
    A * a = new C;
    a->f();
    a->v();

    ((B*)a)->f();
    ((B*)a)->v();
}
</code>```

output:

```<code>A plain
C virtual
B plain
C virtual
</code>```

I think that a good, simple and short answer might look like this (because I think people who can understand more can memorize less thus needing for short and simple explanation):

Virtual methods checks for the DATA of the instance the pointer points to, while classic methods don't thus calling the method correponding to the specified type.

The point of that feature is the following: suppose you have an array of A's. The array can contain B's, C's, (or even derived types.). if you want to sequentially call the same method of all those instances, you would call each one you overloaded.

I find this quite tricky to understand, and obviously any C++ course should explained how this is achieved, because most of the time you are just teached about virtual functions, you use them, but until you understand how the compiler understand them and how the executable will handle the calls, you are in the dark.

The thing about VFtables is that I have never been explained what kind of code it adds, and that's obviously here where C++ requires much more experience than C, and this might be the main reason C++ was labelled as "slow" in its early days: in fact, it's powerful, but just like everything, it's powerful if you know how to use it, or else you just "blow your whole leg off".

Title: Overriding vs Virtual

Body:
What is the purpose of using the reserved word virtual in front of functions? If I want a child class to override a parent function, I just declare the same function such as void draw(){}.

class Parent {
public:
    void say() {
        std::cout << "1";
    }
};

class Child : public Parent {
public:
    void say()
    {
        std::cout << "2";
    }
};

int main()
{
    Child* a = new Child();
    a->say();
    return 0;
}

The output is 2.

So again, why would the reserved word virtual be necessary in the header of say() ?

Thanks a bunch.

Body:
Well I tested it for myself, because there are a lot of things we can think about:

#include <iostream>
using namespace std;
class A
{
public:
    virtual void v() { cout << "A virtual" << endl; }
    void f() { cout << "A plain" << endl; }
};

class B : public A
{
public:
    virtual void v() { cout << "B virtual" << endl; }
    void f() { cout << "B plain" << endl; }
};

class C : public B
{
public:
    virtual void v() { cout << "C virtual" << endl; }
    void f() { cout << "C plain" << endl; }
};

int main()
{
    A * a = new C;
    a->f();
    a->v();

    ((B*)a)->f();
    ((B*)a)->v();
}

output:

A plain
C virtual
B plain
C virtual

I think that a good, simple and short answer might look like this (because I think people who can understand more can memorize less thus needing for short and simple explanation):

Virtual methods checks for the DATA of the instance the pointer points to, while classic methods don't thus calling the method correponding to the specified type.

The point of that feature is the following: suppose you have an array of A's. The array can contain B's, C's, (or even derived types.). if you want to sequentially call the same method of all those instances, you would call each one you overloaded.

I find this quite tricky to understand, and obviously any C++ course should explained how this is achieved, because most of the time you are just teached about virtual functions, you use them, but until you understand how the compiler understand them and how the executable will handle the calls, you are in the dark.

The thing about VFtables is that I have never been explained what kind of code it adds, and that's obviously here where C++ requires much more experience than C, and this might be the main reason C++ was labelled as "slow" in its early days: in fact, it's powerful, but just like everything, it's powerful if you know how to use it, or else you just "blow your whole leg off".


问:
Image url in css based on html title value
I'm trying to generate multiple hexagons with background images, using a php for loop:

```<code><?php
        $dir    = 'resources/images/logos';
        $images = scandir($dir);
        for($i = 2; $i < count($images); $i++) {
            $title = explode('.', $images[$i])[0];
            ?>
                <div class="hexagon_loc<?= $i ?>">
                    <div class="hexagon image" title="<?= $title ?>"></div>
                </div>
    <?php } ?>
</code>```

This works fine, I make a div, with a different class name every time and with the correct title (based of on the filename of the image). Now I want to have a for loop in scss which draws the hexagons, I also want to define the background-images there. But since I can't pass any kind of variables from html/php to css/sass and the fact that the attr() function is widely unsupported I have no way of dynamically doing this, which would result in the titles possibly being mismatched with the images. Is there anyway to do this anyways? Or do I have to use a different approach entirely?

Example sass where I want to define the image:

```<code>.hexagon_loc {
$image: '../../resources/images/bill.jpeg';
@include hexagon($image);
margin-left: 100px;
}
</code>```

Using vanilla JavaScript to solve this would also be a possibility

Thanks

答:
In this situation, I would use  HTML element.

There is a CSS solution but it is not supported in many browsers.

```<code>div { background-image : attr(data-image); }
</code>```

Body:
I'm trying to generate multiple hexagons with background images, using a php for loop:

<?php
        $dir    = 'resources/images/logos';
        $images = scandir($dir);
        for($i = 2; $i < count($images); $i++) {
            $title = explode('.', $images[$i])[0];
            ?>
                <div class="hexagon_loc<?= $i ?>">
                    <div class="hexagon image" title="<?= $title ?>">

    <?php } ?>

This works fine, I make a div, with a different class name every time and with the correct title (based of on the filename of the image). Now I want to have a for loop in scss which draws the hexagons, I also want to define the background-images there. But since I can't pass any kind of variables from html/php to css/sass and the fact that the attr() function is widely unsupported I have no way of dynamically doing this, which would result in the titles possibly being mismatched with the images. Is there anyway to do this anyways? Or do I have to use a different approach entirely?

Example sass where I want to define the image:

.hexagon_loc {
$image: '../../resources/images/bill.jpeg';
@include hexagon($image);
margin-left: 100px;
}

Using vanilla JavaScript to solve this would also be a possibility

Thanks

Body:
In this situation, I would use <img> HTML element.

There is a CSS solution but it is not supported in many browsers.

div { background-image : attr(data-image); }


问:
Can I review incoming changes in TortoiseSVN like in Eclipse before updating?
The synchronize view of Eclipse is very nice to see incoming changes from everybody before updating my codebase.

Is there a similar feature in TortoiseSVN? I can only compare 2 revisions there, I did not find any functionality to compare my working copy (which is a mix of modified files and files from various revisions) with the HEAD revision easily!

答: You can have a look at the log before you update. It shows which revision you're currently at (bold font) and what was committed later. </p>