🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: pl.comp.lang.php
Article #230468

Re: parent::__construct() w modelach aplikacji CodeIgniterowych

#230468
From: Kviat
Date: Sun, 13 Jul 2014 18:29
52 lines
2307 bytes
W dniu 2014-07-13 17:18, jivanmukta@poczta.onet.pl pisze:
> Napisałem tak:
>
> <?php
> class Bazowa {
> 	public function __construct() {
> 		echo 'Bazowa';
> 	}
> }
> class Pochodna extends Bazowa {
> }
> $obiekt = new Pochodna();		
>
> i wyświetliło się: Bazowa. Czyli konstruktor jest widoczny w klasie Pochodna.
> Dlaczego w takim razie w przykładowych aplikacja CodeIgnitera programiści wołają konstruktor klasy bazowej CI_Model:
>
> class Sample_model extends CI_Model {
> 	public function __construct() {
> 		parent::__construct();
> 	}
>          ...
> }
>
> Przecież konstruktor Sample_model::__construct w ogóle nie jest potrzebny!
> Proszę o wytłumaczenie.

Bo możesz zrobić tak:

class Sample_model extends CI_Model {
	public function __construct() {
                 cośtamcośtam....
		parent::__construct();
	}
          ...
}

albo tak:

class Sample_model extends CI_Model {
	public function __construct() {
		parent::__construct();
                 cośtamcośtam....
	}
          ...
}

Czyli w konstruktorze potomka zrobić coś przed wywołaniem konstruktora 
rodzica, albo po.

Pozdrawiam
Piotr
Technical Details
Message-ID: <53c2d024$0$2141$65785112@news.neostrada.pl>
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!agh.edu.pl!news.agh.edu.pl!news.cyf-kr.edu.pl!news.nask.pl!news.nask.org.pl!news.unit0.net!news.glorb.com!news-out.readnews.com!news-xxxfer.readnews.com!nx02.iad01.newshosting.com!newshosting.com!newsfeed.neostrada.pl!unt-exc-01.news.neostrada.pl!unt-spo-a-02.news.neostrada.pl!news.neostrada.pl.POSTED!not-for-mail
References: <d396da14-6198-4504-9cb0-2e342f664d97@googlegroups.com>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!agh.edu.pl!news.agh.edu.pl!news.cyf-kr.edu.pl!news.nask.pl!news.nask.org.pl!news.unit0.net!news.glorb.com!news-out.readnews.com!news-xxxfer.readnews.com!nx02.iad01.newshosting.com!newshosting.com!newsfeed.neostrada.pl!unt-exc-01.news.neostrada.pl!unt-spo-a-02.news.neostrada.pl!news.neostrada.pl.POSTED!not-for-mail
Date: Sun, 13 Jul 2014 20:29:58 +0200
From: Kviat <kviat@NIE_DLA_SPAMUneostrada.pl>
User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:24.0) Gecko/20100101 Thunderbird/24.6.0
MIME-Version: 1.0
Newsgroups: pl.comp.lang.php
Subject: Re: parent::__construct() w modelach aplikacji CodeIgniterowych
References: <d396da14-6198-4504-9cb0-2e342f664d97@googlegroups.com>
In-Reply-To: <d396da14-6198-4504-9cb0-2e342f664d97@googlegroups.com>
Lines: 52
Message-ID: <53c2d024$0$2141$65785112@news.neostrada.pl>
Organization: Telekomunikacja Polska
NNTP-Posting-Host: 83.11.130.131
X-Trace: 1405276196 unt-rea-a-02.news.neostrada.pl 2141 83.11.130.131:22251
X-Complaints-To: abuse@news.neostrada.pl
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit