No variable $config found in cakephp - cakephp-2.0

I am getting this error
No variable $config found in \app\Config\global_constant.php
Please help me to fix this issue.
This is my global_constant file:
<?php
include_once('../../global_constant.php');
include_once('../../settings.php');
?>

Please define a blank array like this in your global constant file
$config = array();

Related

controller logic for included view files in cakephp

As I am including elements/header.ctp file in another main.ctp file..
<?php echo $this->element('header'); ?>
I have included header in main.ctp it is displaying quite good. but when I am writing the query in ElementsController in is throwing an error undefined varible..
Below code for Elements Controller header() is the included file function.
public function header()
{
$this->set('marquee',$this->Newsmaster->find('all',array('order'=>array('Newsmaster.priority DESC'),'limit' =>20)));
$userid = $this->Session->read('user');
}
can anyone help me in solving this please... thank You
Elements Controller is not needed to set "marquee" varaible , you need to code in your usual controller for eg. for pages/index you will need to set variable in PagesController's index function not in under ElementsController

cakePHP not able to use a global variable in my views

I am using cakephp v2.3.4
Have set in the /app/Config/bootstrap.php a global variable as follow;
Configure::write('Bike.Frontwheel','Gazette, 16 inch');
I am not able to see this value in my any of my views, what am I doing wrong?
I am able to change the value in a controller with:
Configure::write('Bike.Frontwheel', $Data['Bike']['description']);
Code in the view:
<?php echo Configure::read('Bike.Frontwheel'); ?>
Set the variable in your controller so that it gets passed to your view:
$this->set('front_wheel', Configure::read('Bike.Frontwheel'));
Then in your view:
<?php echo $front_wheel; ?>
try in the config folder,
for this you need to create a file in the config folder & load that in the bootstrap as shown
Configure::load('custom');
this shows that your file is custom.php
now you can write as
$config['Bike.Frontwheel'] = 'Gazette, 16 inch';
where ever you need you can call this as
$variable = Configure::read('Bike.Frontwheel');

View Error CakePHP UploadPack plugin

I am using CakePHP's UploadPlugin (https://github.com/szajbus/uploadpack). Storing images goes smooth as documented, the problem kicks in when trying to use the helper to view the images:
Fatal Error
Error: Call to a member function image() on a non-object
Code:
<?php echo $upload->image($entry['User']['id'], 'User.avatar') ?>
The helper is correctly loaded in the controllers. What could caseis issue? thanks
UPDATE:
My helper is included as follows:
public $helpers = array('Form', 'UploadPack.Upload');
I had the same issue. I was able to fix it by doing the following:
echo $this->upload->image($MODELNAME, 'MODEL.avatar');

cakephp Form helper $this->data empty

I have a problem with the Form Helper that returned $this->data keeps being empty. In my Forms before there was no problems and I cant figure out what's different here.
For this Form there's not a model containing the data, its just user input for doing a search.
This is my View:
<?php
echo $this->Form->create();
echo $this->Form->input('Postleitzahl');
$options=array('10'=>10,'20'=>20);
echo $this->Form->input('Entfernung',array('type'=> 'select' , 'options'=>array(($options))));
echo $this->Form->end('Suchen');
?>
<?php
echo $this->Form->create(null, array('type' => 'post')); # not sure if that's needed
echo $this->Form->input('Search.Postleitzahl');
$options=array('10'=>10,'20'=>20);
echo $this->Form->input('Search.Entfernung',array('options'=> $options)); # seems shorter and should work
echo $this->Form->end('Suchen');
?>
The above should result into a $this->data array containing something similar to this:
['Search']
['Postleitzahl']: 102929
['Enfernung']: 'foobar'
Just don't double array your array:
'options'=>$options
Not necessarily related to Cake, but the answer to the problem when I had it: if you're including a file upload in your POST, double-check that the file you're uploading isn't larger than the limit specified in your php.ini file.

how to access a function defined in app_controller from a ctp

I have function in app_controller.php.The function is like:
function globalSum($Var1,$Var2)
{
$Var3 = $Var1 + $Var2;
return $Var3;
}
Now I want to access this function from any CTP file to get the value after sum.when I call this function the arments will be send from the ctp file.
So,anybody can tell me how to call this function with arguments from the ctp file??
Thanks in advance..
The way you're trying to do this probably isn't the best, seeing as it's working against the MVC architecture that CakePHP uses.
In MVC, the ctp file is your view and should only act as a template, to the greatest extent possible, with any values that you need in the view should be passed to it from the controller.
You have a number of simple solutions to your problem.
One is simply to do the addition in the view:
index.ctp
<?php
echo $var1 + $var2
?>
For such a simple operation, why bother with a separate function?
If your function is more complicated, you can put it in the AppController and then set the view variable in the controller that the action belongs to. For example:
app_controller.php
<?php
function globalSum($Var1,$Var2) {
$Var3 = $Var1 + $Var2;
return $Var3;
}
?>
posts_controller.php
<?php
function index() {
$this->set('var3', $this->globalSum($var1,$var2));
}
?>
index.ctp
<?php
echo $var3;
?>
Hope that helps.

Resources