我有一个ActiveRecord BaseModel类和许多继承它的类模型.而且我有一个类Bookmark,也是继承的BaseModel.此外,我有Decorator-inherited类,他们实现了特殊的接口来表示单个模型(getModelView(model)方法).这是一些伪代码:
TestModel inherits BaseModel
getName:
return this.name
BookmarkModel inherits BaseModel
BaseModel model
getBookmark:
return this.model
TestDecorator inherits BaseDecorator implements SingleModelViewInterface:
getView(model):
return 'view' //html-view of model
BookmarkDecorator inherits BaseDecorator
getBookmarksView(BookmarkModel[] bookmarks):
foreach(bookmarks > bookmark):
decorator = Relation::getDecoratorByModel(bookmark->getEntityType())
decorator->getView(bookmark->getBookmark())
Run Code Online (Sandbox Code Playgroud)
所以,一切看起来都不错,直到我想稍微更改该书签模型的View.我想要为该视图添加自定义标题.而且我无法在装饰器内部制作它,因为它不仅仅是用于书签.
编辑:所以,问题是 - 似乎我需要一个装饰模式,但我没有任何东西可以继承,因为具体的TestDecorator使用TestModel的特殊方法.所以现在我使用魔术方法(PHP)完成了一些非常糟糕的实现:
class BookmarkedModel {
/** @var BaseEntityModel*/
private $model;
public function __construct(BaseEntityModel $model) {
$this->model = $model;
}
public function getName() {
return 'Bookmark '.$this->model->getName();
}
public function __call($name, …Run Code Online (Sandbox Code Playgroud) 我使用的是通过XAMPP和Microsoft SQL Server 2008 R2(SQLEXPRESS)安装的PHP 5.3.8版.我正确安装了驱动程序(我猜)并将正确的行添加到php.ini中(确切地说是extension = php_pdo_sqlsrv_53_ts_vc9.dll).
我正在尝试连接到服务器,如下所示:
try {
$DBH = new PDO("mssql:host=xxxx;dbname=xxxx", 'xxxx', 'xxxx');
} catch(PDOException $e) {
echo $e->getMessage();
}
Run Code Online (Sandbox Code Playgroud)
我得到了"找不到驱动程序"错误,我已经通过各种方式调整了解决问题的方法.我已经尝试过所有其他类型的驱动程序,但这是Apache在启动时没有给我错误的唯一一个.当我运行phpinfo()时,除了pdo_sqlsrv.log_severity(设置为0)之外,pdo_sqlsrv字段都是空白的.
我从微软那里得到了我的驱动程序,我已经尝试了2.0和3.0
任何建议都会很棒!!
我@font-face在过去一年左右开始使用,因为现在大多数主流浏览器都支持它.我通常只使用1-3种字体,但最常见的是我包括斜体版本,粗体和斜体粗体版本,最多可以容纳几MB的数据(取决于字体).由于我使用EOT,TTF,WOFF和SVG在大多数浏览器中工作,因此文件大小增加了.我不想要太多的带宽(和加载时间),所以我想知道:如果Firefox(或任何浏览器)成功加载文件的EOT版本,该浏览器是否仍会下载所有其他3个或者它将特别忽略休息?
我知道你们中的一些人可能会说"嗯,现在的带宽......",但我仍然希望通过习惯来保持最小化.
我一直在寻找这个问题的答案,但似乎以前没有人能解决这个问题.也许你们中的一些人能够并愿意帮我解决这个问题......那太好了!
我目前正在研究一个mysqli包装器并尝试为已准备好的语句实现自定义结果类,就像我已经为标准查询做的那样!似乎结果是在stmt的"执行"方法中生成的,但我仍然无法理解幕后发生了什么!
有没有办法(或黑客)将生成的结果指向我的结果类而不是普通的mysqli_result,就像使用常规查询一样?
只是为了得到一个想法,这里有一些来自代码的粘贴:
class extended_mysqli extends mysqli
{
public function __construct()
{
call_user_func_array(array(get_parent_class($this), 'mysqli'), func_get_args());
if ( $this->connect_errno )
{
throw new extended_mysqli_exception('database connection failure');
}
}
public function query ($query, $binds = array())
{
if ( empty( $binds ) )
{
if ( $this->real_query($query) )
{
if ( $this->field_count )
{
return new extended_mysqli_result($this, $query); // select, show, describe
}
else return true; // insert, update, delete
}
else return false; // fix
} …Run Code Online (Sandbox Code Playgroud) 我目前正在为chrome的console对象编写一个包装器,以便在Web worker中提供相同的功能,至少目前还不支持日志记录.
一旦工作人员通知主线程,我就会复制日志调用,例如:
Function.prototype.apply.call(console.log, console, [workerLogObject])
Run Code Online (Sandbox Code Playgroud)
此时,chrome识别调用并引用控制台本身(右侧)中的文件,行和列.根据console.log的定义显示的信息使用调用该方法的任何资源 - 在我的例子中是包装器.
回到问题,是否可以在调用console对象的方法时更改文件引用,以便在我的情况下显示像web worker这样的另一个文件?
我需要构建一个生成器,我正在寻找一种方法来缩短这个循环到一行.我尝试枚举但是没有用.
counter=0
for element in string:
if function(element):
counter+=1
yield counter
else:
yield counter
Run Code Online (Sandbox Code Playgroud) 我正在使用PHP 5.2.10和MySQL 5.1.36-Community的Window Vista上运行Moodle测试环境.当我从Moodle 1.9.9升级到2.0时,我收到以下错误.
Error: database driver problem detected
The site administrator should verify server configuration
PHP has not been properly configured with the MySQLi extension so that it can communicate with MySQL. Please check your php.ini file or recompile PHP. MySQLi extension is not available for PHP 4.
Run Code Online (Sandbox Code Playgroud)
我还尝试在config.ini中更改dbtype ='mysqli',但仍然看到相同的错误.
如果您能提供一些解决此错误的建议,我将不胜感激.
先感谢您.
我有一个非常奇怪的问题,无法弄清楚.我正在使用notepad ++,如果我将文件保存为带有希腊字符的文件(字符不是来自数据库),它会在Web浏览器中显示希腊字符作为问号但是如果我将相同的字符文件保存为.html则会正确显示字符.
如果从数据库显示希腊字符,它会正确显示它们而不会出现问题 它也无法在我的共享主机上正常工作,但在我的localhost上工作正常.
我试图以不同的编码保存.php文件,但仍然是同样的问题.我也尝试用utf-8添加php header()和meta标签,但没有运气.
可能是什么问题?谢谢
执行此代码时,我收到“分段错误(核心哑音)”。
#include <pthread.h>
#include <stdio.h>
void function(char *oz){
char *y;
y = (char*)oz;
**y="asd";
return NULL;
}
int main(){
char *oz="oz\n";
pthread_t thread1;
if(pthread_create(&thread1,NULL,function,(void *)oz)){
fprintf(stderr, "Error creating thread\n");
return 1;
}
if(pthread_join(thread1,NULL)){
fprintf(stderr, "Error joining thread\n");
return 2;
}
printf("%s",oz);
return 0;
}
Run Code Online (Sandbox Code Playgroud) 我想知道在使用上述函数调用类方法以使用数组动态填充方法调用时,最佳实践是什么!
我有什么优点和缺点?我的意思是,在某些情况下,RefelectionMethod + invokeArgs 选项似乎比 call_user_funcion 快 40%……但是我错过了什么吗?
谢谢。
根据要求,我将在我需要通过引用的场景中添加一些基准……我知道这是一个非常具体的案例,并且这与上述问题没有严格关系!
class foo { public function bar(&$a, &$b, &$c) { /* */ } }
$t1 = microtime(true);
$arr = array(1,2,3);
$foo = new foo;
$rfl = new ReflectionMethod('foo', 'bar');
for ($i=0; $i < 10000; ++$i)
{
$rfl->invokeArgs($foo, $arr);
}
$t2 = microtime(true);
echo sprintf("\nElapsed reflectionmethod : %f", $t2 - $t1);
$t1 = microtime(true);
$arr = array(1,2,3);
$foo = new foo;
for ($i=0; $i < 10000; ++$i)
{
foreach( $arr as $k …Run Code Online (Sandbox Code Playgroud)