phpthis用法,php中,一个类中,方法内调用另一个方法?

用户投稿 137 0

关于“php_$this用法”的问题,小编就整理了【4】个相关介绍“php_$this用法”的解答:

php中,一个类中,方法内调用另一个方法?

示例

class Test{

function aa(){

$this->bb(); //使用$this变量表示当前类

}

function bb(){

echo "引用过去了";

}

}

类使用方式

$class = new Test();

$class->a();

php高端功能?

1.使用Per-Class常量。

用途:可以在不需要初始化该类的情况下使用:

例子:

class Man //定义Man类

{

const birthday = 19960101; //定义常量变量

}

//使用const修饰的变量,我们可以通过::操作符对其进行访问。例如:

echo Man::birthday;

//使用const修饰的变量是无法进行修改的,例如:

// Man::birthday=19990101;

//上面那句是会报语法错误的。

?>

执行结果:打印出变量值 也就是19960101

2.对静态方法的实现

用途:PHP可以在方法前面使用static关键字,该方法就可以在未初始化类的情况下通过类名::来进行调用,类似于上面。例如:

<?php

class Man //创建一个Man类

{

static function boy() //创建静态方法

{

return 'boy'; //函数返回字符串boy

}

}

echo Man::boy(); //打印函数的返回值,也就是boy

//但是在静态方法中,是不能使用this关键字的。因为可能会没有可以引用的对象实例

//通俗点说,就是一般我们调用函数是使用obj->method(),而$this就是当前的对象,但是因为

跪求、在php中怎么用redirect实现页面跳转?

首先redirect不是php内置的函数。而是thinkphp框架里的

点击函数可以看到最终是:

header('Location: XXX/');的过滤

使用方法可以查看手则

// 跳转到 edit 操作

$this->redirect('edit');

// 跳转到 UserAction下的edit 操作

$this->redirect('User/edit');

// 跳转到 Admin分组默认模块默认操作

$this->redirect('Admin/');

CI框架整合smarty步骤详解?

smarty的模板机制很强大,一般情况下CI无需整合其他模板标签,因为PHP本身就是一种标签,简单易用。codeigniter整合smarty教程(我用的都是最新版本)如下:

第一步:下载codeigniter最新版本:

第二步:下载smarty最新版本:

第三步:

配置步骤:

(1)将smarty拷贝到application/libraries下,然后再根目录下下新建templates,templates_c,config,cache目录,结构如下:

(2)入口文件新增:define('ROOT', dirname(__FILE__));

(3)libraries下新建CI_Smarty.php

$value) { $this->$key = $value; } } else { //ROOT是Codeigniter在入口文件index.php定义的本web应用的根目录 $this->template_dir = $template_dir ? $template_dir : ROOT . '/templates'; $this->compile_dir = $compile_dir ? $compile_dir : ROOT . '/templates_c'; $this->config_dir = $config_dir ? $config_dir : ROOT . '/config'; $this->cache_dir = $cache_dir ? $cache_dir : ROOT . '/cache'; } } }

到此,以上就是小编对于“php_$this用法”的问题就介绍到这了,希望介绍关于“php_$this用法”的【4】点解答对大家有用。

抱歉,评论功能暂时关闭!