本文整理汇总了PHP中Ak::toJson方法的典型用法代码示例。如果您正苦于以下问题:PHP Ak::toJson方法的具体用法?PHP Ak::toJson怎么用?PHP Ak::toJson使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Ak
的用法示例。
在下文中一共展示了Ak::toJson方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: handle_partial_upload
/**
* Handles a gmail-like file upload.
*
* Just add this code at the beigining of the form action receiver.
*
* if($this->file_upload_helper->handle_partial_upload('/tmp')){ // where /tmp is the temporary directory for uploaded files
* return;
* }
*
* You must add this javascript to your view:
*
* <script src="/javascripts/file_uploader.js" type="text/javascript"></script>
* <script type="text/javascript">
* window.onload = function(){
* FileUploader.start('form_id', {partial:true}); // Change "form_id" for the id you supplied to your form
* }
* </script>
*
* @param bool $send_json_response
*/
function handle_partial_upload($temporary_directory = AK_TMP_DIR, $send_json_response = true)
{
$this->_instantiateCacheHandler();
$this->_setTempDir($temporary_directory);
// Perform some garbage collection
$this->clean_persisted_files();
// If we are uploading files from the special iframe we store the file on the cache for using it later
if ($this->_controller->Request->isPost() && !empty($this->_controller->params['__iframe_file_uploader_call_from'])) {
$uploaded_files = $this->_handle_partial_files($this->_controller->params);
if ($send_json_response) {
$this->_controller->layout = false;
$this->_controller->renderText(Ak::toJson($uploaded_files));
} else {
$this->_controller->params = array_merge($this->_controller->params, $uploaded_files);
}
return true;
// We are requesting the file for downloading
} elseif (!$this->_controller->Request->isPost() && !empty($this->_controller->params['persistence_key'])) {
$this->_send_file($this->_controller->params['persistence_key']);
return true;
// We have "persisted_keys" into the post so lets look for them and populate the params with cached data
} elseif ($this->_controller->Request->isPost() && !empty($this->_controller->params['persisted_keys'])) {
if (!empty($this->_controller->params['persisted_files'])) {
$files = $this->_get_persisted_files_params($this->_controller->params['persisted_files']);
$this->_controller->params = array_merge_recursive($this->_controller->params, $files);
$this->_clean_up_persisted_on_shutdown($this->_controller->params['persisted_keys']);
unset($this->_controller->params['persisted_keys']);
unset($this->_controller->params['persisted_files']);
}
return false;
} else {
return false;
}
return true;
}
示例2: test_should_send_params
public function test_should_send_params()
{
$params = array('testing' => array('user' => 'bermi', 'nested' => array('one', 'two')));
$expected = Ak::toJson($params['testing']);
$query = http_build_query($params);
foreach ($this->verbs as $verb) {
$this->assertEqual($this->Client->{$verb}($this->url . '/json/&' . $query), $expected, "{$verb} passing params via url");
$this->assertEqual($this->Client->{$verb}($this->url . '/json', array('params' => $params)), $expected, "{$verb} passing params via params option");
}
}
示例3: visual_effect
/**
* Returns a JavaScript snippet to be used on the Ajax callbacks for
* starting visual effects.
*
* Example:
* <?= $prototype_helper->link_to_remote(
* 'Reload',
* 'update' => 'posts',
* 'url' => array('action' => 'reload'),
* 'complete' => $scriptaculous_helper->visual_effect('highlight', 'posts', array('duration' => 0.5))) ?>
*
* If no element_id is given, it assumes "element" which should be a local
* variable in the generated JavaScript execution context. This can be
* used for example with drop_receiving_element:
*
* <?= $scriptaculous_helper->drop_receiving_element (..., array('loading' => $scriptaculous_helper->visual_effect('fade'))) ?>
*
* This would fade the element that was dropped on the drop receiving
* element.
*
* For toggling visual effects, you can use 'toggle_appear', 'toggle_slide', and
* 'toggle_blind' which will alternate between appear/fade, slidedown/slideup, and
* blinddown/blindup respectively.
*
* You can change the behaviour with various options, see
* http://script.aculo.us for more documentation.
*/
public function visual_effect($name, $element_id = false, $js_options = array())
{
$element = $element_id ? Ak::toJson($element_id) : "element";
if (!empty($js_options['queue']) && is_array($js_options['queue'])) {
$js_queue = array();
foreach ($js_options['queue'] as $k => $v) {
$js_queue[] = $k == 'limit' ? "{$k}:{$v}" : "{$k}:'{$v}'";
}
if (!empty($js_options['queue'])) {
$js_options['queue'] = '{' . join(',', $js_queue) . '}';
}
} elseif (!empty($js_options['queue'])) {
$js_options['queue'] = "'{$js_options['queue']}'";
}
if (in_array('toggle_' . $name, $this->_toggle_effects)) {
return "Effect.toggle({$element},'" . str_replace('toggle_', '', $name) . "'," . AkJavascriptHelper::_options_for_javascript($js_options) . ");";
} else {
return "new Effect." . AkInflector::camelize($name) . "({$element}," . AkJavascriptHelper::_options_for_javascript($js_options) . ");";
}
}
示例4: _encodeToken
/**
* Given an array of options it will return an encrypted url string
*
* @param array $options token options
* @return string Url ready authentication Token
*/
function _encodeToken($options)
{
return base64_encode(Ak::blowfishEncrypt(Ak::toJson($options), Ak::getSetting('admin', 'token_key')));
}
示例5: toJson
/**
* Generate a json representation of the model record.
*
* parameters:
*
* @param array $options
*
* option parameters:
* array(
* 'collection' => array($Person1,$Person), // array of ActiveRecords
* 'include' => array('association1','association2'), // include the associations when exporting
* 'exclude' => array('id','name'), // exclude the attribtues
* 'only' => array('email','last_name') // only export these attributes
* )
* @return string in Json Format
*/
function toJson($options = array())
{
if (is_array($options) && isset($options[0]) && is_a($options[0], 'AkActiveRecord')) {
$options = array('collection'=>$options);
}
if (isset($options['collection']) && is_array($options['collection']) && $options['collection'][0]->_modelName == $this->_modelName) {
$json = '';
$collection = $options['collection'];
unset($options['collection']);
$jsonVals = array();
foreach ($collection as $element) {
$jsonVals[]= $element->toJson($options);
}
$json = '['.implode(',',$jsonVals).']';
return $json;
}
/**
* see if we need to include associations
*/
$associatedIds = array();
if (isset($options['include']) && !empty($options['include'])) {
$options['include'] = is_array($options['include'])?$options['include']:preg_split('/,\s*/',$options['include']);
foreach ($this->_associations as $key => $obj) {
if (in_array($key,$options['include'])) {
$associatedIds[$obj->getAssociationId() . '_id'] = array('name'=>$key,'type'=>$obj->getType());
}
}
}
if (isset($options['only'])) {
$options['only'] = is_array($options['only'])?$options['only']:preg_split('/,\s*/',$options['only']);
}
if (isset($options['except'])) {
$options['except'] = is_array($options['except'])?$options['except']:preg_split('/,\s*/',$options['except']);
}
foreach ($this->_columns as $key => $def) {
if (isset($options['except']) && in_array($key, $options['except'])) {
continue;
} else if (isset($options['only']) && !in_array($key, $options['only'])) {
continue;
} else {
$val = $this->$key;
$type = $this->getColumnType($key);
if (($type == 'serial' || $type=='integer') && $val!==null) $val = intval($val);
if ($type == 'float' && $val!==null) $val = floatval($val);
if ($type == 'boolean') $val = $val?1:0;
$data[$key] = $val;
}
}
if (isset($options['include'])) {
foreach($this->_associationIds as $key=>$val) {
if ((in_array($key,$options['include']) || in_array($val,$options['include']))) {
$this->$key->load();
$associationElement = $key;
$associationElement = $this->_convert_column_to_xml_element($associationElement);
if (is_array($this->$key)) {
$data[$associationElement] = array();
foreach ($this->$key as $el) {
if (is_a($el,'AkActiveRecord')) {
$attributes = $el->getAttributes();
foreach($attributes as $ak=>$av) {
$type = $el->getColumnType($ak);
if (($type == 'serial' || $type=='integer') && $av!==null) $av = intval($av);
if ($type == 'float' && $av!==null) $av = floatval($av);
if ($type == 'boolean') $av = $av?1:0;
$attributes[$ak]=$av;
}
$data[$associationElement][] = $attributes;
}
}
} else {
$el = &$this->$key->load();
if (is_a($el,'AkActiveRecord')) {
$attributes = $el->getAttributes();
foreach($attributes as $ak=>$av) {
$type = $el->getColumnType($ak);
if (($type == 'serial' || $type=='integer') && $av!==null) $av = intval($av);
if ($type == 'float' && $av!==null) $av = floatval($av);
if ($type == 'boolean') $av = $av?1:0;
$attributes[$ak]=$av;
}
$data[$associationElement] = $attributes;
}
//.........这里部分代码省略.........
示例6: json
function json()
{
$this->renderText(Ak::toJson($this->params['testing']));
}
示例7: _encodeToken
/**
* Given an array of options it will return an encrypted url string
*
* @param array $options token options
* @return string Url ready authentication Token
*/
function _encodeToken($options)
{
return base64_encode(Ak::blowfishEncrypt(Ak::toJson($options), Ak::getSetting(AK_DEFAULT_ADMIN_SETTINGS, 'token_key')));
}
示例8: toJson
function toJson()
{
return Ak::toJson($this->getAttributes());
}
示例9: toJson
/**
* Generate a json representation of the model record.
*
* parameters:
*
* @param array $options
*
* option parameters:
* array(
* 'collection' => array($Person1,$Person), // array of ActiveRecords
* 'include' => array('association1','association2'), // include the associations when exporting
* 'exclude' => array('id','name'), // exclude the attribtues
* 'only' => array('email','last_name') // only export these attributes
* )
* @return string in Json Format
*/
public function toJson($options = array())
{
if (is_array($options) && isset($options[0])) {
$options = array('collection' => $options);
}
if (isset($options['collection']) && (is_array($options['collection']) || $options['collection'] instanceof ArrayAccess) && $options['collection'][0]->_modelName == $this->_Model->getModelName()) {
$json = '';
$collection = $options['collection'];
unset($options['collection']);
$jsonVals = array();
foreach ($collection as $element) {
$jsonVals[] = $element->toJson($options);
}
$json = '[' . implode(',', $jsonVals) . ']';
return $json;
}
/**
* see if we need to include associations
*/
$associatedIds = array();
if (isset($options['include']) && !empty($options['include'])) {
$options['include'] = is_array($options['include']) ? $options['include'] : preg_split('/,\\s*/', $options['include']);
foreach ($this->_Model->getAssociations() as $key => $obj) {
if (in_array($key, $options['include'])) {
$associatedIds[$obj->getAssociationIds() . '_id'] = array('name' => $key, 'type' => $obj->getType());
}
}
}
if (isset($options['only'])) {
$options['only'] = is_array($options['only']) ? $options['only'] : preg_split('/,\\s*/', $options['only']);
}
if (isset($options['except'])) {
$options['except'] = is_array($options['except']) ? $options['except'] : preg_split('/,\\s*/', $options['except']);
}
foreach ($this->_Model->getColumns() as $key => $def) {
if (isset($options['except']) && in_array($key, $options['except'])) {
continue;
} else {
if (isset($options['only']) && !in_array($key, $options['only'])) {
continue;
} else {
$val = $this->_Model->{$key};
$type = $this->_Model->getColumnType($key);
if (($type == 'serial' || $type == 'integer') && $val !== null) {
$val = intval($val);
}
if ($type == 'float' && $val !== null) {
$val = floatval($val);
}
if ($type == 'boolean') {
$val = $val ? 1 : 0;
}
if ($type == 'datetime' && !empty($val)) {
// UTC (Coordinated Universal Time) http://www.w3.org/TR/NOTE-datetime
$val = gmdate('Y-m-d\\TH:i:s\\Z', Ak::getTimestamp($val));
}
$data[$key] = $val;
}
}
}
if (isset($options['include'])) {
foreach ($this->_Model->getAssociations() as $key => $val) {
if (in_array($key, $options['include']) || in_array($val, $options['include'])) {
$this->_Model->{$key}->load();
$associationElement = $key;
$associationElement = $this->_convertColumnToXmlElement($associationElement);
if (is_array($this->_Model->{$key})) {
$data[$associationElement] = array();
foreach ($this->_Model->{$key} as $el) {
if ($el instanceof AkBaseModel) {
$attributes = $el->getAttributes();
foreach ($attributes as $ak => $av) {
$type = $el->getColumnType($ak);
if (($type == 'serial' || $type == 'integer') && $av !== null) {
$av = intval($av);
}
if ($type == 'float' && $av !== null) {
$av = floatval($av);
}
if ($type == 'boolean') {
$av = $av ? 1 : 0;
}
if ($type == 'datetime' && !empty($av)) {
// UTC (Coordinated Universal Time) http://www.w3.org/TR/NOTE-datetime
//.........这里部分代码省略.........
示例10: encodeToken
/**
* Given an array of options it will return an encrypted url string
*
* @param array $options token options
* @return string Url ready authentication Token
*/
static function encodeToken($options)
{
return base64_encode(Ak::blowfishEncrypt(Ak::toJson($options), Ak::getSetting(self::getSettingsNamespace(), 'token_key')));
}