修改类库
This commit is contained in:
parent
1dcce85c3a
commit
201cb455f5
@ -10,7 +10,9 @@ class Tree
|
||||
foreach ($items as $key => $item) {
|
||||
if ($item[$pidField] == $pid) {
|
||||
$child = self::done($items, $item['id'], $pidField);
|
||||
$item[$children] = count($child) ? $child : [];
|
||||
if (count($child)) {
|
||||
$item[$children] = $child;
|
||||
}
|
||||
$tree[] = $item;
|
||||
}
|
||||
}
|
||||
|
@ -1 +1,24 @@
|
||||
<?php
|
||||
namespace catcher;
|
||||
|
||||
use think\helper\Str;
|
||||
|
||||
class Utils
|
||||
{
|
||||
/**
|
||||
* 字符串转换成数组
|
||||
*
|
||||
* @time 2019年12月25日
|
||||
* @param string $string
|
||||
* @param string $dep
|
||||
* @return array
|
||||
*/
|
||||
public static function stringToArrayBy(string $string, $dep = ','): array
|
||||
{
|
||||
if (Str::contains($string, $dep)) {
|
||||
return explode($dep, trim($string, $dep));
|
||||
}
|
||||
|
||||
return [$string];
|
||||
}
|
||||
}
|
||||
|
@ -2,96 +2,16 @@
|
||||
namespace catcher\base;
|
||||
|
||||
use catcher\CatchAdmin;
|
||||
use catcher\CatchResponse;
|
||||
use think\facade\View;
|
||||
|
||||
abstract class CatchController
|
||||
{
|
||||
protected $data = [];
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->loadConfig();
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @time 2019年11月28日
|
||||
* @param array $data
|
||||
* @param string $template
|
||||
* @return string
|
||||
* @throws \Exception
|
||||
*/
|
||||
protected function fetch(array $data = [], $template = ''): string
|
||||
{
|
||||
$stack = \debug_backtrace(DEBUG_BACKTRACE_PROVIDE_OBJECT, 2);
|
||||
|
||||
$end = end($stack);
|
||||
|
||||
View::config($this->getViewPath($end['class']));
|
||||
|
||||
$this->setLayout();
|
||||
|
||||
$template = $template ? : $this->getTemp($end['class'], $end['function']);
|
||||
|
||||
return View::fetch($template, array_merge($this->data, $data));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @time 2019年12月17日
|
||||
* @param $module
|
||||
* @return array
|
||||
*/
|
||||
protected function getViewPath($module): array
|
||||
{
|
||||
return [
|
||||
'view_path' => CatchAdmin::getViews()[$this->getModule($module)],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @time 2019年12月17日
|
||||
* @return void
|
||||
*/
|
||||
protected function setLayout(): void
|
||||
{
|
||||
$this->data['layout'] = root_path('view') . 'layout.html';
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @time 2019年12月03日
|
||||
* @param $class
|
||||
* @param $func
|
||||
* @return string
|
||||
*/
|
||||
protected function getTemp($class, $func): string
|
||||
{
|
||||
$viewPath = CatchAdmin::getModuleViewPath($this->getModule($class));
|
||||
|
||||
$class = explode('\\', $class);
|
||||
|
||||
$className = lcfirst(end($class));
|
||||
|
||||
if (is_dir($viewPath . $className)) {
|
||||
return sprintf('%s/%s', $className, $func);
|
||||
}
|
||||
|
||||
return $func;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @time 2019年12月03日
|
||||
* @param $class
|
||||
* @return mixed
|
||||
*/
|
||||
protected function getModule($class)
|
||||
{
|
||||
return explode('\\', $class)[1];
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
@ -120,7 +40,7 @@ abstract class CatchController
|
||||
public function __set($name, $value)
|
||||
{
|
||||
// TODO: Implement __set() method.
|
||||
$this->data[$name] = $value;
|
||||
$this->{$name} = $value;
|
||||
}
|
||||
|
||||
public function __get($name)
|
||||
|
@ -50,6 +50,7 @@ trait BaseOptionsTrait
|
||||
return static::onlyTrashed()->find($id);
|
||||
}
|
||||
|
||||
|
||||
return static::where($this->getPk(), $id)->field($field)->find();
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user