How can I pass variable from a view to another view [duplicate] - php

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
codeigniter : pass data to a view included in a view
How can I pass variable from a view to another view inside it?(codeigniter)
Thanks:D

If you mean, that you set a variable in one view, then you call an other view inside that view and you would like to use it there, the easiest way, to set it in the controller, which call the view.
$data['var'] = 'value';
$this->load->view('view file',$data);
Then you can reach that in every sub view.

Related

get data from URL without having variables [duplicate]

This question already has answers here:
Get the full URL in PHP
(27 answers)
Closed 7 years ago.
I don't know how can I get data from an url without having any sort of variable.
For example if the user comes to the website welcome.com and he starts adding to the url
EX: welcome.com/NewYork-NY/Driver
how can I save NewYork-NY and Driver when he/she hits enter ?
I need to save the data in order to list some content for the user and the only option for him to get to this content is if he goes to that URL manually, there is no button or option for him to chose between cities or categories.
The superglobal $_SERVER['PATH_INFO'] contains all the parts of the URL path after the script. So if the user goes to:
welcom.com/index.php/NewYork-NY/Driver
$_SERVER['PATH_INFO'] will contain /NewYork-NY/Driver.

Is it possible to call a PHP function from js file? [duplicate]

This question already has answers here:
Call php function from JavaScript
(5 answers)
Closed 5 years ago.
Is there any way I can call a PHP function from jQuery? I have a .js file and a .php file.
I have a jQuery event applied on a button click. Now I want to set a condition on what happens next when the button is clicked depending on whether a user is logged in or not. Is there any way I can do this from my .js file ?
You can call any php file by the common HTTP methods, e.g. GET and POST.
What you might be looking for is AJAX. Google the term, and also look into jQuery for a simplified approach.
You can send it to a php file with ajax and use your php file to check if the user's logged in. Then you can send a response back to your js file to see which event you should trigger
Technically, yes. But why would you want to in this case? My suggestion is to look into storing values in cookies, since both PHP and JS will have access to them.

How to get the post data without form builder [duplicate]

This question already has answers here:
Access POST values in Symfony2 request object
(9 answers)
Closed 8 years ago.
Normally I am using formbuilder to get the post data from form.
However,now I need very simple form not relevant with entity.
I can get the method like this and
if ($this->getRequest()->isMethod('POST')) {/
I want to get the each form data.(name is form name)
echo($this->getRequest()->get('name')->getData());
it shows error.
I used to use formbuilder and bindRequet normally to pick the data from form object.
How can I get the each form data from this->getRequest() without using formbuilder?
You could get it from the request property:
$this->getRequest()->request->get('foo');

need to use variables in another page [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
PHP Pass variable to next page
Is it possible to use super global variables on another page. Basically I have two pages form.php and search.php. I'm calling search.php using ajax on submit button on-click also I am using method post and without action. If I try to use super global variable in search.php which is in form.php then it gives error for undefined variable.
I don't want to use session, cookies or $_get. I have to fetch data from MySQL using those vaiables.
You have to include one page in another or create 3rd page with your variables.
Or you just use session superglobal.
in place of global variable you can use session variables

Pass PHP variable from one page to another and to another [duplicate]

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
pass value from page to another in PHP
For example, I have 3 pages. First page will be a regular HTML login page which will ask for username. Second page will get this username variable thru POST function and assign a php variable such as $username. Third page will take this $username variable and display it. How can this be done? I have done the first two pages but I need help with passing it to the third page.
Thanks!
Check the PHP documentation for sessions. There are many examples of how to do this.
http://www.php.net/manual/en/session.examples.basic.php
Use a $_SESSION superglobal:
http://us3.php.net/manual/en/reserved.variables.session.php
You'll need to use a session_start() function at the beginning of any page you want to maintain session data for. After that, you can just assign to and retrieve from $_SESSION['username'].

Categories