我正在尝试使用symfony2设置一个json示例.
我创建了一个测试包,测试实体("信息"),成立了ORM等
的信息(表)具有以下列:ID,标题,文字
,我试图揭露路线*/MYDOMAIN /消息这会将json接口暴露给消息表(一个小列表)
我尝试的第一种方法是:
创建一个MessageController类,它使用Symfony\Component\HttpFoundation\Response并具有如下函数:
public function testAction() {
$response = new Response(json_encode(**code_req_here**));
return $response;
}
Run Code Online (Sandbox Code Playgroud)
并设置如此的路线:
test:
pattern: /test
defaults: { _controller: myProjectmyTestBundle:Message:test, _format: json}
requirements: { _format: (xml|json), _method: GET }
Run Code Online (Sandbox Code Playgroud)
code_req_here? 我试过的第二种方法是使用FOS/RestBundle但是没有按照我的理解正确完成指南,所以
正如我已经发现的那样,Doctrine2" 不支持通过SQL中的"DEFAULT"关键字在列中设置默认值....您可以使用类属性作为默认值 ".
class Product
{
// ...
/**
* @var string $name
*
* @ORM\Column(name="name", type="string", length=255)
*/
private $name = "";
/**
* @var string $sale
*
* @ORM\Column(name="sale", type="boolean")
*/
private $sale = false;
Run Code Online (Sandbox Code Playgroud)
但即使我这样做,生成的CRUD表单仍然要求我填写所有表格.在布尔属性的情况下,这甚至意味着我只能将其设置为true(即1).
难道我做错了什么?
(我知道我可以关闭验证,但我想解决问题,而不是绕过它)
假设当前的URL是 example.com/test/example
让我们说我想链接到 example.com/test/example/another
<a href="/another"> 把我联系到 example.com/another
如何在example.com/test/example/another不必将完整URL放入a标记的情况下链接到?
我正在尝试编译Android SDK附带的Google ApiDemos.但我只能跑去!它让我疯了!!
当我在Eclipse中基于示例(目标1.5或1.6)创建一个新项目并尝试编译和运行时,我得到了将近一千个错误.不是我对教程应用程序的期望!
Description Resource Path Location Type
IRemoteService cannot be resolved RemoteServiceBinding.java /ApiDemos/src/com/example/android/apis/app line 84 Java Problem
IRemoteService cannot be resolved to a type RemoteService.java /ApiDemos/src/com/example/android/apis/app line 92 Java Problem
IRemoteService cannot be resolved to a type RemoteService.java /ApiDemos/src/com/example/android/apis/app line 104 Java Problem
IRemoteService cannot be resolved to a type RemoteService.java /ApiDemos/src/com/example/android/apis/app line 104 Java Problem
IRemoteService cannot be resolved to a type RemoteServiceBinding.java /ApiDemos/src/com/example/android/apis/app line 41 Java Problem
IRemoteService cannot be resolved to a type RemoteServiceBinding.java /ApiDemos/src/com/example/android/apis/app …Run Code Online (Sandbox Code Playgroud) 我在Android中的ListView有问题.当我设置时android:layout_height="wrap_content",ListView只保留一行或两行,我找不到让他"包裹"的方法.
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:gravity="center">
<TextView
android:id="@+id/question"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<ListView android:id="@+id/ListView01"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</ScrollView>
</FrameLayout>
Run Code Online (Sandbox Code Playgroud)
有没有办法实现这个目标?提前致谢!
我有一些静态的html文件,并希望通过mustache.js更改客户端修改内部的静态文本.
似乎这可能是Twitter在github上的小胡子扩展:https://github.com/bcherry/mustache.js
但最近特定的I18n扩展已被删除或更改.
我想象一个解决方案,其中http:/server/static.html?lang=en加载mustache.js和基于lang参数的语言JSON文件data_en.json.
然后小胡子替换{{tags}}发送的数据.
有人可以给我一个例子如何做到这一点?
我有一个应用程序,它将一些数据存储在SQLite DB中.另外我在我的应用程序中进行了大量查询和重新查询.我在其中有大约15个活动.并且所有人都使用数据库来查询数据.但我正在做的是在每个活动中打开我的数据库并在每个活动的onDestroy {...}中关闭它.
问题是onDestroy {...}可能永远不会被调用,有时候我的应用程序会保持很长时间,并且我会从一个活动切换到另一个开放多次我的数据库.
有时我会得到像数据库这样的错误太多次打开而且从未关闭过.
在我从中获取数据并关闭它后,我会尝试完全关闭我的数据库...转到我的下一个活动并重新打开等等.....但问题是在某些活动中我从其他活动......关闭我的数据库并回到那个活动会产生一个强大的力量关闭.
我想做的是在我的应用程序开始时打开我的数据库并在结束时关闭它,但我面临两个问题:
1.我应该让我的SQLiteOpenHelper类成为一个单独的吗?...得到它的一个实例...在我的第一个活动中打开它然后在我的下面的活动中获取我已经打开的数据库的实例/ ???
2.我的应用程序结束了????我应该怎么知道应用程序的结束位置以及关闭数据库的位置.
编辑:
public class DBAdapter extends SQLiteOpenHelper {
public DBAdapter(Context context) {
super(context, DATABASE_NAME, null, 1);
this.myContext = context;
}
public void openDataBase() throws SQLException {
String myPath = DATABASE_PATH + DATABASE_NAME;
db = SQLiteDatabase.openDatabase(myPath, null,
SQLiteDatabase.OPEN_READWRITE);
}
}
Run Code Online (Sandbox Code Playgroud)
这是我班上管理我的DB的一段代码.为了使这个单例,我应该使用一个构造函数:
private DBAdapter()
{
//nothing in here
}
Run Code Online (Sandbox Code Playgroud)
但这对于SQLiteOpenHelper来说是未定义的
EDIT FINAL:这是我按照zirael建议做的:
包com.Server_1;
import android.app.Application;
公共类MyApplication扩展Application {
private static DBAdapter db;
public void onCreate()
{
db=new DBAdapter(getApplicationContext());
db.createDatabase();
db.openDataBase();
}
public static …Run Code Online (Sandbox Code Playgroud) 我正在为Symfony2中的图像大小调整构建一个脚本.
因为我希望能够使用标准的Symfony2响应系统......
$headers = array('Content-Type' => 'image/png',
'Content-Disposition' => 'inline; filename="image.png"');
return new Response($img, 200, $headers); // $img comes from imagecreatetruecolor()
Run Code Online (Sandbox Code Playgroud)
...我需要一个字符串作为回复发送.不幸的是,像imagepngdo这样的函数只会将文件或输出直接写入浏览器,而不是返回字符串.
到目前为止,我能想到的唯一解决方案是
1]将图像保存到临时位置,然后再次读取
imagepng($img, $path);
return new Response(file_get_contents($path), 200, $headers);
Run Code Online (Sandbox Code Playgroud)
2]使用输出缓冲
ob_start();
imagepng($img);
$str = ob_get_contents();
ob_end_clean();
return new Response($str, 200, $headers);
Run Code Online (Sandbox Code Playgroud)
有没有更好的办法?
Log.d(TAG, "Build.VERSION_CODES.ICE_CREAM_SANDWICH: " + Build.VERSION_CODES.ICE_CREAM_SANDWICH);
Run Code Online (Sandbox Code Playgroud)
我写这样的代码,我使用sdk4.0来编译这个android程序,所以它不会导致编译错误.当我在运行Android 2.3.4的手机中运行此程序时,它运行良好.
为什么?我很困惑,版本2.3.4(api级别10)有Build.VERSION_CODES.ICE_CREAM_SANDWICH属性?而当我使用sdk2.3.4时会导致编译错误.
更多
我测试下面这些代码,
private ScaleGestureDetector mScaleGestureDetector;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ECLAIR_MR1) {
mScaleGestureDetector = new ScaleGestureDetector(this, new MyOnScaleGestureListener());
}
Run Code Online (Sandbox Code Playgroud)
这段代码在android 1.6 api 4级上运行良好,但是
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ECLAIR_MR1) {
Log.d(TAG, "getx(0): " + event.getX(0));
}
Run Code Online (Sandbox Code Playgroud)
这个程序在android 1.6 api level 4上运行失败.
他们都运行在android 2.3.4上.
为什么?(在ScaleGestureDetector类中也使用event.getX(0)(因为api级别5))
我测试了一些代码..
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Fragment f = new Fragment();
}
Run Code Online (Sandbox Code Playgroud)
当我在Android 1.6模拟器上运行它时会抛出java.lang.VerifyError,但是在我的手机上运行android 2.3.4它会抛出java.lang.NoClassDefFoundError.
为什么??
我目前在Play商店有一个平板电脑和智能手机运行Android 3.0+(http://tinyurl.com/cnejnjs)的应用程序.为了吸引更多用户,我正在考虑让应用程序在大量设备上运行.
我知道ActionBar Sherlock,这似乎几乎可以做我想要的一切.它没有提供的一件事是我在当前应用程序中使用的搜索小部件.
有没有办法在操作栏中有一个搜索框,它以与默认搜索小部件的工作方式类似的方式更新屏幕上的当前列表片段?
android android-layout android-4.0-ice-cream-sandwich actionbarsherlock android-actionbar