我正在用laravel构建博客应用程序,并为此使用3个表:用户、帖子和评分。用户登录后,除其他外,还可以对帖子进行评分。因此,我在post表中添加了列avgRating来存储每个帖子的平均评分。
我试图在mysql中不使用laravel执行这段代码。
UPDATE posts p
SET p.avgRating=
(SELECT ROUND(AVG(r.rating), 0)
FROM ratings r
WHERE p.id=r.rateable_id)
而且起作用了。我试着用PostController.php写成这样
public
我正在使用安装了TankAuth库的Codeigniter,并试图从swfupload上传到index.php/requests/doUpload,但无法访问通过身份验证的页面。我在网上看到了很多关于类似问题的帖子,并尝试设置$config['sess_match_useragent'] = FALSE;,但仍然没有区别。出于测试目的,我最终跳过了控制器中的登录检查。但是现在我需要从我的控制器访问tankAuth库来获取当前登录的用户ID,它是在我的应用程序中请求的,不能跳过它,我真的需要将登录的用户id传递给那个doUpload模型。我有这样的设置控制器:
function
我尝试为用户构建一个选项,以突出显示在单个帖子底部的“相关帖子”,因此我将此代码放在“content-single.php”的底部:
<div class="related-post">
<?php
$args = array( 'post__in' => array(38328, 38359, 21321) );//it's going to be the user choice, for example, I put three id's
$related_q
我有两个密码。第一个是我在page.php上使用的,它显示了我在管理面板中创建的任何页面的内容。第二个代码在主页上显示我的帖子,只是不确定代码应该放在哪里。
如果我把它放在page.php中,然后相同的内容(帖子)显示在我创建的任何页面上,它就会起作用。我尝试将第二个代码放在home.php和index.php中,同时使用page.php中的第一个代码,但不起作用。
if (have_posts()): while (have_posts()): the_post();
wp_title(''); echo '<br />';
the
我有以下三张桌子
教室
id subject
RegisteredStudents
id user_id class_id
发布
id class_id type attachment
模型
Classroom.php
public function posts()
{
return $this->hasMany(Post::class);
}
RegisteredStudents.php
public function classroom()
{
return $this->belongsTo(Classroom::class);
}
Post.php
pub
我有两个ActiveRecords用户和帖子:
class User < ActiveRecord::Base
has_many :post
end
class Post < MyBase
belongs_to :user
end
我正在尝试获取所有用户的列表,以及所有的帖子。然而,当运行下面的代码时,我会看到有id 1或2的帖子的用户,但是只有这些帖子。我想让这些用户拥有他们所有的帖子。有什么办法吗?
users = User.sorted.references([:posts]).includes([:posts]).where('posts.id=1'