I am trying to pass a Single/Multi Dimensional array to a second page using SESSION. I read and tried all questions and answers but can not get it done. Here is the 1st page:
<?php
// SendIt.php
SESSION_START();
$iA=array('A1','A2','B2','B1','B3','A3');
print_r($iA);
$_session['iA'] = $iA;
echo '<br>Click to send the array.';
?>
Here is the 2nd Page:
<?php
// GetIt.php
SESSION_START();
$iB = $_SESSION['iA'];
print_r($iB);
echo 'I am Here...';
?>
I do not get any of the iA array in the second page.
I must be missing something simple. Please check it out. Thx
I got help from a different PHP forum site and was advised that: Like any other PHP variable, _SESSION is case sensitive. So the problem is fixed by matching _SESSION variables and making them all upper case.
Related
I´m starting to study PHP and I have a doubt in one lesson about array_search.
The teachers example shows "A peeple who got a 10" and as only one of the people got a 10 everything works fine, showing the person's name.
But I've been trying to use it to fetch more than one result. In this case I created this array, with 3 people taking 10:
$notas2=array(
"Ana"=>4,
"Misca"=>10,
"Chatuba"=>6,
"Jurandir"=>7,
"Musca"=>10,
"Mickey Mouse"=>10,
);
echo array_search(10,$notas2);
This code just returns "Misca". I tried a foreach, but it returned only "MiscaMiscaMiscaMiscaMiscaMisca". lol
foreach(array_search(10,$notas2)as $tirou10){
echo $tirou10;
}
Anyone can help-me?
Tanks.
array_search will export only first corresponding key. If you want to get all people who got 10 use array_keys($notas2, 10) it will return array and instead of echo use var_dump() or var_export()
The PHP function array_search only returns the first entry.
I am trying to setup ACL based on the tutorial in the 2.0 book, but I get HTML script when i run
./Console/cake AclExtras.AclExtras aco_sync
It's really long to post here. In my bootstrap.php file I have
CakePlugin::load('AclExtras');
And in my AppController i have
App::uses('Controller', 'Controller');
I have also tried to go without inputting the plugin to see what happens, and when i do something like this:
$this->Acl->allow($group, 'controllers');
I get this error:
Warning (512): DbAcl::allow() - Invalid node [CORE\Cake\Model\Permission.php, line 176]
Any suggestions on how to make this work?
Thanks in advance
Make sure your ACO table is populated with atleast an entry 'controllers', with no parent_id.
Make sure the first argument of allow is a valid argument, in your case, $group should be a Group object, set with a proper group ID. E.g.
$group = $this->User->Group;
$group->id = 1;
(if you only set $group to be an integer, you're definitely going to get the error you're getting, so be sure to check this!)
Make sure the second argument is a valid argument (valid alias for example).
I am facing a curious situation. I am using CakePHP 2.0 (locally), XAMPP and I wanted to add a simple hit counter in my homepage so I added the following code (very very simple)
<?php
$filename = 'hitcount.txt';
$handle = fopen($filename, 'r');
$hits = trim(fgets($handle)) + 1;
fclose($handle);
$handle = fopen($filename, 'w');
fwrite($handle, $hits);
fclose($handle);
echo $hits;
There is a text file named hitcount.txt which contains the number of hits (everytime I visit the page it should increase the number of hits). It works. The problem appeared when I tried to access the hitcount.txt file. It was empty but the echo of $hits returned the exact result! I deleted the file and it still shows me the expected result! I used a different browser, the same. I deleted CakePHP's cache, no change. I used the same piece of code in another page and it did not complain with some error, returning the expected result.
How is it possible for Cakephp to "see" a file that does not exist? Has it anything to do with Apache?
You probably view the file at the wrong location as CakePHP's. My guess is CakePHP's referring to the file at app/webroot/hitcount.txt.
You might want to define a full path for hitcount.txt so you can be sure that you and CakePHP are both referring to the same location.
<?php
$filename = TMP.'hitcount.txt';
This would locate the file at `app/tmp/hitcount.txt'.
I am trying to save an item through my model, but saving fails.
When I output validationErrors - I get empty array, so no validation problems seem to be available. What could be failing my save()?
function resave($wid, $kTime){
$this->contain();
$word = $this->getById($wid);
// Successfully tretrieved here
$word['ModelName']['column'] = $kTime;
if($this->save($word)){
return 'success';
}else{
// this returns empty array
return $this->validationErrors;
}
}
To save yourself some time in the future, if a save() isn't working, the first place to look is in your SQL log and errors.
You should try installing Debug Kit Toolbar for CakePHP (https://github.com/cakephp/debug_kit). It makes it easy to view your SQL log, along with a bunch of other useful stuff. Or, alternatively, you can just put this in your layout file to view SQL history/errors:
<?php echo $this->element('sql_dump'); ?>
It was a problem with float and array type. I investigated it with gettype() and figured it out.
I've got this problem. I've created file node--mycontenttype.tpl.php to display nodes in custom way. I've listed all the $content array by print_r($content). I can display all the variables except CCK fields. For example I can print out node type like:
<?php print $content['body']['#bundle']; ?>
But if I try to display any CCK field like:
<?php print $content['body']['#object']->field_url[und][0]['value']; ?>
It gives me an error "Notice: Use of undefined constant und - assumed 'und' w include()". Alright, so the "und" means "undefined" for langauge, but nor 'pl', nor 'en' solves the problem. How can I manage this?
Alright, after researching I've finally found an answer. It works, but in some cases it look a bit inefficient. Code goes like this:
<?php
$output = field_get_items('node', $node, 'field_url');
$output = $output[0]['safe_value'];
print $output;
?>
But if you have a lot of CCK fields it looks like you have to launch field_get_items() function a lot of times. If any of you knows a better approach it could be nice you could share.
When you write [und] Drupal (PHP) assumes that there's variable $und defined somewhere in the code.
You should use:
<?php print $content['body']['#object']->field_url['und'][0]['value']; ?>