我们正在考虑将我们的Rest API服务器(它在Web服务中,在Symfony PHP上)移动到Scala有以下几个原因:速度,无开销,更少的CPU,更少的代码,可扩展性等.我不知道Scala直到几个几天前,但我一直很享受这些天我用Scala书和所有博客文章和问题学习的东西(它不是那么难看!)
我有以下选择:
我将不得不使用的一些东西:HTTP请求,JSON输出,MySQL(数据),OAuth,Memcache(缓存),日志,文件上传,统计(可能是Redis).
你会推荐什么?
我想知道iPhone上localstorage HTML 5的限制是什么?我读到它就像5 Mb,但我很惊讶这么少.有任何想法吗?
我一直在使用Silex一天,我有第一个"愚蠢"的问题.如果我有:
$app->get('/cities/{city_id}.json', function(Request $request, $city_id) use($app) {
....
})
->bind('city')
->middleware($checkHash);
Run Code Online (Sandbox Code Playgroud)
我想获得中间件中包含的所有参数(city_id):
$checkHash = function (Request $request) use ($app) {
// not loading city_id, just the parameter after the ?
$params = $request->query->all();
....
}
Run Code Online (Sandbox Code Playgroud)
那么,如何在中间件中获取city_id(参数名称及其值).我将会有30个动作,所以我需要一些可用且可维护的东西.
我错过了什么?
非常感谢!
解
我们需要获得$ request-> attributes的额外参数
$checkHash = function (Request $request) use ($app) {
// GET params
$params = $request->query->all();
// Params which are on the PATH_INFO
foreach ( $request->attributes as $key => $val )
{
// on the attributes ParamaterBag there …Run Code Online (Sandbox Code Playgroud) 我正在用PHP构建API.其中一种方法是place.new(PUT请求).它需要几个字符串字段,它还需要一个图像.但是我无法让它发挥作用.使用POST请求很简单,但我不知道如何使用PUT以及如何在服务器上获取数据.
谢谢您的帮助!
$curl = curl_init();
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 2);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_BINARYTRANSFER, 1);
curl_setopt($curl, CURLOPT_URL, $this->url);
curl_setopt($curl, CURLOPT_PUT, 1);
curl_setopt($curl, CURLOPT_INFILE, $image);
curl_setopt($curl, CURLOPT_INFILESIZE, filesize($image));
$this->result = curl_exec($curl);
curl_close($curl);
Run Code Online (Sandbox Code Playgroud)
if ( $im_s = file_get_contents('php://input') )
{
$image = imagecreatefromstring($im_s);
if ( $image != '' )
{
$filename = sha1($title.rand(11111, 99999)).'.jpg';
$photo_url = $temp_dir . $filename;
imagejpeg($image, $photo_url);
// upload image
...
}
}
Run Code Online (Sandbox Code Playgroud)
// Correct: /Users/john/Sites/....
// Incorrect: http://localhost/...
$image = fopen($file_on_dir_not_url, …Run Code Online (Sandbox Code Playgroud) 在一个拥有大量流量的新项目中,我们正在思考如何构建我们的Symfony2应用程序以利用缓存,并准备好在未来更积极.我很想知道你的意见.
假设用户向页面请求地点列表.这个页面有:
- list
- common data (title, author, description)
- user data (the user likes the list + other data)
- first 20 places
- common data (title, photo of each place)
- user data (the rates of the user for those places)
Run Code Online (Sandbox Code Playgroud)
HTML可能是这样的:
<html>...
<body>
<header>
...
<!-- Embed the top user menu -->
<esi:include src="http://example.com/profile/menu" />
...
</header>
<content>
...
common data of the list
...
<!-- Embed the common data of the first 20 places, the …Run Code Online (Sandbox Code Playgroud) 我正在使用Symfony 1.2.我有一个对象列表的视图.我可以订购它们,按类别过滤它们,或者移动到下一页(有分页).一切都是用AJAX完成的,所以我不必再次加载所有页面.
我想要实现的是http:// urltopage#page = 1&order = title&cats = 1,2例如; 因此新页面将保存在浏览器历史记录中,并且可以将其粘贴到另一个Web.
我还没有找到获得#part的方法.我知道这只适用于浏览器,但我无法相信我无法通过PHP.我确信有一个简单的解决方案我不知道......
非常感谢!
我在客户端用Javascript做这个.我想改造:
[
{
"id": 10,
"name": "Designer",
"slug": "designer",
"children": [
{
"id": 11,
"name": "UI / Visual Designer",
"slug": "ui-visual-designer",
"children": []
},
...
]
},
{
"id": 1,
"name": "Software Engineer",
"slug": "software-engineer",
"children": [
{
"id": 2,
"name": "Back-End Developer",
"slug": "back-end-developer",
"children": []
},
...
]
},
...
]
Run Code Online (Sandbox Code Playgroud)
进入这个:
[
{
"id": 10,
"text": "Designer"
},
{
"id": 11,
"text": "UI / Visual Designer",
},
{
"id": 1,
"text": "Software Engineer",
},
{
"id": 2, …Run Code Online (Sandbox Code Playgroud) 我正在使用Symfony 1.2.7.我的网站有多种语言,每种语言都在en.example.com,es.example.com这样的子域中.如果用户进入example.com,我想将他重定向到他的语言.我还想支持staging.example.com并重定向到es.staging.example.com和en.staging.example.com,这样我就可以在部署之前测试所有内容.
我有以下代码在index.php和frontend_dev.php上都有效.我的问题是,你能提高吗?有更好或更清洁的方式吗?谢谢!
require_once(dirname(__FILE__).'/../config/ProjectConfiguration.class.php');
$configuration = ProjectConfiguration::getApplicationConfiguration('frontend', 'dev', true);
$context = sfContext::createInstance($configuration);
// get the domain parts as an array
$host = array_reverse(explode('.', $_SERVER['HTTP_HOST']));
list($tld, $domain, $subdomain) = $host;
// determine which subdomain we're looking at
$app = ($subdomain == 'staging') ? $subdomain2=$host[3] : $subdomain;
if(empty($app) || $app == 'www')
{
$browser_languages = $context->getRequest()->getLanguages();
foreach($browser_languages as $language)
{
$allowed_culture = in_array($language, sfConfig::get('app_languagesAvailable'));
if($allowed_culture)
{
$domain = $subdomain ? $subdomain.'.'.$domain : $domain;
$url = 'http://'.str_replace($domain.'.'.$tld, $language.'.'.$domain.'.'.$tld, $_SERVER['HTTP_HOST']).$_SERVER['REQUEST_URI'];
$context->getController()->redirect($url);
break;
}
} …Run Code Online (Sandbox Code Playgroud) 我从数据库中获取UTF8文本,我想只显示前面的$ len个字符(单词结尾).我已经尝试了几个选项,但由于特殊字符(á,é,í,ó等),该功能仍无效.
谢谢您的帮助!
function text_limit($text, $len, $end='...')
{
mb_internal_encoding('UTF-8');
if( (mb_strlen($text, 'UTF-8') > $len) ) {
$text = mb_substr($text, 0, $len, 'UTF-8');
$text = mb_substr($text, 0, mb_strrpos($text," ", 'UTF-8'), 'UTF-8');
...
}
}
Run Code Online (Sandbox Code Playgroud)
编辑以添加示例
如果我截断65个字符的文本,它将返回:
Unjardíndeestiloneoclásicococorcon el ...
如果我更改特殊字符(í,á),则返回:
Un jardin de estilo neoclasico acorde con el Palacio de ...
我确定编码或服务器或php有些奇怪; 但我无法理解!谢谢!
最终解决方案
我正在使用这个UTF8 PHP库,现在一切正常......
我正在建立一个包含几个子列表的列表.当我将鼠标悬停在一个<li>元素上时,我想改变它的风格<li>,而不是它的父母的风格.
您可以在此处查看代码和演示.如果你将鼠标悬停在上面1.1,我只想1.1变成红色.如果我将鼠标悬停在上面1.3.1,我只想1.3.1变成红色.
我有什么需要改变CSS来实现这一目标?
谢谢!
php ×4
symfony ×2
symfony1 ×2
api ×1
caching ×1
css ×1
css3 ×1
curl ×1
esi ×1
html ×1
html5 ×1
iphone ×1
javascript ×1
lift ×1
put ×1
recursion ×1
redirect ×1
reduce ×1
request ×1
rest ×1
routing ×1
scala ×1
silex ×1
subdomain ×1
substring ×1
truncate ×1
unicode ×1
upload ×1
url ×1
utf-8 ×1
varnish ×1