我正在尝试使用简单的Chrome扩展程序,但是matches
在我的数据库中为数组提供值时遇到了问题content_scripts
.
{
"name": "My Extension",
"version": "1.0",
"description": "My Extension Experiment",
"browser_action": {
"default_icon": "icon.png",
"default_title": "Ext",
"default_popup": "popup.html"
},
"content_scripts": {
"matches": ["http://*"],
"js": ["scripts.js"]
}
}
Run Code Online (Sandbox Code Playgroud)
当我尝试将此扩展程序加载到Chrome时,我收到以下消息:
无法从'C:\ Users\foo\Desktop\Extensions\bar'加载扩展程序.
"content_scripts"的值无效.
我无法看到关于我的价值的"无效".我要做的是匹配每个URL,因此我的扩展可以操作scripts.js
运行的任何页面的DOM(通过javascript ).我错过了什么,这一切都错了,或者是什么?
更新
发布此问题后,我注意到Google示例与我的示例略有不同,因此我稍微修改了我的代码以反映其语法:
"content_scripts": [{
"matches": ["http://*"],
"js": ["scripts.js"]
}]
Run Code Online (Sandbox Code Playgroud)
话虽这么说,我仍然在尝试加载我的扩展时收到以下错误:
无法从'C:\ Users\foo\Desktop\Extensions\bar'加载扩展程序.
'content_scripts [0] .matches [0]'的值无效.
我正在尝试$this->db
在Kohana中运行一个简单的查询,但是当我尝试在查询中使用表的别名时遇到了一些语法问题:
$result = $this->db
->select("ci.chapter_id, ci.book_id, ci.chapter_heading, ci.chapter_number")
->from("chapter_info ci")
->where(array("ci.chapter_number" => $chapter, "ci.book_id" => $book))
->get();
Run Code Online (Sandbox Code Playgroud)
在我看来,这应该工作得很好.我说"chapter_info"应该被称为"ci",但这并不是出于某种原因.错误很简单:
There was an SQL error: Table 'gb_data.chapter_info ci' doesn't exist -
SELECT `ci`.`chapter_id`, `ci`.`book_id`, `ci`.`chapter_heading`,
`ci`.`chapter_number`
FROM (`chapter_info ci`)
WHERE `ci`.`chapter_number` = 1
AND `ci`.`book_id` = 1
Run Code Online (Sandbox Code Playgroud)
如果我使用完整的表名而不是别名,我会得到预期的结果而不会出错.这需要我写更详细的查询,这是不理想的.
有没有办法在Kohana的查询构建器中为表使用较短的名称?
phpQuery是一个非常好的工具,它在过去解析了格式良好的XHTML和XML文档时帮助了我,但是我最近遇到了一个问题,试图选择在其标记名中有冒号的元素,如下所示:
<isc:thumb><![CDATA[http://example.com/foo_thumb.jpg]]></isc:thumb>
Run Code Online (Sandbox Code Playgroud)
我试图使用该pq()
函数来选择所有这些元素:
foreach ( pq("isc:thumb") as $thumbnail ) {
print pq( $thumbnail )->text();
}
Run Code Online (Sandbox Code Playgroud)
不幸的是,这无济于事.如果我尝试另一个元素,比如标记名id
,则结果会按预期弹出.
是否有专门设计的库或工具来帮助PHP程序员编写Javascript?本质上,将PHP逻辑转换为Javascript逻辑.例如:
$document = new Document($html);
$myFoo = $document->getElementById("foo");
$myFoo->value = "Hello World";
Run Code Online (Sandbox Code Playgroud)
转换为以下输出:
var myFoo = document.getElementById("foo");
myFoo.value = "Hello World";
Run Code Online (Sandbox Code Playgroud)
因此$html
传入的内容最初不会被PHP修改.相反,PHP会将自身转换为Javascript,然后将其附加到$html
变量的末尾,以便在输出变量并将其转换为客户端DOM时运行.
当然,如果也可以派生出更复杂的解决方案,将对象和内部方法转换为javascript-objects等,那将是非常好的.
我正在构建一个最近评论的小列表,并希望链接到评论所放置的实际帖子.不幸的是,没有comment_permalink
或post_permalink
我能找到,所以我想也许会有一个get_permalink()
功能,但是再一次,我找不到http://codex.wordpress.org/Function_Reference/.
从$post->ID
单独的角度来看,我该如何找到该特定帖子的永久链接?并不是说它是完全必要的,但这是我到目前为止所拥有的:
<?php $comments = get_comments( array( 'status'=>'approve', 'number'=>5 ) ); ?>
<p class="recently-posted-comments">Recent Comments</p>
<ul>
<?php foreach ($comments as $comment): $parent = get_post($comment->comment_post_ID); ?>
<li><?php print $comment->comment_author; ?>
on <?php print $parent->post_title; ?></li>
<?php endforeach; ?>
</ul>
Run Code Online (Sandbox Code Playgroud)
我的意图是将其$parent->post_title
转换为永久链接.