Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Z
zuiketang
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
夏彬
zuiketang
Commits
3c29764a
Commit
3c29764a
authored
Oct 10, 2016
by
xiabin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
添加评论收藏接口
parent
dd2a8a55
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
33 additions
and
11 deletions
+33
-11
Comments.php
src/common/models/Comments.php
+19
-1
HomeController.php
src/frontend/controllers/HomeController.php
+14
-10
No files found.
src/common/models/Comments.php
View file @
3c29764a
...
@@ -3,6 +3,8 @@
...
@@ -3,6 +3,8 @@
namespace
common\models
;
namespace
common\models
;
use
Yii
;
use
Yii
;
use
yii\behaviors\TimestampBehavior
;
use
yii\db\ActiveRecord
;
/**
/**
* This is the model class for table "comments".
* This is the model class for table "comments".
...
@@ -25,13 +27,29 @@ class Comments extends \yii\db\ActiveRecord
...
@@ -25,13 +27,29 @@ class Comments extends \yii\db\ActiveRecord
return
'comments'
;
return
'comments'
;
}
}
/**
* @inheritdoc
*/
public
function
behaviors
()
{
return
[
[
'class'
=>
TimestampBehavior
::
className
(),
'attributes'
=>
[
ActiveRecord
::
EVENT_BEFORE_INSERT
=>
[
'created_at'
],
],
// if you're using datetime instead of UNIX timestamp:
// 'value' => new Expression('NOW()'),
],];
}
/**
/**
* @inheritdoc
* @inheritdoc
*/
*/
public
function
rules
()
public
function
rules
()
{
{
return
[
return
[
[[
'user_id'
,
'course_id'
,
'parent_id'
,
'content'
,
'ip'
,
'created_at'
],
'required'
],
[[
'user_id'
,
'course_id'
,
'parent_id'
,
'content'
,
'ip'
],
'required'
],
[[
'user_id'
,
'course_id'
,
'parent_id'
,
'created_at'
],
'integer'
],
[[
'user_id'
,
'course_id'
,
'parent_id'
,
'created_at'
],
'integer'
],
[[
'content'
],
'string'
],
[[
'content'
],
'string'
],
[[
'ip'
],
'string'
,
'max'
=>
32
],
[[
'ip'
],
'string'
,
'max'
=>
32
],
...
...
src/frontend/controllers/HomeController.php
View file @
3c29764a
...
@@ -37,7 +37,7 @@ class HomeController extends \yii\web\Controller
...
@@ -37,7 +37,7 @@ class HomeController extends \yii\web\Controller
'allow'
=>
TRUE
,
'allow'
=>
TRUE
,
'actions'
=>
[
'comments'
],
'actions'
=>
[
'comments'
],
'roles'
=>
[
'@'
],
'roles'
=>
[
'@'
],
'verbs'
=>
[
'
GE
T'
]
'verbs'
=>
[
'
POS
T'
]
],
],
],
],
]
]
...
@@ -51,8 +51,6 @@ class HomeController extends \yii\web\Controller
...
@@ -51,8 +51,6 @@ class HomeController extends \yii\web\Controller
}
}
public
$enableCsrfValidation
=
FALSE
;
/**
/**
* 点赞或者取消点赞
* 点赞或者取消点赞
* @param $coursewareId
* @param $coursewareId
...
@@ -121,16 +119,21 @@ class HomeController extends \yii\web\Controller
...
@@ -121,16 +119,21 @@ class HomeController extends \yii\web\Controller
*/
*/
public
function
actionComments
()
public
function
actionComments
()
{
{
$this
->
enableCsrfValidation
=
FALSE
;
$request
=
Yii
::
$app
->
request
;
$request
=
Yii
::
$app
->
request
;
if
(
$request
->
isAjax
)
{
if
(
$request
->
isAjax
)
{
$parentId
=
$request
->
post
(
'parent-id'
);
$parentId
=
$request
->
post
(
'parent-id'
);
$co
mments
=
Html
::
encode
(
$request
->
post
(
'comments
'
));
$co
ntent
=
Html
::
encode
(
$request
->
post
(
'content
'
));
$courseId
=
$request
->
post
(
'course-id'
);
$courseId
=
$request
->
post
(
'course-id'
);
//验证数据是否正常
if
(
$parent
=
Comments
::
existById
(
$courseId
)
or
//0代表为一级评论不需要验证
Course
::
existById
(
$courseId
)
or
if
(
$parentId
==
0
)
{
$courseId
===
NULL
$parentStatus
=
TRUE
;
}
else
{
$parentStatus
=
Comments
::
existById
(
$parentId
);
}
if
(
$parentStatus
and
Course
::
existById
(
$courseId
)
and
$content
!==
NULL
)
{
)
{
$userId
=
Yii
::
$app
->
user
->
identity
->
getId
();
$userId
=
Yii
::
$app
->
user
->
identity
->
getId
();
...
@@ -138,9 +141,10 @@ class HomeController extends \yii\web\Controller
...
@@ -138,9 +141,10 @@ class HomeController extends \yii\web\Controller
$comments
->
user_id
=
$userId
;
$comments
->
user_id
=
$userId
;
$comments
->
parent_id
=
$parentId
;
$comments
->
parent_id
=
$parentId
;
$comments
->
course_id
=
$courseId
;
$comments
->
course_id
=
$courseId
;
$comments
->
content
=
$content
;
$comments
->
ip
=
Utils
::
getRealIP
();
$comments
->
ip
=
Utils
::
getRealIP
();
$result
=
$comments
->
save
();
$result
=
$comments
->
save
();
Utils
::
ajaxResponse
(
$result
);
Utils
::
ajaxResponse
(
$result
,
(
$result
===
FALSE
)
?
$comments
->
getErrors
()
:
NULL
);
}
else
{
}
else
{
throw
new
InvalidParamException
(
'参数错误'
);
throw
new
InvalidParamException
(
'参数错误'
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment