假设我有一个尚未定义的变量$ var.为什么我没有收到此声明的错误:
if ( isset($var) && $var ){
// something
} else {
// do something else
}
Run Code Online (Sandbox Code Playgroud)
如果没有设置,你如何检查某些内容是否正确"&& $ var"?isset()是否对if语句执行了某些操作.当然这应该回归:
Notice: Undefined variable:$var
Run Code Online (Sandbox Code Playgroud) <div class="container">
<div class="site_content">
some stuff, images etc
</div>
</div>
.container{
background-color:#333;
}
Run Code Online (Sandbox Code Playgroud)
我想要的是.container div的不透明度为80%,但.site_content的内容为100%
设置css不透明度会影响所有子元素.有办法做到这一点吗?用jQuery?
由于将如何使用,我宁愿避免使用另一个透明div来定位以实现效果的技术.
我想存储一些特定于应用程序的值,例如:
我到目前为止找到的最近的是http://symfony.com/doc/2.0/cookbook/bundles/best_practices.html#configuration
如果我用app/config/parameters.ini它会看起来像:
[flickr]
callbackUrl = http://example.com/approve
requestTokenUrl = http://www.flickr.com/services/oauth/request_token
consumerKey = 123a1237a29b123a5541232e0279123
[app]
default_layout = 2
Run Code Online (Sandbox Code Playgroud)
这些应该在不同的包中以及模板中提供
INSERT INTO `tableA`
SELECT `Col1`,
`Col2`,
NOW()
FROM `tableB`
WHERE tableA.Col1 is not already in tableB.Col1
Run Code Online (Sandbox Code Playgroud)
我无法正确获取WHERE子句以确保从tableA复制的记录只出现在表B中一次...
我有一个父类:
Abstract Class Base {
function __construct($registry) {
// stuff
}
}
Run Code Online (Sandbox Code Playgroud)
然后,我至少有2个类扩展该类
class Cms extends Base {
// a few functions here
}
Run Code Online (Sandbox Code Playgroud)
还有这个
class Index extends Base {
// a few functions here
}
Run Code Online (Sandbox Code Playgroud)
对于CMS类,用户需要登录.会话已经启动,我想通过使用会话var来检查用户是否已登录.所以我想做的是:
class Cms extends Base {
function __construct()
{
// check the user session is valid
}
// a few functions here
}
Run Code Online (Sandbox Code Playgroud)
但是当然会覆盖父构造类及其设置的所有内容.有没有办法让一个__construct()类型的方法可以在子类中定义?
require_once('Class.php');
$myArray = array(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15); // etc
Run Code Online (Sandbox Code Playgroud)
哪个是对的?
foreach($myArray as $key => $val) {
$class = new Class();
$result = $class->someMethod($val);
}
Run Code Online (Sandbox Code Playgroud)
要么
$class = new Class();
foreach($myArray as $key => $val) {
$result = $class->someMethod($val);
}
Run Code Online (Sandbox Code Playgroud)
使用http://simplepie.org/wiki/reference/simplepie/get_items编辑更具体
$aFeeds = array(rssFeed1,rssFeed2,rssFeed3,...);
foreach($aFeeds as $key => $feedURL) {
$feed->set_feed_url(feedURL);
$feed->init();
$feed->get_items(0, 5);
}
Run Code Online (Sandbox Code Playgroud) 我想从数据库中获取数据并将其显示在模板中.我通常会在控制器内执行此操作并将该数据作为变量传递,但是我想使用相同的方法获取不同数量的数据,具体取决于调用该方法的模板.我看过嵌入式控制器,但我只想要数据,而不是渲染HTML http://symfony.com/doc/2.0/book/templating.html#embedding-controllers
例
{# views/template1.html.twig #}
{% for item in FetchDBdata('someParam', 20) %}
{{ item.name }}
{{ item.title }}
{% endfor %}
{# views/template2.html.twig #}
{% for item in FetchDBdata('someOtherParam', 40) %}
{{ item.name }}
{{ item.title }}
{% endfor %}
Run Code Online (Sandbox Code Playgroud)
FetchDBdata('someParam', 40)应用程序中的服务类位于何处
当cap deploy我的Symfony2项目,然后登录到我的服务器,我看到dev(app_dev.php)运行正常但prod版本(app.php)没有.
错误是
[Tue Jan 03 14:31:48 2012] [error] [client xxx.xxx.xxx.xxx] PHP Fatal error: Uncaught exception 'RuntimeException' with message 'Failed to write cache file "/var/www/example/prod/releases/20120103202539/app/cache/prod/classes.php".' in /var/www/example/prod/releases/20120103202539/app/bootstrap.php.cache:1079\nStack trace:\n#0 /var/www/example/prod/releases/20120103202539/app/bootstrap.php.cache(1017): Symfony\\Component\\ClassLoader\\ClassCollectionLoader::writeCacheFile('/var/www/example/p...', '<?php ????name...')\n#1 /var/www/example/prod/releases/20120103202539/app/bootstrap.php.cache(682): Symfony\\Component\\ClassLoader\\ClassCollectionLoader::load(Array, '/var/www/example/p...', 'classes', false, false, '.php')\n#2 /var/www/example/prod/releases/20120103202539/web/app.php(10): Symfony\\Component\\HttpKernel\\Kernel->loadClassCache()\n#3 {main}\n thrown in /var/www/example/prod/releases/20120103202539/app/bootstrap.php.cache on line 1079
Run Code Online (Sandbox Code Playgroud)
查看最近部署的缓存目录,我看到:
drwxrwxrwx 4 root root 4096 Jan 3 14:28 .
drwxrwxr-x 5 root root 4096 Jan 3 14:28 ..
drwxr-xr-x 6 www-data www-data 4096 Jan 3 14:28 dev
drwxrwxr-x 7 …Run Code Online (Sandbox Code Playgroud) <!-- HTML -->
<section class="row slide">
<div class="span4">
<h1>
<span>Some</span>
<br />
<span>Title</span>
</h1>
</div>
</section>
<section class="row slide">
<div class="span4">
<h1>
<em>Some emphasis</em>
<br />
<span>Some</span>
<br />
<span>Title</span>
</h1>
</div>
</section>
<section class="row slide">
<div class="span4">
<h1>
<em>Some other emphasis</em>
<br />
<span>Some</span>
<br />
<span>Title</span>
</h1>
</div>
</section>
/* CSS */
section h1 span:first-child{
color:#FF0033;
}
Run Code Online (Sandbox Code Playgroud)
我试图在容器<span>中的每个<h1>标记中定位第一个,<section>但是一旦<span>它不是第一个子元素(比如<em>),那么它就不应用规则.
我怎样才能获得价值imgWidth?这给了我undefined.
somejQueryMethod(function() {
var imgWidth;
$("<img/>").attr(
"src",
$("#SomeImgSelector").attr("src")
).load(function() {
imgWidth = this.width;
});
// use imgWidth here
// imgWidth is undefined here
});
Run Code Online (Sandbox Code Playgroud)
背景信息:从这个SO问题我假设,正如
imgWidth在load()方法之外定义的那样,它总是在外面可用load().这让我想知道为什么定义imageWidth那里而不是load()?
php ×5
symfony ×3
class ×2
jquery ×2
capifony ×1
capistrano ×1
css ×1
css3 ×1
deployment ×1
html ×1
html5 ×1
insert ×1
javascript ×1
loops ×1
opacity ×1
parameters ×1
sql ×1
transparency ×1
twig ×1