$this->admin_model->list_user()
我写的大部分时间我的程序在面向对象的PHP。但我这样写...如何制作这样的PHP代码?
$this->hello_world().
上面的代码是CodeIgniter,我认为CakePHP也遵循相同的编码风格。
请给我简单的例子,如何让我的“程序hello_world”像
$this->something->hello_world().
感谢你提前。
苏里亚
$this->admin_model->list_user()
我写的大部分时间我的程序在面向对象的PHP。但我这样写...如何制作这样的PHP代码?
$this->hello_world().
上面的代码是CodeIgniter,我认为CakePHP也遵循相同的编码风格。
请给我简单的例子,如何让我的“程序hello_world”像
$this->something->hello_world().
感谢你提前。
苏里亚
something
只是其具有hello_world()
方法的类型的对象。
所以:
class Something
{
public function hello_world()
{
echo 'Hello, big world!';
// Do work.
}
}
class Program
{
private $something;
public function Run()
{
$this->something = new Something();
$this->something->hello_world()
}
}
$program = new Program();
$program->Run();
它没有什么特别的; $ this-> admin_model是一个包含对象的属性,出于所有目的与$ object-> method();相同。
一步一步的将是这样的:
$this->property = new MyObjectWIthADoItMethod();
$this->property->DoIt();
@orokusaki并不复杂或简单的只是我想知道它是如何工作? – Surya 2010-11-30 06:15:46
@orok将对象作为属性的对象会令人困惑?补充一下,为什么我之前没有注意到这一点?现在我们都必须因为你而放弃OOP! (看看这个评论里有一个interrobang。) – deceze 2010-11-30 06:40:07