Can View in Thinkphp framework reference objects like laravel?
PHP中文网
PHP中文网 2017-05-16 16:56:47
0
1
406

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中文网

认证高级PHP讲师

reply all(1)
世界只因有你

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.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template