PHP sınıfları dışındaki dosyaları otomatik eklemek için bir şey var mı?

2 Cevap

Sihirli __ özdevinimli_yükle fonksiyonu doğru, yalnızca sınıflar için çalışır? Nasıl şablonları gibi diğer dosyaları hakkında? Ben büyük sorun hakkında hiç umurumda olmayan bir çözüm görmek isteriz "dosyasıdır? Yolu nedir? Onu eklemek zorunda ne zaman?". Büyük bir zaman tasarrufu olacaktır.

Performans? Hey .. yüzleşelim çünkü ... Peki ... Bu durumda ben, performans üzerinde daha hızlı gelişmesini tercih ediyorum, biz yapmak bizim web sitelerinin% 99,99 nadiren neyse ziyaret edilmektedir. Bir milyon ziyaretçi nereden gün geldiğinde, muhtemelen büyük, Inc konum ve bunu geliştirmek için 10 devs ödemek.

Eh, en azından benim çerçevesi için.

2 Cevap

Bir göz atın set_include_path(). Bu size bir dosya eklemek için çalıştığınızda PHP bakacağız hangi bir dizin listesi ayarlamanızı sağlar. Bir Dir tüm şablonları var ise, templates/, sadece can say:

set_include_path(get_include_path() . PATH_SEPARATOR . 'templates');
//...
include 'mytemplate.php';

Ve PHP doğru dosya bulacaksınız. Bu hala bir () içerir gerektirir, ancak yardımcı olur. Ayrıca, hangi açık olmak size iyi bir şeydir dahil dosyaları.

Sen bir daha gidebilirsiniz.

auto_prepend_file ve auto_append_file için php.ini dosyasına bakın.

auto_prepend_file NULL PHP_INI_PERDIR PHP_INI_ALL in PHP <= 4.2.3. auto_append_file NULL PHP_INI_PERDIR PHP_INI_ALL in PHP <= 4.2.3.

auto_prepend_file dize

Specifies the name of a file that is automatically parsed before the main file. The file is included as if it was called with the require() function, so include_path is used.

The special value none disables auto-prepending.

auto_append_file dize

Specifies the name of a file that is automatically parsed after the main file. The file is included as if it was called with the require() function, so include_path is used.

The special value none disables auto-appending.

    Note: If the script is terminated with exit(), auto-append will not occur.