Do I need to add session_start() in include pages if I have it on the parent file? - php-5.3

I have this code below as as an example .. should I use session_start() again in all the included scripts if I already have it on top in the parent file ..
here's parent.php
<?php
session_start();
include 'child1.php';
include 'child2.php';
//
?>
do child1.php and child2.php need session_start() as well in order to use session variables in them or is the first session_start of the parent.php file enough for the include files to use session variables?

No you only want session_start() called once.
Calling session_start() after the session was previously started will result in an error of level E_NOTICE. Also, the second session start will simply be ignored.

Related

Generate URL of resources that are handled by Grails AssetPipeline

I need to access a local JSON file. Since Grails 2.4 implements the AssetPipeline plugin by default, I saved my local JSON file at:
/grails-app/assets/javascript/vendor/me/json/local.json
Now what I need is to generate a URL to this JSON file, to be used as a function parameter on my JavaScript's $.getJSON() . I've tried using:
var URL.local = ""${ raw(asset.assetPath(src: "local.json")) }";
but it generates an invalid link:
console.log(URL.local);
// prints /project/assets/local.json
// instead of /project/assets/vendor/me/json/local.json
I also encountered the same scenario with images that are handled by AssetPipeline1.9.9— that are supposed to be inserted dynamically on the page. How can I generate the URL pointing this resource? I know, I can always provide a static String for the URL, but it seems there would be a more proper solution.
EDIT
I was asked if I could move the local JSON file directly under the assets/javascript root directory instead of placing it under a subdirectory to for an easier solution. I prefer not to, for organization purposes.
Have you tried asset.assetPath(src: "/me/json/local.json")
The assets plugin looks in all of the immediate children of assets/. Your local.json file would need to be placed in /project/assets/foo/ for your current code to pick it up.
Check out the relevant documentation here which contains an example.
The first level deep within the assets folder is simply used for organization purposes and can contain folders of any name you wish. File types also don't need to be in any specific folder. These folders are omitted from the URL mappings and relative path calculations.

Overriding in module not working in prestashop

I am new to prestashop and developing a module to change behaviour of checkout process. As i am new, i am first overriding IndexController.php file in my module directory to just test the overriding mechanism in prestashop. The directory structure, i have followed, to override controller file as:
modules/my_modules/override/controllers/front/IndexController.php
Below is the code of above file:
class IndexController extends IndexControllerCore{
public function __construct() {
parent::__construct();
d('You are overriding index file');
}
}
In above code, i have just created an construct and print a test string with die. But nothing is happening on the home page on front end. I have also tried with override another controller file, but i have got same result.
I have searched many things on google, but nothing got. Please anyone tell me, what i am doing wrong in this? if the logic is correct, then why overriding is not working here?
Waiting for solution.
Like #rsanchez said. You need to reinstall the module everytime you change your module's overrides. Prestashop will not automatically check for new changes or new overrides without it.

How can i load config file but not autoload in zf2

I have some config file,they don't need use in everywhere,so i don't want it autoload,can you tell me how to load config file in controller and it can be get in serviceLocator,don't tell me to use zend\config\config, thanks。
First off, it's not advised to ask a question and then directly say that you don't want someone to tell you about XY. What if XY would be the only way?
You could always do something like
$onlyNowConfig = require_once('./config/onlyNowConfig.php');
The current working directory of PHP is the root of your application, as it's set in your public/index.php via the chdir() function.
Other than that, there's no real harm to include the configuration inside your module.config.php. The ModuleManager will check for the existance of the getConfig() function inside your Module class. If it's existant, the Configuration will be loaded. Typically every module has a config that will be loaded. And there's no real speed (dis)advantage of outsourcing 100-200 configuration lines into a separate file. The additional I/O you'd do by only including it on those few actions you need it would actually be higher than the very little time it takes longer to merge the configuration (probably like 1ms total vs. 2-3ms I/O).
I'd advise to just include it in your module.config.php and you'd have it available everywhere via the ServiceLocator, otherwise just include/require the one config file that you need, wherever you are. The include/require parameter would never change, as the working directory of PHP will not change, no matter in what file you are (as long as you don't set it anew via chdir() - which would be highly not recommended).

Need to load contents of XML file into a constant variable, when to do this?

I want to load a xml file into a collection, and I will need to access this on each and every page request.
I only need to load it once, where/what point should I do this?
You can create an initializer to load the xml file and put into a constant.
config/initializers/load_xml_collection.rb
The most straight-forward way would be to set it up as an initializer. Create a new file in #{Rails.root}/config/initializers called load_xml_file.rb (or something a little more descriptive)
Then, within that, you could do something along the lines of:
SETTINGS_FROM_XML_FILE = method_to_read_xml
This will be executed once when your app is loaded. You'll also be able to access SETTINGS_FROM_XML_FILE anywhere in your application.
The only caveat is that if the file changes, you'll need to re-start the application, or come up with a more sophisticated way of loading the details you need.

Grails: Getting current View name from within a Taglib

Is there any way to find out the current view (or gsp file) that is being evaluated?
RequestURI doesn't work due to URL Mappings and forwards.
I'm trying to retrieve resources dynamically based on the current GSP file. For example, if product/view.gsp is being executed, I want to include product/view.css and product/view.js (if they exist). The part that I'm having a problem with is getting the text "view"
A gsp page is compiled into a class derived from org.codehaus.groovy.grails.web.pages.GroovyPage. You can get the whole pathname of the gsp file with ${this.getGroovyPageFileName()}, or just ${groovyPageFileName}. You'll have to trim off the path information yourself.

Resources