我目前正在开发一个PHP Web应用程序,我想知道包含文件(include_once)的最佳方式是什么,它仍然是可维护的代码.通过maintanable我的意思是,如果我想移动一个文件,重构我的应用程序以使其正常工作是很容易的.
我有很多文件,因为我尝试了很好的OOP实践(一个类=一个文件).
这是我的应用程序的典型类结构:
namespace Controls
{
use Drawing\Color;
include_once '/../Control.php';
class GridView extends Control
{
public $evenRowColor;
public $oddRowColor;
public function __construct()
{
}
public function draw()
{
}
protected function generateStyle()
{
}
private function drawColumns()
{
}
}
}
Run Code Online (Sandbox Code Playgroud) 我们有很多类的庞大应用程序.我们目前正在使用Monotouch将此.net应用程序移植到IPad.我们在使用DataContractSerializer时遇到了一些问题,我们想使用Marc Gravell的protobuf-net序列化器.
客户端和服务器之间的通信由WCF服务管理.
WCF服务由暴露给客户端和服务器的一个接口以及服务器上此接口的一个实现组成.
界面看起来像这样:
[ServiceContract]
public interface IMyService
{
[OperationContract]
SomeObject MyFunction(SomeObject myObject);
}
Run Code Online (Sandbox Code Playgroud)
服务器端实现看起来像这样:
[ServiceBehavior(...)]
public class MyService
{
public SomeObject MyFunction(SomeObject myObject)
{
}
}
Run Code Online (Sandbox Code Playgroud)
我们的课程看起来像这样:
[DataContract]
public class MyClass
{
[DataMember]
public int SomeProp {get; set;}
[OnSerialized]
public void OnSerialized(StreamingContext context)
{
}
}
Run Code Online (Sandbox Code Playgroud)
所以这是我的问题:
对我的类,wcf接口和wcf实现做什么改动.
如何将默认WCF DataContractSerializer替换为Protobuf Serializer.
请注意,在monotouch上,我只能访问Protobuf和Protobuf.Meta命名空间.
[编辑] 我找到了一种交换序列化器运行时的方法: 自定义WCF DataContractSerializer
上述解决方案使用DataContractSerializerOperationBehavior.Protobuf-net是否提供此类行为?
我想弄清楚设计我的网址的最佳方式是什么.所以这就是我到目前为止所做的:
account_index:
pattern: /Accounts/
defaults: { _controller: "CoreBundle:Account:index" }
requirements: { _method: get }
account_create:
pattern: /Accounts/
defaults: { _controller: "CoreBundle:Account:create" }
requirements: { _method: post }
account_read:
pattern: /Accounts/{id}
defaults: { _controller: "CoreBundle:Account:show" }
requirements: { _method: get }
account_update:
pattern: /Accounts/{id}
defaults: { _controller: "CoreBundle:Account:update" }
requirements: { _method: put }
account_delete:
pattern: /Accounts/{id}
defaults: { _controller: "CoreBundle:Account:delete" }
requirements: { _method: delete }
Run Code Online (Sandbox Code Playgroud)
在测试了我所做的之后,我意识到更新和删除不起作用(总是调用account_read)...在谷歌搜索我的问题后,我发现所有浏览器都不支持PUT和DELETE方法......可能会在将来放弃.
然后我读到Ruby on rails通过做一些魔术在所有浏览器上支持这两种方法.
所以我想知道,Symfony2可以像ruby一样处理PUT和DELETE吗?我应该使用restful url吗?
我做了一个小函数,在给定的文件位置打开一个WordDocument.我想在文档出现时启用气球.
这是迄今为止的代码:
public static Document OpenWordDocument(object fileName)
{
ApplicationClass application = new ApplicationClass();
object readOnly = false;
object isVisible = true;
object missing = Missing.Value;
application.Visible = true;
Document wordDocument = application.Documents.Open(ref fileName, ref missing, ref readOnly, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref isVisible, ref missing, ref missing, ref missing, ref missing);
wordDocument.TrackRevisions = true;
//Do something here the enable balloons
wordDocument.Activate();
return wordDocument;
}
Run Code Online (Sandbox Code Playgroud)

至

我目前使用DoctrineMongoDbBundle向我的mongodb数据库发出请求.
这是我控制器中的呼叫:
$dm = $this->get('doctrine.odm.mongodb.document_manager');
$entities = $dm->getRepository('MyBundle:Animal')->findBy(array("prop" => "1"));
echo print_r($entities->getQuery());
echo printf(count($entities));
echo get_class($entities);
Run Code Online (Sandbox Code Playgroud)
然后我尝试将$ enitities序列化为json并将其发送给客户端,但它没有用.
回声打印:
Array ( [prop] => 1 )
101
Doctrine\ODM\MongoDB\LoggableCursor0
Run Code Online (Sandbox Code Playgroud)
这意味着查询正确但计数应为"2",类型应为Animal数组.
为什么重定位返回LoggableCursor0而不是Animal数组?
[编辑]它怎么能返回一个动物数组?
[edit]在JSON中返回结果的最佳方法是什么?
我想知道显示所有 MessageHeaders 服务器端的最佳方式是什么。实际上我知道的唯一方法如下:
OperationContext.Current.IncomingMessageHeaders.GetHeader<T>(Name, Namespace)
Run Code Online (Sandbox Code Playgroud)
该方法仅适用于已知的 MessageHeader,但我想在循环中显示它们的值。
谢谢
我对这段代码有些问题.当我运行它时,我希望它不会锁定事务使用的表.为实现此目标,我将隔离级别设置为ReadUncommited.
问题是它仍然锁定表,就像isolationLevel是Serializable一样.我正在使用SQL Server 2008
这是代码:
using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required, new TransactionOptions() { IsolationLevel = System.Transactions.IsolationLevel.ReadUncommitted }))
{
while (true)
{
using (SqlConnection connection = new SqlConnection(ConnectionString))
{
connection.Open();
Console.WriteLine(Transaction.Current.IsolationLevel);
SqlUtils.ExecuteNonQuery(connection, "INSERT INTO test4 (test) VALUES ('ASDASDASD')");
}
Thread.Sleep(1000);
}
scope.Complete();
}
Run Code Online (Sandbox Code Playgroud) c# ×4
php ×3
symfony ×2
wcf ×2
http-delete ×1
include-path ×1
mongodb ×1
ms-office ×1
ms-word ×1
protobuf-net ×1
restful-url ×1
sql-server ×1
url ×1