doukongpao0903 2017-10-03 11:02
浏览 55
已采纳

如何在laravel中的控制器中包含刀片视图?

i have a recursive function in my controllers that create a tree view table from an array, in this function i need to include task view when the if condition is true and this view is just a row of table with different param how can i access this view in a right way? problem is in crate_task_view function where i need task view pleas read codes before answering thanks... code is blow:

this is my TaskController

    namespace App\Http\Controllers;

    use App\Task;
    use Illuminate\Http\Request;
    use Illuminate\Support\Facades\DB;

class TaskController extends Controller
{

private static $menu = array(
    'items' => array(),
    'parents' => array()
);
private static $params = [] ;

private static $user_id = 'حامد_تقی_زاده';



public static function create_tree_view($parent, $menu)
{


    $html = "";
    if ( isset( self::$menu['parents'][$parent] ) )
    {

        $html .= "<ul class='tree animate'>";
        foreach ( self::$menu['parents'][$parent] as $itemId )
        {


            $task=[

                'id' => $menu['items'][$itemId]['id'],
                'p_id' => $menu['items'][$itemId]['p_id'],
                'title' => $menu['items'][$itemId]['title'],
                'visitors' => explode( ',' , $menu['items'][$itemId]['visitors'] ),
                'members' => explode( ',' , $menu['items'][$itemId]['members'] ),
                'owners'=> explode( ',' , $menu['items'][$itemId]['owners'] ),
                'start_date' => $menu['items'][$itemId]['start_date'],
                'due_date' => $menu['items'][$itemId]['due_date'],
                'finish_date' => $menu['items'][$itemId]['finish_date'],
                'status' => $menu['items'][$itemId]['status'],
                'priority' => $menu['items'][$itemId]['priority'],
                'forecast_cost' => $menu['items'][$itemId]['forecast_cost'],
                'revenue' => $menu['items'][$itemId]['revenue'],
                'reports_count' => $menu['items'][$itemId]['reports_count'],
                'files_count' => $menu['items'][$itemId]['files_count'],
                'final_cost' => $menu['items'][$itemId]['final_cost'],
                'total_time' => $menu['items'][$itemId]['total_time'],
                'final_report' => $menu['items'][$itemId]['final_report'],
                'created_at' => $menu['items'][$itemId]['created_at'],
                'created_by' => $menu['items'][$itemId]['created_by'],
            ];
            // TASKS WITHOUT CHILD
            if( !isset( self::$menu['parents'][$itemId] ) )
            {

                $html .="<li class='tr animate'>";
                if( in_array( self::$user_id , $task['members'] ) === true && in_array( self::$user_id,$task['owners'] ) === false )
                {//member

                    self::$params = [
                        'permission_level' => 1 ,
                        'parent' => false ,
                        'task' => $task ,
                    ];

                    $html .= /*task view */.'</li>';

                }
                if ( in_array( self::$user_id,$task['owners'] ) === true && in_array( self::$user_id, $task['members'] ) === false )
                {//owner
                    self::$params = [
                        'permission_level' => 2 ,
                        'parent' => false ,
                        'task' => $task ,
                    ];

                    $html .= /*task view */.'</li>';

                }
                if( in_array( self::$user_id, $task['members'] ) === true && in_array( self::$user_id,$task['owners'] ) === true)
                {//both
                    self::$params = [
                        'permission_level' => 3 ,
                        'parent' => false ,
                        'task' => $task ,
                    ];

                    $html .= /*task view */.'</li>';

                }
                if( in_array( self::$user_id,$task['visitors'] ) === true && in_array( self::$user_id, $task['members'] ) === false && in_array( self::$user_id,$task['owners'] ) === false )
                {//visitors
                    self::$params = [
                        'permission_level' => 0 ,
                        'parent' => false ,
                        'task' => $task ,
                    ];

                    $html .= /*task view */.'</li>';

                }
            }

            // TASKS WITH CHILD
            if( isset( self::$menu['parents'][$itemId] ) )
            {
                $html .= "<li class='tr animate'>";
                if( in_array( self::$user_id, $task['members'] ) === true && in_array( self::$user_id,$task['owners'] ) === false )
                {//member
                    self::$params = [
                        'permission_level' => 1 ,
                        'parent' => true ,
                        'task' => $task ,
                    ];

                    $html .= /*task view */.'</li>';
                    $html.="
                    <img onclick='(chevron".$task['id'].")' id='chevron".$task['id']."' class='chevron' src='css/png/chevron-pointing-to-the-left.png'>
                    <input class='checkbox-chevron' id='checkbox".$task['id']."' onclick='switchClopsImgSrc(".$task['id'].")'  type='checkbox' name='subFolder'/>";
                    $html .= self::create_tree_view($itemId,$menu).'</li>';

                }
                if ( in_array( self::$user_id,$task['owners'] ) === true && in_array( self::$user_id, $task['members'] ) === false )
                {//owner
                    self::$params = [
                        'permission_level' => 2 ,
                        'parent' => true ,
                        'task' => $task ,
                    ];

                    $html .= /*task view */.'</li>';
                    $html.="
                    <img onclick='(chevron".$task['id'].")' id='chevron".$task['id']."' class='chevron' src='css/png/chevron-pointing-to-the-left.png'>
                    <input class='checkbox-chevron' id='checkbox".$task['id']."' onclick='switchClopsImgSrc(".$task['id'].")'  type='checkbox' name='subFolder'/>";
                    $html .= self::create_tree_view($itemId,$menu).'</li>';

                }
                if( in_array( self::$user_id, $task['members'] ) === true && in_array( self::$user_id,$task['owners'] ) === true )
                {//both
                    self::$params = [
                        'permission_level' => 3 ,
                        'parent' => true ,
                        'task' => $task ,
                    ];
                    $html .= /*task view */.'</li>';
                    $html.="
                    <img onclick='(chevron".$task['id'].")' id='chevron".$task['id']."' class='chevron' src='css/png/chevron-pointing-to-the-left.png'>
                    <input class='checkbox-chevron' id='checkbox".$task['id']."' onclick='switchClopsImgSrc(".$task['id'].")'  type='checkbox' name='subFolder'/>";
                    $html .= self::create_tree_view($itemId,$menu).'</li>';


                }
                if( in_array( self::$user_id,$task['visitors'] ) === true && in_array( self::$user_id, $task['members'] ) === false && in_array( self::$user_id,$task['owners'] ) === false )
                {//visitors
                    self::$params = [
                        'permission_level' => 0 ,
                        'parent' => true ,
                        'task' => $task ,
                    ];
                    $html .= /*task view */.'</li>';
                    $html.="
                    <img onclick='(chevron".$task['id'].")' id='chevron".$task['id']."' class='chevron' src='css/png/chevron-pointing-to-the-left.png'>
                    <input class='checkbox-chevron' id='checkbox".$task['id']."' onclick='switchClopsImgSrc(".$task['id'].")'  type='checkbox' name='subFolder'/>";
                    $html .= self::create_tree_view($itemId,$menu).'</li>';


                }

            }
        }
        $html .= "</ul>";
    }
    return $html;
}


public static function create_array()
{
    $tasks = DB::table('tasks')->where('visitors', 'like', '%'.self::$user_id.'%')->orderBy('p_id' , 'id')->get();

    $tasks = json_decode( $tasks,true );


    for ( $i=0 ; $i < count( $tasks ) ;  $i++ )
    {
        // Create current menus item id into array
        self::$menu['items'][$tasks[$i]['id']] = $tasks[$i];

        // Creates list of all items with children
        self::$menu['parents'][$tasks[$i]['p_id']][] = $tasks[$i]['id'];
    }

    return view('home');
}

public static function test(){

    return self::create_tree_view( 0 , self::$menu );
}

}

this is my home view

<!DOCTYPE html>
<html lang="{{ app()->getLocale() }}">
<head>
    <meta charset="utf-8">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">

    <link href="{{ asset('css/styles.css') }}" rel="stylesheet">
</head>
<body>

    @php
        use App\Http\Controllers\TaskController;
        echo TaskController::test();
    @endphp


</body>
</html>

and this is my tasks view

<div class="row">
    <!--
            # # # # # # # # # # # # # # # # # # # # # # # # # # #
            #                                                   #
            # task-controls contains buttons for task actions   #
            #                                                   #
            # # # # # # # # # # # # # # # # # # # # # # # # # # #
    -->
    <div class="task-controls td">

        <div class="edit">
            <div class="action">
                <i onclick='' class='fa fa-pencil toolbar-icons' aria-hidden='true'></i>
            </div>
            <div class="description" id="edit-description">
                <span id="edit-tooltip">ویرایش</span>
            </div>
        </div>

        <div class="upload">
            <div class="action">
                <i onclick='' class='fa fa-upload toolbar-icons' aria-hidden='true'></i>
            </div>
            <div class="description" id="upload-description">
                <span id="upload-tooltip">آپلود</span>
            </div>
        </div>

        <div class="files">
            <div class="action">
                <i onclick='' class='fa fa-folder-o toolbar-icons' aria-hidden='true'></i>
            </div>
            <div class="description" id="files-description">
                <span id="files-tooltip">فایل ها</span>
            </div>
        </div>

        <div class="reports">
            <div class="action">
                <i onclick='' class='fa fa-file-text-o toolbar-icons' aria-hidden='true'></i>
            </div>
            <div class="description" id="reports-description">
                <span id="reports-tooltip">گزارش</span>
            </div>
        </div>

        <div class="letters">
            <div class="action">
                <i onclick='' class='fa fa-envelope-o toolbar-icons' aria-hidden='true'></i>
            </div>
            <div class="description" id="letters-description">
                <span id="letters-tooltip">نامه</span>
            </div>
        </div>

        <div class="search">
            <div class="action">
                <i onclick='' class='fa fa-search toolbar-icons' aria-hidden='true'></i>
            </div>
            <div class="description" id="search-description">
                <span id="search-tooltip">جستجو</span>
            </div>
        </div>

        <div class="save" style="display:none">
            <div class="action">
                <i onclick='' class='fa fa-floppy-o toolbar-icons' aria-hidden='true'></i>
            </div>
            <div class="description" id="save-description">
                <span id="save-tooltip">ذخیره</span>
            </div>
        </div>

        <div class="cancel" style="display:none">
            <div class="action">
                <i onclick='' class='fa fa-times toolbar-icons' aria-hidden='true'></i>
            </div>
            <div class="description" id="cancel-description">
                <span id="cancel-tooltip">لغو</span>
            </div>
        </div>

        <div class="active" style="display:none">
            <div class="action">
                <i onclick='' class='fa fa-check toolbar-icons' aria-hidden='true'></i>
            </div>
            <div class="description" id="active-description">
                <span id="active-tooltip">فعالسازی</span>
            </div>
        </div>

        <div class="sub-task">
            <div class="action">
                <i onclick='' class='fa fa-arrow-left toolbar-icons' aria-hidden='true'></i>
            </div>
            <div class="description" id="sub-task-description">
                <span id="sub-task-tooltip">زیرگروه</span>
            </div>
        </div>

    </div>


    <!--
            # # # # # # # # # # # # # # # # # # #
            #                                   #
            # content-row contains task content #
            #                                   #
            # # # # # # # # # # # # # # # # # # #
    -->
    <div class="content-row">
        <div id="title{{$tasks['id']}}" class="content-container td">
            <div class="title one content-div">{{ $params['task']['title'] }}</div>
        </div>

        <div id="vistors{{$tasks['id']}}" class="content-container td">
            <div class="visitors two content-div">{{$tasks['visitors']}}</div>
        </div>

        <div id="members{{$tasks['id']}}" class="content-container td">
            <div class="members three content-div">{{$tasks['members']}}</div>
        </div>

        <div id="owners{{$tasks['id']}}" class="content-container td">
            <div class="owners four content-div">{{$tasks['owners']}}</div>
        </div>

        <div id="start-date{{$tasks['id']}}" class="content-container td">
            <div class="start-date five content-div">{{$tasks['start_date']}}</div>
        </div>

        <div id="due-date{{$tasks['id']}}" class="content-container td">
            <div class="due-date six content-div">{{$tasks['due_date']}}</div>
        </div>

        <div id="finish-date{{$tasks['id']}}" class="content-container td">
            <div class="finish-date seven content-div">{{$tasks['finish_date']}}</div>
        </div>

        <div id="status{{$tasks['id']}}" class="content-container td">
            <div class="status eight content-div">{{$tasks['status']}}</div>
        </div>

        <div id="forecast-cost{{$tasks['id']}}" class="content-container td">
            <div class="forecast-cost nine content-div">{{$tasks['forecast_cost']}}</div>
        </div>

        <div id="final-cost{{$tasks['id']}}" class="content-container td">
            <div class="final-cost ten content-div">{{$tasks['final_cost']}}</div>
        </div>

        <div id="revenue{{$tasks['id']}}" class="content-container td">
            <div class="revenue eleven content-div">{{$tasks['revenue']}}</div>
        </div>

        <div id="total-time{{$tasks['id']}}" class="content-container td">
            <div class="total-time twelve content-div">{{$tasks['total_time']}}</div>
        </div>

        <div id="priority{{$tasks['id']}}" class="content-container td">
            <div class="priority thirteen content-div">{{$tasks['priority']}}</div>
        </div>
    </div>
</div>

  • 写回答

1条回答 默认 最新

  • dsm13698679318 2017-10-03 11:05
    关注

    Replace

     $html .= /*task view */.'</li>';
    

    With

     $html .= view('task.view.name')->render().'</li>';
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 ensp,用局域网解决
  • ¥15 Python语言实验
  • ¥15 我每周要在投影仪优酷上自动连续播放112场电影,我每一周遥控操作一次投影仪,并使得电影永远不重复播放,请问怎样操作好呢?有那么多电影看吗?
  • ¥20 电脑重启停留在grub界面,引导出错需修复
  • ¥15 matlab透明图叠加
  • ¥50 基于stm32l4系列 使用blunrg-ms的ble gatt 创建 hid 服务失败
  • ¥150 计算DC/DC变换器平均模型中的参数mu
  • ¥25 C语言代码,大家帮帮我
  • ¥15 请问以下文字内容及对应编码是用了什么加密算法或压缩算法呢?
  • ¥50 关于#html5#的问题:H5页面用户手机返回的时候跳转到指定页面例如(语言-javascript)