"Real software engineers work from 9 to 5, because that is the way the job is described in the formal spec. Working late would feel like using an undocumented external procedure."
[ Voor 60% gewijzigd door NMe op 09-04-2006 21:43 ]
'E's fighting in there!' he stuttered, grabbing the captain's arm.
'All by himself?' said the captain.
'No, with everyone!' shouted Nobby, hopping from one foot to the other.
Ik weet alleen niet of hij de PHP pagina uit de adresbalk haalt of echt de fysieke file. In het laatste geval heb je hier niets aan.The filename of the currently executing script, relative to the document root. For instance, $_SERVER['PHP_SELF'] in a script at the address http://example.com/test.php/foo.bar would be /test.php/foo.bar.
More than meets the eye
There is no I in TEAM... but there is ME
system specs
1
2
3
4
5
6
7
8
 | function foo() { if ($_SERVER["REQUEST_URI"] == 'dit.php') { return 'functie aangeroepen vanaf dit.php!'; } else if ($_SERVER["REQUEST_URI"] == 'dat.php') { return 'functie aangeroepen vanaf dat.php!'; } }  | 
[ Voor 14% gewijzigd door [BoSS] op 09-04-2006 21:44 ]
20x 170 Wp (Solar Frontier) op ZZO / 54 graden
Rrrright. How about:B_O_S_S schreef op zondag 09 april 2006 @ 21:43:
Gebruik makend van de informatie in server-variabelen:
PHP:
 1 2 3 4 5 6 7 8 function foo() { if ($_SERVER["REQUEST_URI"] == 'dit.php') { return 'functie aangeroepen vanaf dit.php!'; } else if ($_SERVER["REQUEST_URI"] == 'dat.php') { return 'functie aangeroepen vanaf dat.php!'; } }
1
2
3
 | function foo() { return "functie aangeroepen vanaf " . $_SERVER["REQUEST_URI"]; }  | 
?
Mother, will they like this song?
Uiteraard gaat dat in dit simpele geval goed, maar de topicstarter heeft aangegeven dat hij andere handelingen wil uitvoeren aan de hand van de pagina waar de request vandaan komt. Vandaar deze oplossing. Maar ik moet eerlijk zeggen dat dit wel ruikt naar een scriptrequest, het gebruik van $_SERVER moet toch wel bekend zijn als je met PHP overweg kan?
20x 170 Wp (Solar Frontier) op ZZO / 54 graden
'E's fighting in there!' he stuttered, grabbing the captain's arm.
'All by himself?' said the captain.
'No, with everyone!' shouted Nobby, hopping from one foot to the other.
'E's fighting in there!' he stuttered, grabbing the captain's arm.
'All by himself?' said the captain.
'No, with everyone!' shouted Nobby, hopping from one foot to the other.
Verwijderd
Iemand een idee?Misschien ben ik in mijn TS niet duidelijk geweest. Het probleem is als volgt: elke request naar mijn website wordt mbv. mod_rewrite afgehandeld door index.php. Bijvoorbeeld: site.com/groenten/winter/witlof/30 wordt index.php?groenten/winter/witlof/30. Via een database check kijk ik wat voor type content groenten/winter/witlof is. In dit geval is dat een artikel. Ik include dan vervolgens artikel.inc. In artikel.inc roep ik de functie foo() aan.
Het probleem is dat PHP_SELF of elke andere $_SERVER variabele index.php als requestende pagina geeft. Mijn vraag was of ik automatisch kon herleiden vanaf welke include de request gemaakt wordt.
"Real software engineers work from 9 to 5, because that is the way the job is described in the formal spec. Working late would feel like using an undocumented external procedure."
__FILE__ ?Reveller schreef op maandag 10 april 2006 @ 18:49:
Iemand een idee?
Verwijderd
Wat je beter had kunnen doen, is een (abstracte) class of interface maken met een of andere functie die je aan wilt kunnen roepen. Vervolgens maak je voor verschillende soorten inhoud verschillende classes aan die die class extenden (of interface implementeren). Bij een request maak je een instantie van de juiste class aan en voila.
In je commin.inc hoef je dan alleen maar die methode foo() aan te roepen. Dan zoekt een object zelf verder wel uit wat er nog moet gebeuren.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
 | <?php // common.inc // wil je je script private houden hier common.inc.php van maken function foo() { $included_files = get_included_files(); $calling_page = basename($included_files[0]); if ($calling_page == 'dit.php') { return 'functie aangeroepen vanaf dit.php!'; } else if ($calling_page == 'dat.php') { return 'functie aangeroepen vanaf dat.php!'; } } ?>  | 
Toelichting: het aanroepende bestand is volgens mij altijd het eerste element in de includes-array. Mogelijk pas vanaf PHP5, weet ik niet zeker.
[ Voor 95% gewijzigd door user109731 op 10-04-2006 19:28 . Reden: code wat uitgebreid :) ]
Dat zijn van die undocumented "features" waar je echt ver vanaf wilt blijven als programmeur..Grote prutser schreef op maandag 10 april 2006 @ 19:05:
Of zoiets in je include zetten:
<snip>
Toelichting: het aanroepende bestand is volgens mij altijd het eerste element in de includes-array. Mogelijk pas vanaf PHP5, weet ik niet zeker.
Op zoek naar een nieuwe collega, .NET webdev, voornamelijk productontwikkeling. DM voor meer info
1
2
3
4
5
6
7
8
9
10
 | include_file($request) { /* Do some processing, ends with $type, i.e. article or something like that, then */ define("REQUEST_TYPE", $type); require_once("includes/".$type.".inc"); /* Or */ $include_file = $type.".inc" define("REQUEST_INCLUDE", $include_file); require_once($include_file); }  | 
Maar eerlijkgezegd denk ik dat /me gelijk heeft, en dat dit nogal tekenen zijn van een niet optimaal ontwerp
Grote Prutser: "Wil je je script private houden hier common.inc.php van maken." En wat nu als je php engine op de een of andere manier uitvalt