Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
U
UserAdminApi4Tpl
Overview
Overview
Details
Activity
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
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
庄欣
UserAdminApi4Tpl
Commits
52197e33
Commit
52197e33
authored
Oct 12, 2016
by
庄欣
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
分类
parent
9ad2c06e
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
44 additions
and
1 deletions
+44
-1
app/Http/Controllers/Category/Controller/Category.php
+34
-1
public/index.php
+1
-0
routes/api.php
+9
-0
No files found.
app/Http/Controllers/Category/Controller/Category.php
View file @
52197e33
...
...
@@ -7,7 +7,39 @@ class Category extends ControllerBase
{
public
function
pretty
()
{
$data
=
parent
::
index
(
""
,
false
);
empty
(
$query
)
&&
$query
=
request
()
->
getQueryString
();
try
{
$client
=
app
(
"client"
);
$client
->
setUrl
(
$this
->
prefix
.
"?"
.
$query
);
$client
->
setMethod
(
"get"
);
$res
=
$client
->
curl
();
$res
=
$this
->
list_to_tree
(
$res
,
"id"
,
"previous"
);
return
Response
::
success
(
$res
);
}
catch
(
\Exception
$e
)
{
return
Response
::
error
(
$e
->
getMessage
());
}
}
protected
function
list_to_tree
(
$list
,
$pk
=
'id'
,
$pid
=
'pid'
,
$child
=
'child'
,
$root
=
0
)
{
$tree
=
array
();
if
(
is_array
(
$list
))
{
$refer
=
array
();
foreach
(
$list
as
$key
=>
$data
)
{
$refer
[
$data
[
$pk
]]
=&
$list
[
$key
];
}
foreach
(
$list
as
$key
=>
$data
)
{
$parentId
=
$data
[
$pid
];
if
(
$root
==
$parentId
)
{
$tree
[]
=&
$list
[
$key
];
}
else
{
if
(
isset
(
$refer
[
$parentId
]))
{
$parent
=&
$refer
[
$parentId
];
$parent
[
$child
][]
=&
$list
[
$key
];
}
}
}
}
return
$tree
;
}
}
\ No newline at end of file
public/index.php
View file @
52197e33
...
...
@@ -34,6 +34,7 @@ require __DIR__.'/../bootstrap/autoload.php';
*/
header
(
'Access-Control-Allow-Origin:*'
);
header
(
'Access-Control-Allow-Methods: POST, GET, OPTIONS'
);
$app
=
require_once
__DIR__
.
'/../bootstrap/app.php'
;
...
...
routes/api.php
View file @
52197e33
...
...
@@ -115,4 +115,12 @@ Route::group(["prefix" => "sets", 'namespace' => Provider::getNamespace("sets")]
Route
::
delete
(
"/
{
id
}
"
,
"Sets@destory"
);
//解禁
Route
::
put
(
"/
{
id
}
/resume"
,
"Sets@resume"
);
});
Route
::
group
([
"prefix"
=>
"category"
,
'namespace'
=>
Provider
::
getNamespace
(
"category"
)],
function
(){
//列表
Route
::
get
(
"/"
,
"Category@index"
);
//格式化分类
Route
::
get
(
"/pretty"
,
"Category@pretty"
);
});
\ No newline at end of file
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