trrsrr
asked on
Automatically adjust a value ?
I'm not sure what to write for the title :0)
Actually I was playing around with codes and stuck on this :
So, this is the only value I would have on the top of the script:
$site['url'] = 'http://mydomain.com/';
What I want is, when I call something like $site['url']['page'] it is automatically give me this 'http://mydomain.com/page/' without having to define $site['url']['page'] = $site['url'].'page/';
But I want this to be applied ONLY to $site['url'].
I might have
$site['title'] = 'Welcome...';
and I dont want $site['title']['page'] to become 'Welcome...page/'
Here are my codes so you can take a look better of what I want to have... Thanks.
Actually I was playing around with codes and stuck on this :
So, this is the only value I would have on the top of the script:
$site['url'] = 'http://mydomain.com/';
What I want is, when I call something like $site['url']['page'] it is automatically give me this 'http://mydomain.com/page/' without having to define $site['url']['page'] = $site['url'].'page/';
But I want this to be applied ONLY to $site['url'].
I might have
$site['title'] = 'Welcome...';
and I dont want $site['title']['page'] to become 'Welcome...page/'
Here are my codes so you can take a look better of what I want to have... Thanks.
<?php
$site['url'] = 'http://mydomain.com/';
// custom codes as described above...
// perhaps using foreach or while .. I dunno :-(
$site['title'] = 'Welcome...';
$site['title']['sub'] = 'Please browse through the menu above';
?>
<h1><?=$site['title'];?></h1>
<p>SITE MENU:</p>
<p>
<a href="<?=$site['url'];?>">HOME</a><br />
<a href="<?=$site['url']['about-us'];?>">ABOUT US</a><br />
<a href="<?=$site['url']['profile'];?>">PROFILE</a><br />
<a href="<?=$site['url']['portfolio'];?>">PORTFOLIO</a><br />
<a href="<?=$site['url']['contact-us'];?>">CONTACT US</a><br />
</p>
<p><?=$site['title']['sub'];?></p>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Notation like <?= will get you in trouble some day. I would avoid the use of short-open tags. Consider what will happen when you try to use XML. XML strings start with <?xml.
I think you might want to consider your data design carefully. While it is true that you could put your information into multi-dimensional arrays, you almost guarantee yourself a difficult time debugging the typographical errors that are certain to result from the complicated syntax. Most modern MVC app designs would use classes to encapsulate this information, with setters and getters to insert and retrieve the data.
Also, this is a recipe for an eventual mess:
<a href="<?=$site['url']['abo ut-us'];?> ">ABOUT US</a><br />
What if you wanted to move the site or part of the site? Relative addressing is your friend, believe me!
I think you might want to consider your data design carefully. While it is true that you could put your information into multi-dimensional arrays, you almost guarantee yourself a difficult time debugging the typographical errors that are certain to result from the complicated syntax. Most modern MVC app designs would use classes to encapsulate this information, with setters and getters to insert and retrieve the data.
Also, this is a recipe for an eventual mess:
<a href="<?=$site['url']['abo
What if you wanted to move the site or part of the site? Relative addressing is your friend, believe me!
ASKER
@hexer4u:
I think that's the closer solution I can get .. actually I was having a little misperception about $site['url'] as a string or part of an array :(
And your codes really makes all clear to me now.
Just realize that $site['url']['whatever'] will be part of an array and never gonna be a string :()
So, thank a lot... I learned something new here...
@Ray_Paseur:
Thanks for your advice but I'm not really using <?=$var?> on my codes, it just for short typing here :)
I use <?php echo $var; ?> in my codes.
Regards...
I think that's the closer solution I can get .. actually I was having a little misperception about $site['url'] as a string or part of an array :(
And your codes really makes all clear to me now.
Just realize that $site['url']['whatever'] will be part of an array and never gonna be a string :()
So, thank a lot... I learned something new here...
@Ray_Paseur:
Thanks for your advice but I'm not really using <?=$var?> on my codes, it just for short typing here :)
I use <?php echo $var; ?> in my codes.
Regards...
I'm not really using <?=$var?> on my codes, it just for short typing here
Why? Next time when you post a code sample, please post the actual code you are using. You will almost guarantee yourself low quality responses if you hide these "little details" of your code. You will almost always get accurate answers if we can see the code you are really using instead of something that was redacted.
Why? Next time when you post a code sample, please post the actual code you are using. You will almost guarantee yourself low quality responses if you hide these "little details" of your code. You will almost always get accurate answers if we can see the code you are really using instead of something that was redacted.
Open in new window
The issue with this is that $site['url'] will be array() and not a string, and as suchOpen in new window
will have to beOpen in new window
or something similarHope this helps.