我正在搜索,无法找到答案.我的应用程序中有数据库角色模型.用户可以拥有角色,但必须将此角色存储到数据库中.
但是,用户需要从数据库中添加默认角色.所以我创建了一个服务:
<?php
namespace Alef\UserBundle\Service;
use Alef\UserBundle\Entity\Role;
/**
* Description of RoleService
*
* @author oracle
*/
class RoleService {
const ENTITY_NAME = 'AlefUserBundle:Role';
private $em;
public function __construct(EntityManager $em)
{
$this->em = $em;
}
public function findAll()
{
return $this->em->getRepository(self::ENTITY_NAME)->findAll();
}
public function create(User $user)
{
// possibly validation here
$this->em->persist($user);
$this->em->flush($user);
}
public function addRole($name, $role) {
if (($newrole = findRoleByRole($role)) != null)
return $newrole;
if (($newrole = findRoleByName($name)) != null)
return $newrole;
//there is no existing role …
Run Code Online (Sandbox Code Playgroud) 第一件事:我知道有W3C验证器的接口:http://pear.php.net/package/Services_W3C_HTMLValidator/ 但我不知道我是否可以在便宜的托管服务器上安装它.我不这么认为.
我需要在我的内容管理系统中使用我的seo工具验证器,因此它必须非常便携.
我很想使用W3C但只有它是便携式的.我也可以使用Curl,但它不是优雅的解决方案.
我到目前为止找到的最好的是:http://phosphorusandlime.blogspot.com/2007/09/php-html-validator-class.html
是否有任何验证器可与W3C相媲美但可移植(只有PHP不依赖于自定义包)?
我想创建自定义用户检查器以验证针对上次接受的eula的登录操作.'想法很简单,会有很多版本的eula和用户无法登录,直到他接受最新的eula.
场景是:
我找到了这个:https: //groups.google.com/forum/#!msg/symfony2/D0V0bFks9S0/Qg9mrbpfB3IJ
但遗憾的是,没有完整版的自定义用户检查程序.我该如何实现剩下的呢?
我在德国的某家公司遇到了问题.他们在他们的网络中使用代理,我的程序无法与服务器通信.
IE使用此设置:
这意味着:自动检测设置
这是代码:
public static bool CompleteValidation(string regKey)
{
string uri = "***";
int c = 1;
if (Counter < 5) c = 6 - Counter;
string response = "";
try
{
System.Net.ServicePointManager.Expect100Continue = false;
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(uri);
request.AllowWriteStreamBuffering = true;
request.Method = "POST";
request.UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:5.0) Gecko/20100101 Firefox/5.0";
request.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
request.Headers.Add(HttpRequestHeader.AcceptLanguage, "pl,en-us;q=0.7,en;q=0.3");
request.Headers.Add(HttpRequestHeader.AcceptEncoding, "gzip, deflate");
request.Headers.Add(HttpRequestHeader.AcceptCharset, "ISO-8859-2,utf-8;q=0.7,*;q=0.7");
request.KeepAlive = true;
//proxy settings
string exepath = Path.GetDirectoryName(Application.ExecutablePath);
string proxySettings = exepath + …
Run Code Online (Sandbox Code Playgroud) 我想使用WebClient
(或者还有另一个更好的选择?)但是有一个问题.我知道打开流需要一些时间,这是无法避免的.然而,与完全立即阅读相比,阅读它需要更多的时间.
有没有最好的方法来做到这一点?我的意思是两种方式,字符串和文件.Progress
是我自己的代表,它运作良好.
第五次更新:
最后,我设法做到了.与此同时,我查看了一些让我意识到问题出在其他地方的解决方案.
我已经测试了自定义WebResponse
和WebRequest
对象,库libCURL.NET
甚至Sockets
.
时间的差异是gzip压缩.压缩流长度只是普通流长度的一半,因此浏览器的下载时间不到3秒.
如果有人想知道我是如何解决这个问题,我会放一些代码:(不需要一些标题)
public static string DownloadString(string URL)
{
WebClient client = new WebClient();
client.Headers["User-Agent"] = "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/532.5 (KHTML, like Gecko) Chrome/4.1.249.1045 Safari/532.5";
client.Headers["Accept"] = "application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5";
client.Headers["Accept-Encoding"] = "gzip,deflate,sdch";
client.Headers["Accept-Charset"] = "ISO-8859-2,utf-8;q=0.7,*;q=0.3";
Stream inputStream = client.OpenRead(new Uri(URL));
MemoryStream memoryStream = new MemoryStream();
const int size = 32 * 4096;
byte[] buffer = new byte[size];
if (client.ResponseHeaders["Content-Encoding"] == "gzip") …
Run Code Online (Sandbox Code Playgroud) 有没有办法在不编写自己的函数的情况下完成此操作?
例如:
$text = 'Test <span><a>something</a> something else</span>.';
$text = cutText($text, 2, null, 20, true);
//result: Test <span><a>something</a></span>
Run Code Online (Sandbox Code Playgroud)
我需要让这个功能坚不可摧
我的问题类似于 这个线程, 但我需要一个更好的解决方案.我想保持嵌套标签不变.
到目前为止我的算法是:
function cutText($content, $max_words, $max_chars, $max_word_len, $html = false) {
$len = strlen($content);
$res = '';
$word_count = 0;
$word_started = false;
$current_word = '';
$current_word_len = 0;
if ($max_chars == null) {
$max_chars = $len;
}
$inHtml = false;
$openedTags = array();
for ($i = 0; $i<$max_chars;$i++) {
if ($content[$i] == '<' && $html) {
$inHtml = …
Run Code Online (Sandbox Code Playgroud) 集成使用gedmo可翻译行为的某个实体的版本控制系统的最佳方法是什么?
Gedmo Loggable似乎不像这样工作:
/**
* @ORM\Entity(repositoryClass="Alef\JobOffersBundle\Repository\JobOfferRepository")
* @ORM\Table(name="alef_job_offer")
* @Gedmo\Loggable
*/
class JobOffer implements Loggable, Translatable, UserOwnerInterface {
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @ORM\ManyToOne(targetEntity="Alef\UserBundle\Entity\User")
* @ORM\JoinColumn(name="id_user", referencedColumnName="id")
*/
protected $user;
/**
* @var datetime $created
*
* @Gedmo\Timestampable(on="create")
* @ORM\Column(name="created", type="datetime")
*/
protected $created;
/**
* @var datetime $updatedAt
*
* @ORM\Column(type="datetime")
* @Gedmo\Timestampable(on="update")
*/
protected $updatedAt;
/**
* @Gedmo\Versioned
* @Gedmo\Translatable
* @ORM\Column(name="title", type="string", length=255)
*/
protected $title;
/**
*
* @Gedmo\Versioned …
Run Code Online (Sandbox Code Playgroud) Symfony 3.0.2
我的配置(其他一切都接近默认):
session:
# handler_id set to null will use default session handler from php.ini
handler_id: ~
save_path: "%kernel.root_dir%/../var/sessions/%kernel.environment%"
cookie_httponly: false
Run Code Online (Sandbox Code Playgroud)
安全:
security:
encoders:
XXX\UserBundle\Entity\User:
algorithm: bcrypt
cost: 12
role_hierarchy:
ROLE_USER: ROLE_USER
ROLE_MODERATOR: ROLE_USER
ROLE_ADMIN: ROLE_MODERATOR
ROLE_SUPER_ADMIN: ROLE_ADMIN
providers:
xx_userbundle:
id: xx.user_provider
firewalls:
public:
pattern: ^/report/(footer|report)
security: false
main:
pattern: ^/
anonymous: ~
guard:
provider: xx_userbundle
authenticators:
- xx.user_authenticator
logout:
path: /auth/logout
remember_me:
name: vsess
secret: "%secret%"
lifetime: 604800 # 1 week in seconds
path: /
remember_me_parameter: remember_me
access_control: …
Run Code Online (Sandbox Code Playgroud) 我试图从knpMenu修改模板.我把它重命名为knp_main_menu.html.twig
config.yml:
knp_menu:
twig:
template: knp_main_menu.html.twig
templating: true
default_renderer: twig
Run Code Online (Sandbox Code Playgroud)
knp_menu.html.twig
但是我的文件(原件的确切副本)没有.有没有办法做到这一点?
我的最终目标是制作适用于图标的模板:
例如:
$menu->addChild('Grupy', array(
'route' => 'group',
'attributes' => array(
'title' => 'Dodaj now? grup?',
'data-icon' => 'group',
'data-id' => 'groups_list',
)
));
Run Code Online (Sandbox Code Playgroud)
应该产生这样的东西:
<ul>
<li title="Dodaj now? grup?" data-id="groups_list" data-icon="group">
<a href="...">
<img src="somedir/group.png" /> Grupy
</a>
</li>
</ul>
Run Code Online (Sandbox Code Playgroud)