Zend Framework : Need All parameters for application.ini - php

I want to know all the parameters/options which can be used in application.ini file. Is there any list available?
Please help

You can specify anything you want. For instance, I set my javascript files there:
js.jquery.filename = "/js/jquery.min.js"
js.jquery.offset = 0
js.jqueryui.filename = "/js/jquery-ui.min.js"
js.jqueryui.offset = 1
js.nestedsortable.filename = '/js/jquery.ui.nestedSortable.js'
js.nestedsortable.offset = 2
js.ckeditor.filename = "/js/ckeditor/ckeditor.js"
js.ckeditor.offset = 3
Now, whenever I need to add a javascript file, I do:
$config = Zend_Registry::get('config');
$js = $config['js'];
$this->view->headScript()->offsetSetFile($js['ckeditor']['offset'],$js['ckeditor']['filename']);
$this->view->headScript()->offsetSetFile($js['jquery']['offset'],$js['jquery']['filename']);
Like I said, you can specify any value. Anything you will be accessing often and need to be available globally can and perhaps should be there :).

During loading config in index.php you can store it in Zend_Registry and you can access them when you want.
You can also parse Zend_Config to an array and look, what is inside.

#Future King Do this:
$config = Zend_Registry::get('config');
Zend_Debug::dump($config);
That should do it. Let me know if it helps.

Related

Need regex to match routes in Codeigniter

I am having routes configuration like below,
$route['sf_network/list'] = "sf_resource/list";
$route['sf_client/list'] = "sf_resource/list";
$route['sf_subnet/list'] = "sf_resource/list";
$route['sf_ip_address/list'] = "sf_resource/list";
$route['sf_network/describe/(:any)'] = "sf_resource/describe";
$route['sf_client/describe/(:any)'] = "sf_resource/describe";
$route['sf_subnet/describe/(:any)'] = "sf_resource/describe";
$route['sf_ip_address/describe/(:any)'] = "sf_resource/describe";
Similar to this I am also need to configure routes for add and modify pages. so, its becoming too large lines of coding. Is there anyway to use regex for reduce the multiple lines of coding. I am new to PHP and this is my first project. Any suggestion would be most grateful. Thank you.
Solution
$route['sf_([A-Za-z_-]+)/list'] = "sf_resource/list";
$route['sf_([A-Za-z_-]+)/describe/(:any)'] = "sf_resource/describe/$2";

Fortnite API html

I want to put my fortnite stats on my website HTML/CSS. I find this.
But I don't know php very good, so I need your help. Must I delete this: 'your_api_key' and put : your_api_key without the ' ' ?
And lines like this:
$this->auth = new Fortnite_Auth($this);
$this->challenges = new Fortnite_Challenges($this);
$this->leaderboard = new Fortnite_Leaderboard($this);
$this->items = new Fortnite_Items($this);
$this->news = new Fortnite_News($this);
$this->patchnotes = new Fortnite_PatchNotes($this);
$this->pve = new Fortnite_PVE($this);
$this->status = new Fortnite_Status($this);
$this->weapons = new Fortnite_Weapons($this);
$this->user = new Fortnite_User($this)
Must I modify something?
(here are some informations:
-user_id: 501b9f2dfda34249a2749467513172bf
-username: NoMaD_DEEPonion
-platform: pc
-windows: season 5
)
For all this code, I used xammp server (I hope it's good)
Thank you for your help
You should always quote '' your key/strings. So it would look like:
$api->setKey('123qwerty456');
$api->user->id('NoMaD_DEEPonion');
Please read their documentation. You're supposed to get an API key from them to get started. And you don't have to edit Client.php. You're supposed to include the files instead. Try including Autoloader.php, since it requires the necessary files.
XAMPP is alright for development, but not suitable for production/public. Good luck!
What #sykez wrote.
I personally use https://fortniteapi.com/ to get the data. They also have a sweet POSTMAN page with different requests https://documenter.getpostman.com/view/4499368/RWEjoGqD
At last. I am not really sure that this will be a good project to start learning PHP from. I really suggest that you get to understand the basics of PHP first before you jump into API calls, processing arrays and more.

How to get all not translated texts in Smarty

Currently I am working with Smarty and been busy with translations.
I am using the config files for translation, but I cannot find a way to collect all the vars that are not in my config file. When I don't have the translation in my config file, the output is blank.
My config files look like:
register = "Registreren"
username = "Gebruikersnaam"
password = "Wachtwoord"
login = "Inloggen"
In PHP I use:
$this->smarty = new Smarty();
$this->smarty->configLoad(THEME_DIR . "/translations/nl.conf");
$this->translations = $this->smarty->getConfigVars();
echo $this->translations["username"]; // output: Gebruikersnaam
I can use in my HTML:
{#password#}
{#username#}
{#password#}
{#login#}
But when I want to output a not yet translated var like this:
{#logout#}
My result is blank.
Does anyone know how to use a default function when this occurs? Or maybe add the not found var to my config file? Or at least, show the var name instead of nothing.
There is a way that doesn't need resorting to |default for each of your variables, but it requires a little change in one of the core files.
on line 340 of smarty/sysplugins/smarty_internal_data.php
replace
return null
by
return "#$variable#";
After this, all vars not defined int he conf file will appear as #name# (i.e. this is your #password#).
If for some reason you want a variable to be empty, just define it in the conf file as
variable = ""
The only way I found was this:
{#foo#|default:'foo'}
setting a default, if the variable is empty it will display that string.
http://www.smarty.net/docsv2/en/tips.tpl

How to find and replace a line in multiple files with PHP

I want to create a installer for my current project, that automatically modifies a dozens of config files.
So if the form was sent, the PHP script should look in which config file the searched option is and change it. Before you ask, I cant put the files together ;) .
A basic config line looks like this:
$config['base_url'] = 'test';.
I tried to use str_replace()but this didn't work because I don't know what is currently in the variable.
So I need a function that searches for $config['base_url'] = '%'; in multiple files and replaces it with $config['base_url'] = 'new_value'; (for example).
I realise the answer's accepted, and originally I deleted this, however, in the comments you mention the config being editable, which presumably means by other users, so you can't guarantee the spacing will match, nor that they'll use ' instead of " always, so the following is perhaps a little more forgiving
$name = 'base_url';
$value = 'new_value';
$config = '$config["base_url"] = "old_value";';
$config = preg_replace('/\[(?:\'|\")'.$name.'(?:\'|\")\]\s*=\s*(\'|\")(.*)\\1;/', "['".$name."'] = '$value';", $config);
echo '<pre>', var_dump($config), '</pre>';
You can use a regular expression like the following:
/\$config\['base_url'\] = '[a-zA-Z0-9]';/
Which you would have to adapt to each line.
A better solution, in my opinion, would be to create a template config file with lines like the following:
$config['base_url'] = '%BASE_URL%';
Where you could simply use str_replace().

Possible to use PEAR SearchReplace to replace text within a .php file?

I came across this simple pear tutorial over here: http://www.codediesel.com/php/search-replace-in-files-using-php/
include 'File/SearchReplace.php' ;
$files_to_search = array("fruits.txt") ;
$search_string = "apples";
$replace_string = "oranges";
$snr = new File_SearchReplace($search_string,
$replace_string,
$files_to_search,
'', // directorie(s) to search
false) ;
$snr->doSearch();
echo "The number of replaces done : " . $snr->getNumOccurences();
The writer uses the fruits.txt file as an example.
I would like to do a search and replace on a .php file.
Basically what I am trying to achieve would be this:
On a user interaction, index.php is opened,
$promoChange = "%VARYINGTEXT%";
is searched for and replaced with
$promoChange = "$currentYear/$currentPromotion";
The $current variables will vary, hence the need to change the words inbetween the "" only.
Does anyone have any input on how this type of task could be accomplished?
If anyone knows of any tutorials relating to this subject, that too would be greatly appreciated.
Thank you!
I do have everything else figured out, regarding the template and user interaction, I am just having trouble trying to work out how to accomplish this type of search and replace. I have an understand of how it should be done as I have made something similiar using visual basic. But I am starting to this that my answer for this would be perl? I hope that this is not so...
Okay, my problem is partly solved with this:
// Define result of Activate click
if (isset($_POST['action']) and $_POST['action'] == 'Activate')
{
include ''.$docRoot.'/includes/pear/SearchReplace.php' ;
$files = array( "$docRoot/promotions/index.php" ) ;
$snr = new File_SearchReplace( '$promoChange = "";', '$promoChange = "'.$currentYear.'/'.$currentPromotion.'";', $files) ;
$snr -> doSearch() ;
}
but how do i get it to search and replace something like $promoChange = "%VARYINGTEXT%";
It found and replaced "" with the current session values. But now that is has changed, I need it to replace and text inbetween "AND".
Any ideas anyone?
If you only need to adapt a single file, then do it manually:
$src = file_get_contents($fn = "script.php");
$src = str_replace('"%VARYINGTEXT%"', '"$currentYear/$currentPromotion"', $src);
file_put_contents($fn, $src);
str_replace is sufficient for your case.
Why on earth do you want to do something like that? Frameworks like PHP do exist solely on the base of not having to write a page for each different view of the same interaction. What's wrong with just including the PHP page you now want to change, and set the variables accordingly before calling it?
Ontopic: I don't see why what you're doing is a problem, purely technically speaking. This can be done using PHP. But really, you shouldn't.

Categories