CakePHP Having a variable in every file - cakephp

I would like to have a variable $bURL available on every view/controller/element/layout of my CakePHP installation.
What is the best location to set such a variable?

bootstrap.php
This file is ideal for a number of common bootstrapping tasks:
Defining convenience functions.
Registering global constants.
...

Related

how to define array/list as global in Perl?

i have an array called #missing_ports this array has been updating from different subroutines and loops. So array need to be global. how to define this array as global in perl.
code contains
use warnings;
use strict;
i declared this array in start of the program without "my" keyword, facing below error
#missing_ports" requires explicit package name at experiment.pl
with my keyword able to resolve the error but array is null in the end.
how can manage this situation in perl?
The following creates a lexical variable:
my #missing_ports;
If it's placed the start of a file, the variable will be visible to the entire file.
The following creates a lexical variable that's aliased to a package (global) variable:
our #missing_ports;
You can use this in multiple places in the same package.
You will still need to use the variable's full name from other packages.
The following declares the package variable:
use vars qw( #missing_ports );
This is not lexically scoped.
You will still need to use the variable's full name from other packages.
And of course, you could always use the full name of the variable.
$main::missing_ports
This requires no declaration, but will warn if only referenced by name once. So it's better to combine it with our or use vars.
Punctuation variables (e.g. $_) are "super globals". Use of these variables without a package name doesn't default to a variable in the current package; it defaults to a variable in the root/main namespace. (e.g. package Foo; $x; $_; means package Foo; $Foo::x; $main::_;.) There's no means of making additional superglobals.
As a final note, all the approaches listed here other than my are extremely strong indications of bad code.

Nagios/Check_MK: How to see effective object definition

In Nagios (or check_mk), is there a way to see what the final effective object (e.g. host) definition is after all templates, inheritance, etc.?
I want to use this as a test/debug tool to make sure my definitions end up as intended, and also to compare configurations to each other.
Thank you
There should be a 'status.dat' file in your Nagios installation (usually [Nagios_install]/var/status.dat) that contains a 'flattened' list of all defined checks.
Your main nagios.cfg file should have its location under:
Format: status_file=<file_name>
Example: status_file=/usr/local/nagios/var/status.dat
And also this file:
Format: object_cache_file=<file_name>
Example: object_cache_file=/usr/local/nagios/var/objects.cache
Hope this helps.

Correct way to resolve a circular reference in make/C code?

I have two C modules that each use some functionality of the other. In my makefile I have expressed this thus:
moduleA.h: common.h moduleB.h
moduleB.h: common.h moduleA.h
For obvious reasons this generates a circular reference warning though it goes on to compile fine. What is the correct way of resolving this? Should I refactor the modules to create a third - moduleC - that ties the two together?
Module A is a logging module and module B is a cronjob implementation. Logging uses cronjob to schedule log rotates and cronjob uses logging to tell everyone what it's up to.
Module C would be rather small; simply create a cronjob to call a logging rotate function but logging would then not need to know about cronjob. Cronjob would still depend on logging of course.
Or should I just ignore the warning?
You can use soothing like this :
#ifndef MY_HEADER_FILE_H
#define MY_HEADER_FILE_H
/* Prototypes and others consts and .... */
#endif
Hope this help.
Regards.
You should create a version of the logging module moduleA that only logs without worrying about cron jobs. And then create a new module (perhaps moduleC) which is only involved in using cron jobs to rotate the logs. Then your dependencies are non-circular:
moduleC -> moduleB -> moduleA
It is wrong to state a header file being a prerequisite of a target header file, unless the target is to be remade depending on the prerequisite. Normally, an object file target depends on header files, e. g.
moduleA.o moduleB.o: common.h moduleA.h moduleB.h

Does LoadLibrary parse environment variables such as %windir%

If I do LoadLibrary("%windir%\\system32\\ole32.dll") does that mean Windows will ONLY load from "c:\windows\system32\ole32.dll" ? Also does LoadLibrary() in C understand the environment variable?
as Serge said and carefully tested, LoadLibrary does not do environment variable substitution in path.
however, there is a function in the windows API to replace environment variables in strings: ExpandEnvironmentStrings(). you can perform the required substitution on your path before calling LoadLibrary().
The docs for LoadLibrary clearly state that:
If the string specifies a full path, the function searches only that
path for the module.
That said, they don't mention support for environment variables substitution. I seriously doubt they do support environment variables substitution: That's a shell feature, not a kernel API one.
BTW, that means LoadLibrary() would consider %windir%\blah.dll as a relative path since it doesn't start with a drive letter or a UNC path. Hence it would look through the whole series of directories, looking for a subdir named %windir%, which it's not likely to find!
I gave it a quick test: It confirms my opinion. Error = 126 : The specified module could not be found.

Is there a recommended way to set environment variables for CUnit tests?

We want to use CUnit to test a shared library that we have developed.
The shared library is loaded via the standard Solaris LD_PRELOAD mechanism where it uses an environment variable to remap a string containing a file path to a new date and time based on the file path.
Initial testing will use a single value for the environment variable being used to control this remap of the file paths.
Is there a suggested way, a recipe maybe?, to pass our environment variable into the CUnit environment?
I'm thinking of setting the test value in the optional test suite setup function.
Edit: A bit more detail as requested by #eaanon01 below. (-:
Our shlib implements a function that takes a directory path, for example
/home/www/my_tld
and then using a Unix epoch timestamp, converts that to a directory path within our archive, for example
/home/www/my_tld/1088589843
for the contents of that tld at 20040630 10:04:03 GMT.
As we have no control over the parameters of the syscalls being intercepted, we must use an environment variable to pass in the required timestamp, in this example a value of 1088589843.
We want unit tests for all the Unix syscalls we are intercepting with this shlib and we want to use the CUnit framework for the unit tests and have a fixed value of the time stamp which is passed in via the environment variable.
Is there a recommended way of setting the environmental variable for each unit test?
You have the posibility to to init setups and removal in an "init suite" function and an "clean suite" function. Not sure I can fully grasp the question, please elaborate more.

Resources