In java we vll set attributes into request object as request.setAttr ibute(aa,bb), how to do the same in PHP
8 5336 Atli 5,058
Recognized Expert Expert
I suppose: -
// By instantiation
-
$request->setAttribute($aa, $bb);
-
-
// Or statically
-
request::setAttribute($aa, $bb);
But I have no idea what the "request" object is; whether it is some special Java thing that. I'm just assuming you have a class called "request" and that you want to call the a "setAttribu te" method on it.
If that is not what you are trying to do, elaborate. (And keep in mind that many of us do not know details about the inner workings of Java.)
In PHP you have three global arrays to accomplish this.
$_POST, $_GET which contains data sent through post method or get method
There is also $_REQUEST which contains the content found in $_POST + $_GET
to carry data between webpages, use $_SESSION['varname'] = value
To use sessions you also need to use the session_start() ; method at the very beginning of your php file. like this: -
<?php
-
session_start();
-
-
$_SESSION['attr_name'] = $value;
-
There can be no print action or even whitespace before the session_start() method
Hi,
In my case i have written a class inside the <?php> tag as below - <?php
-
-
class First{
-
public function setValues(){
-
$inputArray=array();
-
$inputArray['1']="one";
-
$inputArray['2']="two";
-
$inputArray['3']="three";
-
//now i have to pass this array to another PHP webpage,such that i
-
//can print the values of this array in the next PHP page(second.php given below).
-
}
-
}
-
?>
second.php - <html>
-
<?php
-
-
?>
-
<body>
-
//here i have to access the $inputArray and print its value as
-
<h1>The value of 1 is:</h1><?php $inputArray["1"] ?>
-
</body>
-
</html>
how to carry the array that is $inputArray from First PHP and print its values in second.php as above.
Do you want to pass this array after user action on the web site or you just want to include the file with class into another php file?
Atli 5,058
Recognized Expert Expert
Assuming, again, that at some point in your code the First::setValue function would be called, and that the code in the second page would not be called in the same request, then you would want to use Sessions.
See the examples in the manual for details on how they work. You can also check out this tutorial. (Or one of the many others out there. Come to think of it, I even wrote one of those a few years back xD)
Ya i have to pass the array after user action.
-
<?php
-
-
class First{
-
public function setValues(){
-
$inputArray=array();
-
$inputArray['1']="one";
-
$inputArray['2']="two";
-
$inputArray['3']="three";
-
//now i have to pass this array to another PHP webpage,such that i
-
//can print the values of this array in the next PHP page(second.php given below).
-
-
// rythmic input!!!: in order to get the array at all you need to return it from the function
-
return $input_array;
-
}
-
}
-
?>
-
Now, each time that you use this class you will need that page to start with -
<?php
-
session_start(); // now you are using session vars which are reached through the $_SESSION var which is an array.
-
To store classes in a session you need to serialize the class by using the serialize function built-in in php like so -
<?php
-
session_start();
-
-
$first = new First();
-
-
// serialize and add to session
-
$_SESSION['first'] = serialize($first);
-
Then in second.php you'd write -
<?php
-
session_start();
-
-
//get the saved class
-
$first = unserialize($_SESSION['first']);
-
-
$input_array = $first->setValues();
-
-
print "<h1>The value of 1 is:</h1>" . $inputArray[1];
-
-
That should do it!
By the way: another thing I noticed, whenever you want to put something in the html code from your php code you need to echo or print it.
So your example with -
// prints The value of 1 is:
-
<h1>The value of 1 is:</h1><?php $inputArray["1"]?>
-
should be: -
// prints The value of 1 is: 1
-
<h1>The value of 1 is:</h1><?php print $inputArray["1"];?>
-
best regards
rythmic
Thanks..i used this code, it worked..
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Dan Sikorsky |
last post by:
How can I get the recordset attributes for a table field in SQL Server 2000
to report the field updatable attribute correctly ... mine keeps saying the
fields are not updatable? That is, ( oRecordSet ( oItem ).Attributes & 0x4)
is always 0 for every field on SQL Server 2000
Example code:
var sSQL = 'SELECT TOP 1 * FROM WHERE ' + sUniqueField
+ '=' + sUniqueValue + ';';
|
by: Michael Iantosca |
last post by:
I have a custom attribute that I attach to certain pages in my application and I want to inspect each page request as it is made to see if the custom attribute is attached to the underlying page class. If is attached I want to perform some action.
How can I access custom attributes from an HttpModule? I have to pass a target to the
System.Attribute.GetCustomAttribute() call to attempt to retrieve the attached attribute.
I tried to access...
|
by: jensen bredal |
last post by:
Hello,
i was not able to find any documentation about the largest value one can
assign the "timeout" attribute of the
<sessionState section in web.config.
any idea?
|
by: Danny Crowell |
last post by:
I have a question related to ASP.net sessions and static attributes. In an
ASP.net application (MyApp) I have a class called Globals with a public
static string called UserName. Will UserName be unique for each session or
will the value of UserName be the same for all sessions?
For example, John launches MyApp and the UserName is assinged the value
"John". Next, Bob launches MyApp and the UserName is assigned the value
"Bob". Does John...
|
by: Samuel M. Smith |
last post by:
I have been playing around with a subclass of dict wrt a recipe for
setting dict items using attribute syntax.
The dict class has some read only attributes that generate an
exception if I try to assign a value to them.
I wanted to trap for this exception in a subclass using super but it
doesn't happen.
I have read Guido's tutorial on new style classes and Shalabh's
tuturial on new style attributes and methods, and thought
I understood...
| |
by: LG |
last post by:
I want to add attributes to a custom dropdownlist and I found some code
on Internet that doesn't work after post back.
First time the control has the attributes, but after postback the
attributes are lost.
It must be a bug in the code bellow. Can anyone help?
Thanks,
LG
using System;
|
by: Alan Isaac |
last post by:
I have a class whose instances should only receive attribute
assignments for attributes that were created at inititialization.
If slots are not appropriate, what is the Pythonic design for this?
Thanks,
Alan Isaac
|
by: james_027 |
last post by:
hi,
for example an request object ... is request.user the same as
request.__class__.user?
THanks
james
|
by: tjhnson |
last post by:
Hi,
With properties, attributes and methods seem very similar. I was
wondering what techniques people use to give clues to end users as to
which 'things' are methods and which are attributes. With ipython, I
use tab completion all the time, but I can rarely tell from the names
alone whether it is an attribute or method.
Tips? Ideas? Best practices?
|
by: Rafe |
last post by:
Hi,
I'm working within an application (making a lot of wrappers), but the
application is not case sensitive. For example, Typing obj.name,
obj.Name, or even object.naMe is all fine (as far as the app is
concerned). The problem is, If someone makes a typo, they may get an
unexpected error due accidentally calling the original attribute
instead of the wrapped version. Does anyone have a simple solution for
this?
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |