1

I want to add multiple link in params.php . Is it possible to do so ?

Current view of my params in yii2 .

Params.php

<?php 
return [

"api_link" => "http://example.com" ,
];

I want to add multiple link in it 
Ex: 
<?php

return[
"api_link" => "http://example.com" & "http://www.example.com"

];

Is it possible to do so ? I tried but unable to succeed on this attempt .

Any lead over this will really be helpful.

3 Answers 3

3

You can set array for each params :

<?php 
    return [
        "api_link" => [
            "http://example.com",
            "http://example.com",
        ]
    ];
Sign up to request clarification or add additional context in comments.

4 Comments

thank you for your answer. but it throw an error saying PHP error "array to string conversion" where my api hits this api_link.
you must use in this way: Yii::$app->params["api_link"][0] and Yii::$app->params["api_link"][1]
but my problems lies there. I want it to fetch example.com or example.com when fetch from either of one url.
Is it possible to mention if i use example.com then it will fetch <?php return [ "api_link" => [ "example.com"; ] ]; or, If i use www. example.com then it will call <?php return [ "api_link" => [ "www. example.com" ] ];
1

You can store in an array

<?php 
   return [
    "api_link" => [
        "http://example.com",
          "http://example.com",
      ]
  ];
 ....

and for accessing you must iterate over it

     $myaArray =  [
        "api_link" => [
            "http://example.com",
            "http://www.example.com",
        ]
    ];

    foreach( $myArray['api_link'] as $key =>$value){
      echo $value;
    }

or

   echo $myArray['api_link'][0]; 

4 Comments

is it possible to mention if i use example.com then it will fetch <?php return [ "api_link" => [ "example.com" ] ]; or, If i use www. example.com then it will call <?php return [ "api_link" => [ "www. example.com" ] ];
i want to configure this params api_link in such a way that if someone use "example.com" then he can able to fetch <?php return [ "api_link" => [ "example.com"; ] ]; and if someone using "www.example.com" then it will fetch <?php return [ "api_link" => [ "www . example.com"; ] ]; .
Now its throwing error of CORS as someone using example.com with host www .example.com .
This seems a new question ... you have asked for multiple link in param .. and you have alredy at least 3 valid answer .. if you have others question .. you should rate properly (mark as accepted ) one of the valid answer and post the new question in a new post ..
1

i don't understand what you want. But you can try by multidimensional array.

 $arrayname = array(
  'url1' => 'nokibrokes.com',
  'url2' => 'example.com'
);

return $arrayname;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.