开发者

How to make PHP code like this?

$this->admin_model->list_user()

I am writing most of the time my programs in OOP PHP. but I am writing like this...

$this->hello_world().

The above code is CodeIgniter and I think CakePHP also following same coding style.

Please give me simple example how to make my "hello_world开发者_如何转开发" like

$this->something->hello_world().

Thanks you on advance.

Surya


Its nothing special; $this->admin_model is a property which contains an object, and for all purposes is identical to $object->method();

A step by step would look like:

$this->property = new MyObjectWIthADoItMethod();
$this->property->DoIt();


something is just an object of a type which has hello_world() method.

So:

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();
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜