在我的CakePHP应用程序中,我返回JSON并退出某些请求.这方面的一个例子是尝试作为GET请求访问登录API:
header('Content-Type: application/json');
echo json_encode(array('message'=>'GET request not allowed!'));
exit;
Run Code Online (Sandbox Code Playgroud)
但是我必须在回显前面添加内容类型,以便将其作为JSON发送.否则我在另一端的代码会将其解释为不同.
关于如何解决这个问题的任何想法?或至少改善它.
更新:Cake版本2.3.0
我有以下代码示例:http://jsfiddle.net/sX3w9/
$('.item').on('click', function() {
var checkbox = $(this).find('input');
checkbox.attr("checked", !checkbox.attr("checked"));
$(this).toggleClass('selected');
});
Run Code Online (Sandbox Code Playgroud)
用户应该能够单击其中的div.item和/或复选框,并且应该选中或取消选中该复选框,并从div中添加或删除所选的类.
它在单击div时有效,但单击该复选框会立即再次取消选中它...
如何在Rails中创建一个可选的位置?
我试过了:
@pages = Page
.where(status: params[:status].present? ? params[:status] : 1)
.where(parent_id: nil) if params[:status].blank?
.order(sort_column + ' ' + sort_direction)
Run Code Online (Sandbox Code Playgroud)
但它看起来要退出该区块,而是返回:undefined method 'where' for true:TrueClass.
在我的 Rails 应用程序中,我想验证filter和post_type参数。
两者都是可选的,但如果它们存在,则它们必须具有一个值,并且必须具有与一组有效值中的一个相匹配的值。
在我的控制器中,我有两种检查它们的方法:
def validate_filter
if params.has_key?(:filter)
if params[:filter].present?
if ['popular', 'following', 'picks', 'promoted', 'first-posts'].include?(params[:filter])
return true
else
return false
end
else
return false
end
else
return true
end
end
def validate_post_type
if params.has_key?(:post_type)
if params[:post_type].present?
if ['discussions', 'snaps', 'code', 'links'].include?(params[:post_type])
return true
else
return false
end
else
return false
end
else
return true
end
end
Run Code Online (Sandbox Code Playgroud)
然后在我的主控制器方法中我这样做:
def index
raise ActionController::RoutingError.new('Not Found') unless validate_filter && validate_post_type
...
Run Code Online (Sandbox Code Playgroud)
所以这意味着post_type=会post_type=cam返回 404 但 …
我使用以下代码隐藏并在一堆搜索结果中显示一个框.每个结果都有自己的切换和框来显示和隐藏.我遇到的问题是,单击任何一个切换将显示和隐藏页面上的所有框,而不仅仅是一个结果的框.我怎样才能做到这一点?
谢谢
jQuery(document).ready(function ($) {
$("div.MoreResultsTrigger").click(function (e)
{
$("div.MoreResultsTrigger").next().slideToggle('fast');
});
});
Run Code Online (Sandbox Code Playgroud)
更新代码使用HOVER
$('a.MoreResultsTrigger').hover(
function () {
$(this).next().show();
},
function () {
$(this).next().hide();
}
);
Run Code Online (Sandbox Code Playgroud) 我有以下代码来显示帖子作者的gravatar,但我如何喜欢该用户的作者个人资料呢?
<a title="View posts by ###" href="###"><?php echo get_avatar( $email, $size = '64' ); ?></a>
Run Code Online (Sandbox Code Playgroud)
编辑这是我的index.php文件
<?PHP
get_header();
?>
<script type="text/javascript" src="<?php bloginfo('template_directory'); ?>/js/jquery.masonry.js"></script>
<script type="text/javascript">
jQuery(document).ready(function(){
$('#post-list').masonry({ singleMode: true, itemSelector: 'article', animate: false });
});
</script>
<?php
function MyLoopCode()
{
?>
<article id="post-<?php the_ID(); ?>">
<div class="post-image"></div>
<div class="post-text">
<h2><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
<p class="p-cat">In: <?php the_category('|') ?></p>
<p class="p-author">
<span class="name"><?php the_author_posts_link(); ?></span>
<span class="avatar"><a title="View posts by <?php the_author(); ?>" href="<?php …Run Code Online (Sandbox Code Playgroud) 我想检查查询变量是否存在.然后我会基于该查询值做一些事情.如果它存在且是真的,那就做点什么吧.如果它不存在或为假,请执行其他操作,例如显示404页面.
例如,如果网址是 domain.com?konami=true
if (condition) {
//something
} else {
//show404
}
Run Code Online (Sandbox Code Playgroud) 我已经建立了一个WordPress网站,例如domain.com,我想建立一个Web应用程序,例如chrome.domain.com,它将包含第二个WordPress安装,但该网站在内容方面将完全相同(除了URL)并且有一个不同的主题.
是否有可能做到这一点?有关如何做到这一点的任何建议?也许以某种方式在主网站上为应用程序运行不同的主题?因为我也想让网站再次使用主题在iPhone和iPad上工作,以使它看起来都是原生的.
对此的想法将不胜感激.谢谢.
我有一个双重职责的索引方法,显示帖子列表和查询的帖子列表,也可以有页面,所以你得到像/News/Page/1或/News?query=test
当用户点击帖子时,News/Details/1他们会得到一个简单的ActionLink,将他们带回列表.但是我想要这个链接将它们带回到它们在分页或查询方面所处的实际页面.我怎么能这样做?我不想使用JavaScript历史记录方法.这是我当前的ActionLink:<%=Html.ActionLink("<< Back to News List", "Index")%>这是分页链接的一个例子:<%= Html.RouteLink("<< First Page", "NewsPaging", new { query = ViewData["query"], page = 0 })%>
谢谢
我最近一直在努力学习CakePHP的ACL内容但是一直有困惑,有没有人有完整的版本,比如这里的Cookbook的ACL教程的源和数据库:http://book.cakephp.org/view/1543/Simple -Acl控制应用中
非常感谢它,因为我喜欢在我的localhost上玩一个有效的解决方案.
谢谢
php ×4
cakephp ×2
javascript ×2
jquery ×2
ruby ×2
wordpress ×2
acl ×1
actionlink ×1
activerecord ×1
asp.net-mvc ×1
css ×1
themes ×1