在thinkphp中,实例化对象有这么几种方法,如果是类,有a和r方法,区别是a方法只是对象的实例化,而r方法是可以同时实例化对象里面的方法的,这里需要去指定,如下面的实例代码:
立即学习“PHP免费学习笔记(深入)”;
<!--?php
namespace Admin\Controller;
use Think\Controller;
class GoodsController extends Controller{
public function showlist(){
//实例化控制器A方法
$test=A("Manager");
echo $test--->test1();
echo "
";
//也可以去跨模块调用
$test_m=A("Home/Goods");
echo $test_m->test();
echo "
";
//R方法可以取执行对应模块下面的
R("Home/Goods/test");
// $this->display();
}
}
立即学习“PHP免费学习笔记(深入)”;
另外我们在Model的数据模型里面,必然需要下面的两种方法,一个是D方法,一个是M方法,前者是实例化数据模型类,而后者则是实例化数据模型的父类。
立即学习“PHP免费学习笔记(深入)”;
<!--?php
namespace Admin\Controller;
use Think\Controller;
class TestController extends Controller{
public function test1(){
$mythinkphp=M("user");
$t=$mythinkphp--->select();
echo "
"; // var_dump($mythinkphp->select()); // echo count($t); // echo "
"; // echo count($t[1]); // echo "
"; // for($i=0; $i<count($t); border="'1px'" br="" echo="" function="" i="0;" is="" pre="" public="" t="new" t2="D("test_1");" table="" temp="$t2->select();" test="" this="" user="D("Test");">
虽然从用法上看不出什么差别,但是内部确实不同的,D方法只实例化定义的数据模型类,而M方法去实例化数据模型的父类。<p> </p><p><span>立即学习</span>“<a href="https://pan.quark.cn/s/7fc7563c4182" style="text-decoration: underline !important; color: blue; font-weight: bolder;" rel="nofollow" target="_blank">PHP免费学习笔记(深入)</a>”;</p><p> </p><p><span>立即学习</span>“<a href="https://pan.quark.cn/s/7fc7563c4182" style="text-decoration: underline !important; color: blue; font-weight: bolder;" rel="nofollow" target="_blank">PHP免费学习笔记(深入)</a>”;</p><p> </p><p><span>立即学习</span>“<a href="https://pan.quark.cn/s/7fc7563c4182" style="text-decoration: underline !important; color: blue; font-weight: bolder;" rel="nofollow" target="_blank">PHP免费学习笔记(深入)</a>”;</p></count($t);>
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号