In Drupal 6, if we want to know everything about the profile user, we print_r the $account variables. However, I just found out in Drupal 7, the $account variable is not available anymore. What is the new way to access the profile user's account information?
Try this: print_r($elements['#account']);
When I put that in user-profile.tpl.php, I get an object like...
stdClass Object
(
[uid] => 29
[name] => user
[pass] =>
[mail] => user#example.com
[theme] =>
[signature] =>
[signature_format] =>
[created] => 1304866465
[access] => 0
[login] => 0
[status] => 1
[timezone] =>
[language] =>
[picture] =>
[init] =>
[data] =>
[roles] => Array
(
[2] => authenticated user
)
[entity_view_prepared] => 1
)
(I found this by installing the Devel module and checking the available variables by putting dsm(get_defined_vars()); in the template.)
Related
It is my first time working with an external API. I have already fixed that it gives me the right output. In a controller I have the following code:
public function index() {
$api = new Wefact();
$parameters = [
];
$api_response = $api->sendRequest('product', 'list', $parameters);
print_r($api_response);
}
This shows me the array on the page. But I do not know how to use this array to get it into a foreach in the blade. The output of the print_r is as follow:
Array
(
[controller] => product
[action] => list
[status] => success
[date] => 2022-05-05T04:20:03+02:00
[totalresults] => 2
[currentresults] => 2
[offset] => 0
[products] => Array
(
[0] => Array
(
[Identifier] => 1
[ProductCode] => P0001
[ProductName] => SIM ONLY 5GB
[ProductKeyPhrase] => SIM ONLY 5GB
[ProductDescription] =>
[NumberSuffix] =>
[PriceExcl] => 25
[TaxCode] => V21
[TaxPercentage] => 21
[PricePeriod] => m
[Modified] => 2022-05-05 03:49:57
)
[1] => Array
(
[Identifier] => 2
[ProductCode] => P0002
[ProductName] => SIM ONLY 10GB
[ProductKeyPhrase] => SIM ONLY 10GB
[ProductDescription] =>
[NumberSuffix] =>
[PriceExcl] => 35
[TaxCode] => V21
[TaxPercentage] => 21
[PricePeriod] => m
[Modified] => 2022-05-05 04:03:47
)
)
)
As you can see there are two products. I want to have these in a datatable with an foreach.
Since it is my first time, I really do not know how to do this.
Anyone that can help me out?
If you want to access the array of products it would be like this
return view('your_view', [
'products' => $api_response['products']
]);
I want to give criteria where client_id = $this->user['client_id']; so that loggedIn user can see his own data for his Client.
I dont understand how to get client_id from below array.
[Payment] => Array
(
[id] => 1
[location_id] => 138
[cashier_id] => 313
[client_id] => 2
[pay_date] => 2015-02-13 10:51:54
[amount_paid] => 28882685
[total_paid] => 28882685
[change_due] => 0
[pay_method] => CA
[bank] =>
[ref_no] =>
[payment_type] => Bill
[reversal_fee] =>
[reversal_code] =>
[reversal] => 1
[reversal_date] =>
[reversed_by_id] =>
[User] => Array
(
[id] => 313
[username] => tellerb
[client_id] => 8
)
[Location] => Array
(
[id] => 138
[name] => Sector 64
)
)
Your help will be grateful
Use it as nested associative array
$YourArray['Payment']['User']['client_id'];
Always check how you reach that field . Here outer Array is Payment , then you goto User then goto client_id.
I am working on building a json Rest api with CakePHP. It works great, except I can't seem to get the proper structure to the response.
I two tables: Users and Profiles. Users hasOne Profiles. Profiles has a foreign key.
Models: Users.php (with public $hasOne = 'Profile'), Profiles.php
Controller: UsersController.php
The response is:
[2] => Array
(
[User] => Array
(
[id] => 3
[firstname] => test
[lastname] =>
[email] =>
[password] =>
[created] => 2012-09-04 16:44:04
[modified] => 2012-09-04 16:44:04
)
[Profile] => Array
(
[id] =>
[skill] =>
[user_id] =>
)
)
I really want the response to be like this:
[2] => Array
(
[User] => Array
(
[id] => 3
[firstname] => test
[lastname] =>
[email] =>
[Profile] => Array
(
[id] =>
[skill] =>
[user_id] =>
)
)
)
I have looked in the join(), bind(), containable...I can't seem to find the solution for nested table. Any ides to get Profile to be nested within the Users?
Cakephp won't do it, since it isn't the structure it uses to manage data. You will have to do it manually. If you are working with a single result (as the given by find('first')) Try something like this (I haven't tested it):
$result = $this->User->find('first', array('conditions' => array('User.id' => 1)));
Set::insert($result, 'User.Profile', $result['Profile']);
uset($result['Profile']);
For the life of me I can't figure out what's going wrong. When I debug the value of the $order->save operation, I get a 1 (which I assume to mean true). Here's what I'm doing:
$order = $this->Order->find('first', array(
'conditions' => array('Order.token' => urldecode($token))
));
debug($order);
$this->Order->id = $order['Order']['id'];
$orderData = array('Order' => array(
'id' => $order['Order']['id'],
'billing_email' => urldecode($payPalResponse['EMAIL']),
'billing_name' => urldecode($payPalResponse['PAYMENTREQUEST_0_SHIPTONAME']),
'billing_address' => urldecode($payPalResponse['PAYMENTREQUEST_0_SHIPTOSTREET']),
'billing_city' => urldecode($payPalResponse['PAYMENTREQUEST_0_SHIPTOCITY']),
'billing_state' => $payPalResponse['PAYMENTREQUEST_0_SHIPTOSTATE'],
'billing_zipcode' => $payPalResponse['PAYMENTREQUEST_0_SHIPTOZIP']
));
debug($orderData);
$this->Order->save($orderData);
And here's what I'm getting:
controllers/markets_controller.php (line 149)
Array
(
[Order] => Array
(
[id] => 13
[token] => **************
[player_id] => 1
[status_id] => 1
[timestamp] => 2012-02-15 12:09:24
[date_filled] => February 15, 2012
)
[OrderItem] => Array
(
)
)
controllers/markets_controller.php (line 161)
Array
(
[Order] => Array
(
[id] => 13
[billing_email] => *********#************.com
[billing_name] => Test User
[billing_address] => 1 Main St
[billing_city] => San Jose
[billing_state] => CA
[billing_zipcode] => 95131
)
)
Why is it telling me that it's saving but it's not?
Okay, I had tried to clear the cache before, but for some reason it didn't take. I finally cleared the cache file for the Order model, and that fixed it.
I've been banging my head against the wall with a really annoying issue. I have two model classes:
class User extends AppModel {
var $name = 'User';
var $hasMany = array(
'Application' => array(
'className' => 'Application',
'foreignKey' => 'user_id',
'dependent' => false,
)
);
}
class Application extends AppModel {
var $name = 'Application';
var $belongsTo = array(
'User' => array(
'className' => 'User',
'foreignKey' => 'user_id',
)
);
}
I want to pull Applications and the fields of User associated with it.
$this->Applications->find();
No matter what I set $recursive to, it's still giving me only one output:
Array
(
[Applications] => Array
(
[id] => 1
[user_id] => 3
[datecreated] =>
[status] =>
[source] => 1
)
)
On the other hand, when I pull the data from Users table with recursive set to 2, I get all the users, with their applications, WITH the user data associated with the application WITH the applications associated with the user. To put it plain and simple, here's what I get:
Array
(
[0] => Array
(
[User] => Array
(
[id] => 3
[email] => email#email.email
[password] => hashstring
[socialsecurityno] => 21232134123
[role_id] => 3
[firstname] => Firstname
[lastname] => Lastname
[status] => 1
)
[Application] => Array
(
[0] => Array
(
[id] => 1
[user_id] => 3
[datecreated] =>
[status] =>
[source] => 1
[User] => Array
(
[id] => 3
[email] => email#email.email
[password] => hashstring
[socialsecurityno] => 21232134123
[role_id] => 3
[firstname] => Firstname
[lastname] => Lastname
[status] => 1
[Application] => Array
(
[0] => Array
(
[id] => 1
[user_id] => 3
[datecreated] =>
[status] =>
[source] => 1
)
)
)
)
)
)
)
What I want, is to get from the Applications, its associated user info, and that's it. I'm pretty much out of ideas short of creating a habtm relationship between applications and users, which would be technically incorrect, as one user can have many applications but one application only has one user.
Right now, Applications is connected with Users via user_id in Applications table, which... should be kind of obvious, but probably should be noted anyway.
Any kind of help with this could be appreciated, I'm literally out of ideas.
If Model::find is called with no parameters, Cake treats it as though you made this request:
Model::find('first',array('limit'=>1));
This explains why it's only retrieving the first Application. To retrieve all Applications, modify your call to:
$this->Application->find('all');
This doesn't explain why Model::find is ignoring the model's recursive setting, and, indeed, I can't find a way to reproduce that issue, unless it's something silly like you have typoed the model name when setting the recursion level (e.g. $this->Applications->recursive = 1;; note the pluralization of "Application").
Hope this helps.