How to apply triming in beforevalidate method in cakephp appmodel - cakephp

I use cakephp framework ,in that i post parent and child model data but i want to remove triming from that. My demo code is
Array
(
[Currency] => Array
(
[Code] => fgfg
[Name] => fg
[Description] =>
[NoOfDecimalPrecision] => 3
[CurrencyName] => bnjmhj
[CurrencySymbol] => hjh
[DecimalPrecisionName] => bjmh
[DecimalPrecisionSymbol] =>
[CurrencyScaleType_058] => 368
[IsPrefixSymbol] => 0
[IsInActive] => 0
[IsExchangeCurrency] => 0
[RevisionNumber] =>
)
[CurrencyDenomination] => Array
(
[0] => Array
(
[LineNo] => 1
[RowState] => 435
[DenominationName] => jhgjk
[DenominationDetails] => kgk
[DenominationValue] => 1
[RevisionNumber] => 1
[DenominationSequence] => 1
)
)
)
In my code currency is parent model and currencydenimination in child model so i want in both case.my data post dyanamic not static.so please suggest solution.

Related

CakePHP 4 Tree Behaviour manual setting left end right (JQuery ordering)

I have used the nestedSortable jQuery plugin (https://github.com/ilikenwf/nestedSortable) to order my categories with drag and drop. Every time a category is been ordered an Ajax request is going to the controller with a post of an array with the complete data of the categories. Everything is working as expected so for;
Array received in controller by Ajax post:
Array
(
[0] => Array
(
[item_id] =>
[parent_id] =>
[depth] => 0
[left] => 1
[right] => 8
)
[1] => Array
(
[id] => 1
[parent_id] =>
[depth] => 0
[left] => 2
[right] => 3
)
[2] => Array
(
[id] => 4
[parent_id] =>
[depth] => 0
[left] => 4
[right] => 5
)
[3] => Array
(
[id] => 2
[parent_id] =>
[depth] => 0
[left] => 6
[right] => 7
)
)
In my controller I have the following function to process:
public function reorder() {
$list = isset($_POST['_list']) ? json_decode($_POST['_list'], true) : null;
foreach ($list as $item) {
if (!empty($item['id'])) {
$category = $this->Categories->get($item['id']);
if (!empty($category)) {
empty($item['parent_id']) ? $category->parent_id = null : $category->parent_id = $item['parent_id'] ;
$category->lft = $item['left'];
$category->rght = $item['right'];
$this->Categories->save($category);
}
}
}
}
When I debug the categories before saving the lft and rght are set correctly, however after saving the lft and rght contain completly different values.
I assume that since TreeBehavior is implemented the save function is doing some checks and resetting lft and rght to other values? Anyway to skip this?

impresspages parse the renturn data from getMenuItems class

I want to build a custom menu output so I am calling this class:
$pages = \Ip\Menu\Helper::getMenuItems('menu1');
It returns this:
Array
(
[0] => Ip\Menu\Item Object
(
[title:protected] => Home
[pageTitle:protected] =>
[url:protected] => http://porto.gigaweb.me/home
[target:protected] =>
[selected:protected] =>
[current:protected] => 1
[children:protected] => Array
(
[0] => Ip\Menu\Item Object
(
[title:protected] => Lorem ipsum
[pageTitle:protected] =>
[url:protected] => http://porto.gigaweb.me/lorem-ipsumy
[target:protected] =>
[selected:protected] =>
[current:protected] =>
[children:protected] =>
[depth:protected] => 2
[disabled:protected] => 0
[blank:protected] => 0
)
[1] => Ip\Menu\Item Object
(
[title:protected] => about
[pageTitle:protected] =>
[url:protected] => http://porto.gigaweb.me/about
[target:protected] =>
[selected:protected] =>
[current:protected] =>
[children:protected] =>
[depth:protected] => 2
[disabled:protected] => 0
[blank:protected] => 0
)
)
[depth:protected] => 1
[disabled:protected] => 0
[blank:protected] => 0
)
)
I have tried to turn it into an array but it returns value like this [*title].
I want to loop through it and output the values but cant seem to do it.
It is an array of objects. Not an array of arrays. So you have to do something like this:
foreach ($pages as $menuItem) {
$page->getTitle();
}
You can find other methods of $page object here http://www.impresspages.org/menu-item
Please keep in mind, that you are getting MenuItem objects, not Page objects.

Amazon Glacier PHP and Jobs

I am trying to delete my archive in Amazon Glacier. I'm doing it via PHP with PHP SDK2.
I have a little problem.. I've launched job to get ArchiveID:
$this->client->initiateJob(array(
'accountId' => '-',
'vaultName' => $aValutName,
'Type' => "inventory-retrieval")
);
after a couple of hours a can see that job has finished, so I am trying to get job's using it's ID:
$res = $this->client->getJobOutput(array(
'accountId' => '-',
'vaultName' => $aValutName,
'jobId' => $aJobID,
));
and as a respons I am given such things:
Guzzle\Service\Resource\Model Object
(
[structure:protected] =>
[data:protected] => Array
(
[body] => Guzzle\Http\EntityBody Object
(
[contentEncoding:protected] =>
[rewindFunction:protected] =>
[stream:protected] => Resource id #152
[size:protected] =>
[cache:protected] => Array
(
[wrapper_type] => PHP
[stream_type] => TEMP
[mode] => w+b
[unread_bytes] => 0
[seekable] => 1
[uri] => php://temp
[is_local] => 1
[is_readable] => 1
[is_writable] => 1
)
[customData:protected] => Array
(
[default] => 1
)
)
[checksum] =>
[status] => 200
[contentRange] =>
[acceptRanges] => bytes
[contentType] => application/json
[archiveDescription] =>
)
)
Has enybody idea why "archiveDescription" is empty?
Maybe there is another way to obtain ArchiveID so I would be able to delete my archive....
Thanx for any help ;D
MK.
OK, the solution was too easy...
public function getJobResult($aValutName, $aJobID) {
$res = $this->client->getJobOutput(array(
'accountId' => '-',
'vaultName' => $aValutName,
'jobId' => $aJobID,
));
$body = EntityBody::factory($res['body']);
$body->rewind();
$inventory = stream_get_contents($body->getStream());
$ArchiveList = json_decode($inventory,1)['ArchiveList'];
$res = array();
foreach($ArchiveList as $archive):
$res[]=$archive['ArchiveId'];
endforeach;
return $res;
}

Looping through the data from database

Hey I have got data in my variable using foreach($report as &rep)
note it is getting things from 4 different table in database
Now when I print my $rep I get the following:
Array
(
[Report] => Array
(
[id] => 246
[emp] => werock
[name] => werock
[organization] => cakephp
[customer] => great
)
[file] => Array
(
[0] => Array
(
[id] => 211
[report_id] => 246
[file_name] =>
[file_type] =>
[file_size] => 0
[file_error] => 4
[file_tag] => 0
)
)
[Engineer] => Array
(
[0] => Array
(
[id] => 232
[report_id] => 246
)
)
[Issue] => Array
(
[0] => Array
(
[id] => 118
[report_id] => 246
[date_created] => 2012-02-10
[status] => wait
)
[1] => Array
(
[id] => 119
[report_id] => 246
[date_created] => 2012-02-10
[status] => debug
)
[2] => Array
(
[id] => 120
[report_id] => 246
[date_created] => 2012-02-10
[status] => Completed
)
)
)
Now what I want to do is access Issues array and check how many array are there in it. in this case 3(0,1,2). and print the value of status for the last index in this case(2).
But when I do $rep['Issue']['status'] I get Undefined index: status. Can you tell me where I might be going wrong.
What about this:
echo $rep['Issue'][count($rep['Issue'])-1]['status'];
Let me know if it works.
Try this
$rep['Issue'][$x]['status']
Where $x is variable you can use in a loop to get values.
You are missing the second index. It should be:
$rep['Issue'][count($rep['Issue'])-1]['status'].
You could also try using Set::extract instead. The Set class is very useful for working with arrays.
$status = Set::extract('/Issue/.[:last]/status', $rep);
if(count($status)){
// $status[0] == the value of status which is 'Complete' in your example
} else {
// no issues
}
I tried another method if just thought of sharing.
$endEl[$rep['Report']['id'] ] = end($rep['Issue'] );
let me know if it's a good way.. it works

cakephp (1.3) - accessing session vars in views

If I do a print_r($_SESSION) in my page.ctp I get:
Array
(
[Config] => Array
(
[userAgent] => b3346028c15f82ac5d4b25c4f50d8718
[time] => 1281034201
[timeout] => 100
)
[manualLogout] => 1
[Message] => Array
(
)
[Auth] => Array
(
[redirect] => /events/add/controller:events
)
[facebookSynced] => 1
)
The var facebookSynced I set in my controller with $this->Session-write() - and there it is in the session as expected. But when I do a pr($this->Session) or a pr($session) from page.ctp I get:
SessionHelper Object
(
[helpers] => Array
(
)
[__active] => 1
[valid] =>
[error] =>
[_userAgent] => b3346028c15f82ac5d4b25c4f50d8718
[path] => /
[lastError] =>
[security] => medium
[time] => 1281016202
[sessionTime] => 1281034202
[watchKeys] => Array
(
)
[id] =>
[host] =>
[timeout] =>
[base] => /Eclipse/Calc_1.3.2/trunk
[webroot] => /Eclipse/Calc_1.3.2/trunk/
[here] => /Eclipse/Calc_1.3.2/trunk/users/login
[params] => Array
(
[controller] => users
[action] => login
[named] => Array
(
)
[pass] => Array
(
)
[plugin] =>
[form] => Array
(
)
[url] => Array
(
[url] => users/login
)
[models] => Array
(
[0] => User
)
)
[action] => login
[data] =>
[theme] =>
[plugin] =>
)
How do I access my session with the facebookSynced var in it, and what is the difference between these two 'sessions'. Extra info: in core.php I have:
Configure::write('Session.save', 'php');
Configure::write('Session.cookie', 'CAKEPHP');
Configure::write('Session.save', 'custom_sesh');
Configure::write('Session.timeout', '180');
Configure::write('Session.checkAgent', true);
Configure::write('Session.start', true);
The contents of custom_sesh is just one line:
ini_set('session.cookie_lifetime', 0);
The first result from print_r($_SESSION) is a list of the values of the actual session variable.
The second result from pr($this->Session) shows the contents of CakePHP's Session helper object.
Both are entirely different things. If you wanted to access the value of your session variable facebookSynced you would probably want to do something like:
$foo = $_SESSION["facebookSynced"];
In your view you should be using the Session helper.
echo $session->read('Key.value');
Where you have written in something like, in your controller,
$this->Session->write('Key.value','example');
if you are using
$this->Session->write('facebookSynced',true);
in your controller,
just use
$foo = $this->Session->read('facebookSynced');
in the view.
as simple as that ! :)

Resources