search

Home  >  Q&A  >  body text

Can View in Thinkphp framework reference objects like laravel?

I saw that when others use Laravel to develop, they write all database operations in the Model (get and set, etc.), and then they can directly reference the data when they need to use it in the view, like the following, in the view Add this at the beginning:

   <?php  /** @var Order $Order */?> 

Then you can use $Order->id directly in the template. It feels very convenient. I wonder if there are any problems with using it this way? Can thinkphp do this?

Thinkphp seems to have to bind variables in the control to output on the front end. Is there a similar method?

Thanks!!

PHP中文网PHP中文网2776 days ago414

reply all(1)I'll reply

  • 世界只因有你

    世界只因有你2017-05-16 16:58:47

    There is no similar method, we can only modify the template parsing.

    <?php  /** @var Order $Order */?> 
    

    Is it to instantiate the Order object? You still need to pass in parameters to call and get the properties.
    ThinkPHP can directly $Order = M("Order")->find($id);
    Then $Order.id is used.

    reply
    0
  • Cancelreply