本文整理汇总了PHP中Set::insert方法的典型用法代码示例。如果您正苦于以下问题:PHP Set::insert方法的具体用法?PHP Set::insert怎么用?PHP Set::insert使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Set
的用法示例。
在下文中一共展示了Set::insert方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: edit
function edit($id = null)
{
if (!$id && empty($this->data)) {
$this->Session->setFlash(__('Invalid ResultLookup', true));
$this->redirect(array('action' => 'index'));
}
if (!empty($this->data)) {
parent::archive($id);
$this->data = Set::insert($this->data, 'ResultLookup.user_id', $this->Auth->user('id'));
if ($this->ResultLookup->save($this->data)) {
$this->Session->setFlash(__('The ResultLookup has been saved', true));
$this->redirect(array('action' => 'index'));
} else {
$this->Session->setFlash(__('The ResultLookup could not be saved. Please, try again.', true));
}
}
if (empty($this->data)) {
$this->data = $this->ResultLookup->read(null, $id);
$test_id = $this->data['ResultLookup']['test_id'];
$this->set('test_id', $test_id);
$this->set('id', $id);
}
$tests = $this->ResultLookup->Test->find('list');
$this->set(compact('tests'));
}
示例2: write
/**
* Used to store a dynamic variable in the Configure instance.
*
* Usage:
* {{{
* Configure::write('One.key1', 'value of the Configure::One[key1]');
* Configure::write(array('One.key1' => 'value of the Configure::One[key1]'));
* Configure::write('One', array(
* 'key1' => 'value of the Configure::One[key1]',
* 'key2' => 'value of the Configure::One[key2]'
* );
*
* Configure::write(array(
* 'One.key1' => 'value of the Configure::One[key1]',
* 'One.key2' => 'value of the Configure::One[key2]'
* ));
* }}}
*
* @link http://book.cakephp.org/view/926/write
* @param array $config Name of var to write
* @param mixed $value Value to set for var
* @return boolean True if write was successful
* @access public
*/
public static function write($config, $value = null)
{
$_this =& Configure::getInstance();
if (!is_array($config)) {
$config = array($config => $value);
}
foreach ($config as $name => $value) {
if (strpos($name, '.') === false) {
$_this->{$name} = $value;
} else {
$names = explode('.', $name, 4);
switch (count($names)) {
case 2:
$_this->{$names[0]}[$names[1]] = $value;
break;
case 3:
$_this->{$names[0]}[$names[1]][$names[2]] = $value;
break;
case 4:
$names = explode('.', $name, 2);
if (!isset($_this->{$names[0]})) {
$_this->{$names[0]} = array();
}
$_this->{$names[0]} = Set::insert($_this->{$names[0]}, $names[1], $value);
break;
}
}
}
return true;
}
示例3: write
/**
* Permet d'écrire une donnée dans la session
*
* @param varchar $key Clée de la donnée
* @param mixed $value Donnée à écrire
* @return boolean Vrai si la valeur est insérée, faux sinon
* @access static
* @author koéZionCMS
* @version 0.1 - 30/12/2011
* @see /Koezion/lib/set.php
*/
static function write($key, $value)
{
$session = Set::insert($_SESSION, $key, $value);
//On insère les données et on récupère la nouvelle variable de session
$_SESSION = $session;
//On affecte les données à la variable de session
return Set::classicExtract($_SESSION, $key) === $value;
//On retourne le résultat de la fonction
}
示例4: write
/**
* @param string $path
* @param mixed $data
* @param bool $forUser
* @return void
*/
public function write($path = '', $data, $forUser = true)
{
if (!$path) {
return;
}
$path = $this->_getPath($path, $forUser);
$__cookie = $this->_getGummCookie();
if (strpos($path, '.') === false) {
$__cookie[$path] = $data;
} else {
$__cookie = Set::insert($__cookie, $path, $data);
}
$this->_storeGummCookie($__cookie);
}
示例5: _parseTrueToDefault
function _parseTrueToDefault($config)
{
$_this =& CaptchaConfig::getInstance();
$trueToDefault = Set::normalize($_this->trueToDefault);
foreach ($trueToDefault as $path => $options) {
if (Set::extract($path, $config) === true) {
if (empty($options)) {
$options = Set::extract($path, $_this->defaultConfig);
}
$config = Set::insert($config, $path, $options);
}
}
return $config;
}
示例6: afterFind
/**
* After find callback
* @param $result array
* @result $result array
*/
function afterFind($results)
{
$results2[0]['Preference'] = Configure::read('Preference');
$skip = array('user_id', 'created', 'modified', 'id');
foreach ($results[0]['Preference'] as $key => $value) {
if (isset($value) && !is_null($value)) {
if (!in_array($key, $skip)) {
$key = str_replace('_', '.', $key);
$results2[0]['Preference'] = Set::insert($results2[0]['Preference'], $key, $value);
} else {
$results2[0]['Preference'][$key] = $value;
}
}
}
return $results2;
}
示例7: extractHierarchicMulti
function extractHierarchicMulti($pathsAssoc, $data = null, $options = array())
{
$defaultOptions = array('extractNull' => true);
$options = array_merge($defaultOptions, $options);
$res = array();
foreach ($pathsAssoc as $name => $paths) {
$val = SetMulti::extractHierarchic($paths, $data, $options);
if (!is_null($val) || $options['extractNull']) {
if (is_numeric($name)) {
$res[$name] = $val;
} else {
$res = Set::insert($res, $name, $val);
}
}
}
return $res;
}
示例8: connect
/**
* Connects to the database. Options are specified in the $config instance variable.
*
* @return boolean Connected.
* @throws MissingConnectionException
*/
public function connect()
{
if ($this->connected !== true) {
if (Set::check($this->config, 'login')) {
$this->config = Set::insert($this->config, 'request.uri.user', Set::get($this->config, 'login'));
}
if (Set::check($this->config, 'password')) {
$this->config = Set::insert($this->config, 'request.uri.pass', Set::get($this->config, 'password'));
}
try {
$this->Socket = new HttpSocket($this->config);
$this->connected = true;
} catch (SocketException $e) {
throw new MissingConnectionException(array('class' => $e->getMessage()));
}
}
return $this->connected;
}
示例9: add
/**
* Add a menu item
*
* @param string $path dot separated path in the array.
* @param array $options menu options array
* @return void
*/
public static function add($path, $options)
{
$pathE = explode('.', $path);
$pathE = array_splice($pathE, 0, count($pathE) - 2);
$parent = join('.', $pathE);
if (!empty($parent) && !Set::check(self::$_items, $parent)) {
$title = Inflector::humanize(end($pathE));
$o = array('title' => $title);
self::_setupOptions($o);
self::add($parent, $o);
}
self::_setupOptions($options);
$current = Set::extract($path, self::$_items);
if (!empty($current)) {
self::_replace(self::$_items, $path, $options);
} else {
self::$_items = Set::insert(self::$_items, $path, $options);
}
}
示例10: calcAllFormAResults
function calcAllFormAResults($sub_num = null)
{
$allFormAResults = null;
$allTeachers = $this->query("select id,username,name from users as User where group_id=2");
$i = 1;
foreach ($allTeachers as $teacher) {
$teachersResults = $this->calcFormAResults($teacher['User']['id'], $sub_num);
if (!is_string($teachersResults) && isset($teachersResults)) {
foreach ($teachersResults as $teachersResult) {
if (!is_string($teachersResult)) {
$teachersResult['teacherUserName'] = $teacher['User']['username'];
$teachersResult['teacherName'] = $teacher['User']['name'];
$allFormAResults = Set::insert($allFormAResults, $i++, $teachersResult);
}
}
}
}
//debug($allFormAResults);
return $allFormAResults;
}
示例11: edit
function edit($id = null)
{
if (!$id && empty($this->data)) {
$this->Session->setFlash(__('Invalid Test', true));
$this->redirect(array('action' => 'index'));
}
if (!empty($this->data)) {
parent::archive($id);
$this->data = Set::insert($this->data, 'Test.user_id', $this->Auth->user('id'));
if ($this->Test->save($this->data)) {
$this->Session->setFlash(__('The Test has been saved', true));
$this->redirect(array('action' => 'index'));
} else {
$this->Session->setFlash(__('The Test could not be saved. Please, try again.', true));
}
}
if (empty($this->data)) {
$this->data = $this->Test->read(null, $id);
}
}
示例12: get_vol_horaire_a_attribuer_with_loop
function get_vol_horaire_a_attribuer_with_loop($id = 'all')
{
// Méthode 3
if ($id == null or $id == 'all') {
// à l'aide d'une requête find all et d'une boucle
$temp = $this->find('all');
$result = array();
foreach ($temp as $key => $matiere) {
$matiere_id = $matiere['Matiere']['id'];
$result = Set::insert($result, $matiere_id, array('h_cours' => $matiere['Matiere']['h_cours'], 'h_td' => $matiere['Matiere']['h_td'] * $matiere['Filiere']['nb_gr_td'], 'h_tp' => $matiere['Matiere']['h_tp'] * $matiere['Filiere']['nb_gr_tp']));
}
return $result;
} else {
// à l'aide d'une requête read recursive et du calcul heure_matiere*nb_gr
$this->recursive = 0;
$matiere = $this->read(null, $id);
$result = array('h_cours' => $matiere['Matiere']['h_cours'], 'h_td' => $matiere['Matiere']['h_td'] * $matiere['Filiere']['nb_gr_td'], 'h_tp' => $matiere['Matiere']['h_tp'] * $matiere['Filiere']['nb_gr_tp']);
return $result;
}
}
示例13: getBilanServiceWithSqlView
function getBilanServiceWithSqlView($id = 'all')
{
// Méthode 1 : à l'aide d'une vue SQL dans la base
$this->VuePersosBilanServices =& ClassRegistry::init('VuePersosBilanServices');
$this->VuePersosBilanServices->recursive = -1;
if ($id == 'all' or $id == null) {
$temp = $this->VuePersosBilanServices->find('all');
// ToDo : mettre en forme l'array pour avoir perso_id comme clé
//$temp=Set::combine($temp, '{n}.VuePersosBilanServices.id', '{n}.VuePersosBilanServices.h_tp');
$result = array();
foreach ($temp as $key => $matieresperso) {
//debug($result($matieresperso['VuePersosBilanServices']['id'])=1);
//$result($matieresperso['VuePersosBilanServices']['id'])=$matieresperso['VuePersosBilanServices']['h_cours'];
$result = Set::insert($result, $matieresperso['VuePersosBilanServices']['id'], array('h_cours' => $matieresperso['VuePersosBilanServices']['h_cours'], 'h_td' => $matieresperso['VuePersosBilanServices']['h_td'], 'h_tp' => $matieresperso['VuePersosBilanServices']['h_tp']));
}
return $result;
//return $temp;
} else {
$temp = $this->VuePersosBilanServices->read(null, $id);
return $temp['VuePersosBilanServices'];
}
}
示例14: __combine_array
function __combine_array($arr1, $arr2)
{
$number = count($arr1);
// find the first index for the next result
foreach ($arr2 as $element2) {
$test = true;
foreach ($arr1 as $element1) {
if ($element1 == $element2) {
$test = false;
break;
}
}
if ($test) {
$arr1 = Set::insert($arr1, '\\' . $number, $element2);
}
$number += 1;
}
return $arr1;
}
示例15: write
/**
* Writes value to given session variable name.
*
* @param mixed $name Name of variable
* @param string $value Value to write
* @return boolean True if the write was successful, false if the write failed
* @access public
*/
public function write($name, $value)
{
if (empty($name)) {
return false;
}
if (in_array($name, $this->watchKeys)) {
trigger_error(sprintf(__('Writing session key {%s}: %s', true), $name, Debugger::exportVar($value)), E_USER_NOTICE);
}
$this->__overwrite($_SESSION, Set::insert($_SESSION, $name, $value));
return Set::classicExtract($_SESSION, $name) === $value;
}