Welcome to the MetaMod and Chameleon Support Forums.

Before posting, please check out the FAQs.

helpme

 

Need extra help with your Joomla site? Consider paid Joomla support by the developer of Chameleon and MetaMod.

 

PHP operator 'or' and 'case'

PHP operator 'or' and 'case'

Is it possible to use "or" in php "case" ?
like this

if (
$option == 'com_k2'
and $id == '352split-marjanske-crkvice'
or $id='403split'
) return 171;

Do you have some documentation, how to use ?

startprogram
Beginner Modder
ranks
useravatar
Offline
1 Posts
Administrator has disabled public posting

Re: PHP operator 'or' and 'case'

Hi,

If you want to do "or" conditions you should surround them in brackets otherwise they won't work as expected. But you're nearly there!

Try this:

if (
  $option == 'com_k2'
  and ( $id == '352split-marjanske-crkvice' or $id == '403split' )
) return 171;

For documentation for this, I'd advise you to google for a tutorial on basic PHP programming in your language.

Cheers,
Stephen

Stephen Brandon
MetaMod / Chameleon developer
If you use MetaMod or Chameleon, please post a rating and a review at the Joomla! Extensions Directory: Chameleon | MetaMod

metamodguy
useravatar
Offline
3312 Posts
User info in posts
Administrator has disabled public posting

Re: PHP operator 'or' and 'case'

startprogram asked:

"I must create 30 menu modules, and show depend on K2 article
I already create 30 menus, each with 5 menu items
Is it possible to programming code and show menu in one metamod module, depend on K2 item?"

Answer:

Yes, you can put all of these into 1 MetaMod, to save you having to create 30 different MetaMods (as well as the 30 menu modules).

You could do it like this:

if ($option != "com_k2") return; // bypass the rest if it's not a K2 page
switch ($id) {
  case '352split-marjanske-crkvice': return 171;
  case '403split': return 171;
  case '999somethingelse': return 1001;
  case '998nicetown': return 1002;
  // add more case statements here, each
  // returning a different module number
}
// always follow the last case statement with the end bracket you see above!

Stephen Brandon
MetaMod / Chameleon developer
If you use MetaMod or Chameleon, please post a rating and a review at the Joomla! Extensions Directory: Chameleon | MetaMod

metamodguy
useravatar
Offline
3312 Posts
User info in posts
Administrator has disabled public posting

Board Info

Board Stats:
 
Total Topics:
1667
Total Polls:
6
Total Posts:
5909
Total Posts Today:
1
User Info:
 
Total Users:
10075
Newest User:
rsker57
Members Online:
0
Guests Online:
285

Online: 
There are no members online

Forum Legend:

 Topic
 New
 Locked
 Sticky
 Active
 New/Active
 New/Locked
 New Sticky
 Locked/Active
 Active/Sticky
 Sticky/Locked
 Sticky/Active/Locked