小编Har*_*cla的帖子

如何将 Symfony 命令作为 cron 作业执行?

我在 symfony 中有这个简单的命令:

use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

class AuctionEndCommand extends Command
{
protected function configure()
{
    error_log(print_r('test',true), 3, "/tmp/error.log");

    $this->setName('desktop:auction_end')->setDescription('Execute when auction is end.')->setHelp("Identify winners for auctions");
}
protected function execute(InputInterface $input, OutputInterface $output)
{

    // outputs multiple lines to the console (adding "\n" at the end of each line)
    $output->writeln([
        'User Creator',
        '============',
        '',
    ]);

    // outputs a message followed by a "\n"
    $output->writeln('Whoa!');

    // outputs a message without adding a "\n" at the end of the …
Run Code Online (Sandbox Code Playgroud)

php linux cron symfony

6
推荐指数
1
解决办法
3万
查看次数

在Symfony 3 Controller中获取请求和会话

我有一个大问题,请帮助我.所以我想创建一个只使用以下用户的登录系统:

providers:
  in_memory:
      memory:
          users:
Run Code Online (Sandbox Code Playgroud)

所以我的全球路由/app/config/routing.yml:

app_admin:
    resource: "@AppAdminBundle/Resources/config/routing.yml"
    prefix:   /admin
Run Code Online (Sandbox Code Playgroud)

我在AdminBundle中的路由:

app_admin_homepage:
    path:     /
    defaults: { _controller: AppAdminBundle:Login:index }
login:
    path:   /login
    defaults:  { _controller: AppAdminBundle:Login:login }
login_check:
    path:   /login_check
Run Code Online (Sandbox Code Playgroud)

我的LoginController:

<?php

namespace App\AdminBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\Security\Core\SecurityContext;

class LoginController extends Controller
{
public function indexAction()
{
    return $this->render('AppAdminBundle:Member:login.html.twig');
}
public function loginAction()
{
    $request = $this->get('request');
    $session = $this->get('session');

    if ($request->attributes->has(SecurityContext::AUTHENTICATION_ERROR)) {
        $error = $request->attributes->get(SecurityContext::AUTHENTICATION_ERROR);
    } else {
        $error = $session->get(SecurityContext::AUTHENTICATION_ERROR);
        $session->remove(SecurityContext::AUTHENTICATION_ERROR);
    }

    return $this->render('AppAdminBundle:Member:login.html.twig', array( …
Run Code Online (Sandbox Code Playgroud)

php symfony

3
推荐指数
2
解决办法
1万
查看次数

Symfony2:如何在twig过滤器/扩展中从parameters.yml获取容器参数?

我有档案parameters.yml:

parameters:
    ............
    image_news_url: http://image.dev/news/
Run Code Online (Sandbox Code Playgroud)

现在在我的包中我创建了一个新的枝条扩展:

// src/DesktopBundle/Twig/AppExtension.php

namespace App\DesktopBundle\Twig;

use Symfony\Component\DependencyInjection\ContainerBuilder;

class AppExtension extends \Twig_Extension
{
public function getFilters()
{
    return array(
        new \Twig_SimpleFilter('get_image', array($this, 'getImage')),
    );
}

public function getImage($domen, $image_id)
{
    $o_container = new ContainerBuilder();

    switch($domen){
        case 'news':
            return sprintf('%s%s',$o_container->getParameter('image_news_url'),$image_id.'.slide.jpg');
            break;
    }
}

public function getName()
{
    return 'app_extension';
}
Run Code Online (Sandbox Code Playgroud)

我有一个错误:You have requested a non-existent parameter "image_news_url.你能帮我吗 ?我不明白为什么我没有访问parameters.yml.Thx提前和抱歉我的英语

php symfony

2
推荐指数
1
解决办法
2811
查看次数

只获取指定的网址

我想只检查站点完成了:*.test.com*.test1.com 我想:

if((preg_match('.\w+.test.com', $_SERVER['HTTP_ORIGIN'])) or (preg_match('.\w+.test1.com', $_SERVER['HTTP_ORIGIN']))){
}
Run Code Online (Sandbox Code Playgroud)

php regex

2
推荐指数
1
解决办法
57
查看次数

PHP中的DateTime与时区

我有个问题。我尝试在php中使用datetime。我做了:

$now = new \DateTime();
Run Code Online (Sandbox Code Playgroud)

当我print_r $now我有:

DateTime Object
(
  [date] => 2016-12-01 05:55:01
  [timezone_type] => 3
  [timezone] => Europe/Helsinki
)
Run Code Online (Sandbox Code Playgroud)

当我看时钟的时候16:05。我需要设置时区吗?我想使用布加勒斯特时区。如何获得正确的日期和时间?提前Thx

php datetime date php-5.3

2
推荐指数
3
解决办法
1万
查看次数

递归 ksort :不对数组进行排序

我有一个问题所以我有这个数组:

Array
(
[2016] => Array
    (
        [23] => Array
            (
                [total_auctions] => 0
                [total_price] => 0
            )

        [22] => Array
            (
                [total_auctions] => 0
                [total_price] => 0
            )

        [21] => Array
            (
                [total_auctions] => 0
                [total_price] => 0
            )

        [20] => Array
            (
                [total_auctions] => 0
                [total_price] => 0
            )
)
Run Code Online (Sandbox Code Playgroud)

我想按键对递归进行排序。所以我创建了方法:

 public function sortNestedArrayAssoc($a)
{
    if (!is_array($a)) {
        return false;
    }
    ksort($a);
    foreach ($a as $k=>$v) {
        $this->sortNestedArrayAssoc($a[$k]);
    }
    return true;
}
Run Code Online (Sandbox Code Playgroud)

但是我得到了相同的结果,带有键的数组23是第一个,我真的不明白问题出在哪里。你能帮我吗 ?提前感谢并为我的英语感到抱歉

php ksort php-5.3 php-5.5

1
推荐指数
1
解决办法
1907
查看次数

标签 统计

php ×6

symfony ×3

php-5.3 ×2

cron ×1

date ×1

datetime ×1

ksort ×1

linux ×1

php-5.5 ×1

regex ×1