和同事讨论过这是不好的做法.现在我在网上找不到这个例子.
我们有很多数据库对象映射器,并且像这样调用它的函数
(示例) - setId方法获取数据库中的行并将其设置为预定义的属性
class Person {
public static function get($id) {
$object = new Person;
$object->setId($id);
return $object;
}
}
Run Code Online (Sandbox Code Playgroud)
像这样使用它我们可以使用这样的简单结构:(我们从例如一个帖子得到id)
$person = Person::get($id);
Run Code Online (Sandbox Code Playgroud)
代替
$person = new Person;
$person->setId($id);
Run Code Online (Sandbox Code Playgroud)
现在,我的直觉告诉我这是不好的做法.但我无法解释.也许有人在这里可以解释为什么这是,或者不是不好的做法
以下是我们如何使用它的一些其他示例.我们主要用它来吸气.(只是名称,而不是代码.几乎所有这些都只运行一个查询,它可以返回1个对象,然后使用结果的id来使用setId方法)
class CatalogArticle {
public static function get($id) { }
public static function getByArticlenumber($articlenumber) {} //$articlenumber is unique in the database
public static function getRandom() {} //Runs a query returning a random row
}
Run Code Online (Sandbox Code Playgroud) 我整个早上一直在反对这个问题.
我已经建立了与数据源的连接,该数据源返回音频数据(它是一个记录设备,因此数据上没有设置长度.数据只是流入.就像,如果你打开一个流到收音机)
我已经设法在我的代码中接收所有数据包.现在我只需要玩它.我想播放即将发布的数据,所以我不想排队几分钟或者其他什么,我想使用我在那个时刻收到的数据并播放它.
现在我整个上午一直在寻找不同的例子,但没有一个真的被列出来.
在里面
功能,"数据"包是音频包.我尝试使用AVPlayer,MFVideoPlayer进行流媒体播放,但到目前为止我没有任何工作.还试着看看mattgallagher的Audiostreamer,但仍然无法实现它.
这里的任何人都可以提供帮助,有一些(最好)工作实例吗
我正在尝试重写以下网址:
子域应匹配任何子域.同样适用于TLD.两者:http://car.example.com/和http://cat.example.co.uk都应该重写
http://subdomain.example.com/some/dir 访问 http://subdomain.example.nl/some/dir
和 http://example.com/some/dir 到 http://exampkle.nl/some/dir
(也有www.地址)
但是我对htaccess和重写规则的了解一般都不够好:(
我希望你们中的一个人知道解决方案.
PS.我确实尝试过搜索;)
我几乎被困在以下问题的一天,
我使用apt-get install slapd安装了LDAP
并使用以下配置:
include /etc/openldap/schema/core.schema
include /etc/openldap/schema/cosine.schema
include /etc/openldap/schema/inetorgperson.schema
include /etc/openldap/schema/nis.schema
allow bind_v2
loglevel 0
moduleload back_sbdb.la
database bdb
suffix "dc=test,dc=nl"
rootdn "cn=Directory Manager,dc=test,dc=nl"
rootpw test
directory /var/lib/ldap
index objectClass eq
index userPassword eq,pres
index givenName,mail,mobile,sn,title,cn,description eq,sub,pres
index displayName eq,sub,pres
index postalAddress,facsimileTelephoneNumber pres
access to *
by self write
by * read
Run Code Online (Sandbox Code Playgroud)
然后我尝试使用绑定
ldapsearch -D cn=Directory Manager,dc=test,dc=nl -w test
Run Code Online (Sandbox Code Playgroud)
但我仍然收到错误ldap_bind:证书无效(49)
任何人都有任何想法或线索可能是什么?
谢谢你
哪个查询最快:我自己的测试没有显示任何明显的结果:
UPDATE items, brands SET items.brand_id = brands.id WHERE brands.name = 'apple'
Run Code Online (Sandbox Code Playgroud)
--vs--
UPDATE items SET brand_id = (SELECT id FROM brands WHERE name = 'apple')
Run Code Online (Sandbox Code Playgroud)
我无法在Google上找到有关此内容的任何数据; 也许一些SQL专家在这里知道答案?
只看语法,我个人更喜欢第一个.虽然我说的其他人更喜欢第二个(更明显)?
所以我只是尝试调试以下错误:
<script>
$(function() {
div = $('<div />');
div.text('test');
div.hide(0);
div.appendto('body');
});
</script>
Run Code Online (Sandbox Code Playgroud)
当我执行此操作时,显示DIV.尽管我隐藏(在我们添加到DOM之前)它.以下代码:
<script>
$(function() {
div = $('<div />');
div.text('test');
div.hide();
div.appendto('body');
});
</script>
Run Code Online (Sandbox Code Playgroud)
确实隐藏了DIV.
当我进入jQuery的hide函数源代码时,我看到了:
hide: function( speed, easing, callback ) {
if ( speed || speed === 0 ) {
return this.animate( genFx("hide", 3), speed, easing, callback);
} else {
for ( var i = 0, j = this.length; i < j; i++ ) {
var display = jQuery.css( this[i], "display" );
if ( display …Run Code Online (Sandbox Code Playgroud) 我试图使用PHPExcel从excelsheet中读取一个数字.
我有的代码读取数据:
$objReader = PHPExcel_IOFactory::createReaderForFile($upload_file);
$objReader = PHPExcel_IOFactory::createReader('Excel2007');
$objReader->setReadDataOnly(true);
$objPHPExcel = $objReader->load($upload_file);
$objWorksheet = $objPHPExcel->getActiveSheet();
$data = array();
$i = 0;
foreach ($objWorksheet->getRowIterator() as $row) {
if ($i < 1) {
$i++;
continue; //Skip heading titles
}
$cellIterator = $row->getCellIterator();
$cellIterator->setIterateOnlyExistingCells(false);
foreach ($cellIterator as $cell) {
$data [$i] [] = $cell->getValue();
}
$i ++;
Run Code Online (Sandbox Code Playgroud)
代码有效.我读了Excel,所有数据都很好地保存在$ data数组中.问题是在列AI中得到了一个数字(4078500264822).它返回"4078500264820"(见最后0).不管我怎么看.如果我打印整行,我看到值是错误的.当我使用诸如"getCalculatedValue"之类的函数时,结果是一样的.
我认为它与如何在excel中保存字段有关.我把它保存为"数字"类型.在另一排.我保存了相同的号码.这一次作为"文本"(excel抛出关于此的通知).PHPExcel可以读取该数字.我有40张记录表.其中26个单元格的最后一个数字被替换为0.你可以在这里找到一个截断的文件(只有2行) - > http://dl.dropbox.com/u/1458083/excel.xlsx
在基于位置的应用程序中,我们使用MKMapPoints来存储位置,例如当前用户位置.
当我们尝试在MKMapView上使用此位置时,要设置最初显示的区域(放大用户),我们将其转换为CLLocationCoordinate2D
有一种方便的方法:namenly:MKCoordinateForMapPoint,但在测试期间,这给出了奇怪的结果.
MKMapPoint mapPoint = MKMapPointMake(51.96, 6.3); // My area ;)
CLLocationCoordinate2D automagicCoordinate = MKCoordinateForMapPoint(mapPoint);
CLLocationCoordinate2D manualCoordinate = CLLocationCoordinate2DMake(mapPoint.x, mapPoint.y);
Run Code Online (Sandbox Code Playgroud)
我希望automagicCoordinate和manualCoordinate都是完全一样的.但是当我在调试器中检查它时,我得到以下结果:
automagicCoordinate.latitude = (CLLocationDegrees) 85.05
automagicCoordinate.longitude = (CLLocationDegrees) -179.99
manualCoordinate.latitude = (CLLocationDegrees) 51.96
manualCoordinate.longitude = (CLLocationDegrees) 6.3
Run Code Online (Sandbox Code Playgroud)
为什么使用该方法创建的坐标不正确?
ios ×2
php ×2
.htaccess ×1
apache ×1
cllocation ×1
core-audio ×1
hide ×1
iphone ×1
jquery ×1
mkmapview ×1
mysql ×1
objective-c ×1
oop ×1
openldap ×1
performance ×1
phpexcel ×1
sql-update ×1