Jump to content
php.lv forumi

mainigais vairakos failos


No0ne

Recommended Posts

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 by No0ne
Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

/* 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 by rATRIJS
Link to comment
Share on other sites

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 :)

Link to comment
Share on other sites

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 :)

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...