Views and built-in tags of thinkPHP5.0 framework

Table of contents

 

1. View

2. Built-in tags


1. View

a) load the page

        1. Inherit the system controller class

            return $this->fetch(parameter 1, parameter 2, parameter 3, parameter 4);

            Parameter 1 (string): template rendering
                       parameter 2 (array): template assignment
                       parameter 3 (array): template replacement
                       parameter 4 (array):

        2. Use helper functions

             return view();
                        The parameters of view are the same as fetch

        3. Use the view class (not recommended)

            $view=new View();

            return $view->fetch();

    b) template assignment

        1. The assign method in the controller class

            $this->assign('name',$name);
                       $this->assign('city',$city);

                       load page
                       return view();

        2. Through the fetch method

            return $this->fetch('',['name'=>$name,'city'=>$city]);

        3. Helper function

            return view('',['name'=>$name,'city'=>'西安']);

        4. Object assignment
                        $this->view->name="Haoge";
                        $this->view->city="Linfen";

                        return view();
 

2. Built-in tags

1. Volist cycle

            name The id of the data to be traversed
                       is similar to the value offset in foreach,
                       the starting position of the intercepted data
                       length the number of intercepted data
                       mod odd and even number empty use                        the key number
                       if the data is empty


          2. foreach loop

            name The data item that needs to be traversed
                       , similar to the value key in foreach
                       , similar to the key in foreach

            {foreach name="data" item="val" key="abc"}
                            <p> {$abc} {$val.id} {$val.name}</p>
                       {/foreach}


           3. for loop

            start start value
                       end end value
                       comparison comparison condition
                       step step number
                       name loop variable name default i

            {for start="0" end="10" comparison="elt" step="2" name="abc"}
                               <p>{$abc}</p>
                        {/for}

            {for start="10" end="0" comparison="gt" step="-1"}
                              <p>{$i}</p>
                       {/for}

4. Compare tags

            {eq name="a" value="11"}correct{/eq}
                       {neq name="a" value="11"}correct{/neq}
                       {lt name="a" value="11"}correct {/lt}
                       {gt name="a" value="11"}Correct{/gt}
                       {egt name="a" value="11"}Correct{/egt}
                       {elt name="a" value=" 11"}correct{/elt}
                       {heq name="a" value="11"}correct{/heq}
                       {nheq name="a" value="11"}correct{/nheq}

5、if

            {if condition="$a eq $b"}

                <p>a and b are equal</p>
                       {else /}

                <p>a and b values ​​are not equal</p>

            {/if}


             6、switch

            {switch name="week"}
                              {case value='1'}Monday{/case}
                              {case value='2'}Tuesday{/case}
                              {default /} Sunday
                       {/switch}

7. in and notin are similar

            {in name="week" value="0,1,2,3,4,5,6"}
                             legal data
                       {else /}
                             illegal data
                       {/in}

 8、between 和 notbetween

            {between name="week" value="0,6"}
                            legal data
                        {else/}
                             illegal data
                       {/between}

9、原生PHP
                       {php}
                          echo "123";
                       {/php}

             <?php 
                           echo "456";
                        ?>

おすすめ

転載: blog.csdn.net/qq_43269730/article/details/100022394
おすすめ