No0ne Posted November 22, 2010 Report Share Posted November 22, 2010 (edited) Nedaudz aplauzos sada situacija: ir 3 faili: include.php, header.php un details.php details.php incluudo include.php, savukart ieksh include.php ir funkcija, kuru izsauc no details.php un caur to tiek inkludots ari header.php tas, ko es velos izdarit ir, details.php nodefinet mainigo $mainigais, un ieksh header.php vinu izsaukt, piemeram funkcija($mainigais);, es vinu defineju ieksh details.php, jo katrai lapai (index utt) bus savs $mainigais. Nu, luuk - visadi izmeginajos nekaa nesanaca, ceru uz palidzibu :) PS un jaa vinu ir jaizsauc tiesi caur header.php, jo mainigajam jabut ieksh headera nevis pec taa. Edited November 22, 2010 by No0ne Quote Link to comment Share on other sites More sharing options...
rATRIJS Posted November 22, 2010 Report Share Posted November 22, 2010 http://php.net/manual/en/language.variables.scope.php Quote Link to comment Share on other sites More sharing options...
No0ne Posted November 22, 2010 Author Report Share Posted November 22, 2010 http://php.net/manual/en/language.variables.scope.php un uz ko man tiesi tur jaskatas? global man nestrada, jo es ieks details.php inkludoju include.php nevis otradi un kaut kadu papildus failu includot nav risinajums Quote Link to comment Share on other sites More sharing options...
rATRIJS Posted November 22, 2010 Report Share Posted November 22, 2010 Paraadi kaa tu izmanto global. Eniivei - tas nav forshs risinaajums. Konstante neder? http://uk3.php.net/define Quote Link to comment Share on other sites More sharing options...
No0ne Posted November 22, 2010 Author Report Share Posted November 22, 2010 include.php: function fukcija { global $mainigais; echo $mainigais; } header.php: funkcija($mainigais) details.php $mainigais = "anannanana"; tada doma apmeram, DEFINE it kaa meginaju, bet ipasi neiedzilinajos, kad neaizgaja uzreiz. Quote Link to comment Share on other sites More sharing options...
Martiny Posted November 22, 2010 Report Share Posted November 22, 2010 Ja pareizi sapratu, tad include.php satur funkciju: function f($var) { echo 'Tavs mainīgais: '.$var.'<br/>'; include 'header.php'; } Savukārt failā details.php ir kaut kas līdzīgs šim: include 'include.php'; $var = 'Faila details.php mainīgais.'; f($var); Kur problēma? Quote Link to comment Share on other sites More sharing options...
No0ne Posted November 22, 2010 Author Report Share Posted November 22, 2010 Problema taja, ka kaa jau teicu, to funkciju vajag palaist ieksh header.php un include.php ir sads: function f($var) { ... } function header() { include 'header.php'; } attiecigi details.php ir $mainigais un header(); Quote Link to comment Share on other sites More sharing options...
Martiny Posted November 22, 2010 Report Share Posted November 22, 2010 Sorry, es nepiedalos, jo nesapartu problēmu. Quote Link to comment Share on other sites More sharing options...
Леший Posted November 22, 2010 Report Share Posted November 22, 2010 Problema taja, ka kaa jau teicu, to funkciju vajag palaist ieksh header.php un include.php ir sads: function f($var) { ... } function header() { include 'header.php'; } attiecigi details.php ir $mainigais un header(); Problēma ir, ka tu includo header iekš funkcijas ķermeņa. Acīmredzot, mainīgie un funkcijas, kas atrodās ārpus tas funkcijas, nebūs pieejamas, ja nav global. Quote Link to comment Share on other sites More sharing options...
Martiny Posted November 22, 2010 Report Share Posted November 22, 2010 Var lietot arī sesiju mainīgos (globālie). Quote Link to comment Share on other sites More sharing options...
rATRIJS Posted November 22, 2010 Report Share Posted November 22, 2010 (edited) /* details.php */ global $mainigais; $mainigais = 'OMG'; include 'include.php'; func(); /* include.php */ function func() { include 'header.php'; } /* header.php */ global $mainigais; echo $mainigais; // izvadiis 'OMG' Ja es pareizi sapratu tavu probleemu. Ja ne paskaidro siikaak. Ar konstanteem: /* details.php */ define('KONSTANTE', 'OMG'); include 'include.php'; func(); /* include.php */ function func() { include 'header.php'; } /* header.php */ echo KONSTANTE; // izvadiis 'OMG' Neviens variants gan nav vizuaali pievilciigs (man) Edited November 22, 2010 by rATRIJS Quote Link to comment Share on other sites More sharing options...
No0ne Posted November 22, 2010 Author Report Share Posted November 22, 2010 Problēma ir, ka tu includo header iekš funkcijas ķermeņa. Acīmredzot, mainīgie un funkcijas, kas atrodās ārpus tas funkcijas, nebūs pieejamas, ja nav global. Manuprat, taa ir lielakaja dala template sistemu. Katra faila sakuma ierakstam header(), nodefinejam vienu vienigu funkciju un woilla viss headeris gatavs :) Quote Link to comment Share on other sites More sharing options...
Леший Posted November 22, 2010 Report Share Posted November 22, 2010 rATRIJS, nē, viņam ir: /* include.php */ function func(){ echo "omg"; }; function func2(){ include 'header.php'; } /* header.php */ func(); Quote Link to comment Share on other sites More sharing options...
No0ne Posted November 22, 2010 Author Report Share Posted November 22, 2010 Ar konstanteem: /* details.php */ define('KONSTANTE', 'OMG'); include 'include.php'; func(); /* include.php */ function func() { include 'header.php'; } /* header.php */ echo KONSTANTE; // izvadiis 'OMG' Neviens variants gan nav vizuaali pievilciigs (man) Paldies, stick`oshu pie shii varianta, nesaprotu, kapec vakar nesanaca. Anyway, kapec nav vizuali pievilcigi? Manuprat, loti okei :) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.