CakePHP 1.3: Issue with saveField - cakephp

I dont understand why I am not able to update a field on the database based on the following code:
$this->User->id = 1;
$this->User->saveField('image','img/default_pic.png');
Basically, I want to change the current image in the Db with a new one.
The code above just clears the value that is currently in the image field, but does not add anything.
As an example, this is what happens:
id username image
=============================
1 admin mypic.jpg
2 john johnPic.jpg
After the code above is executed I get the following result
id username image
=============================
1 admin
2 john johnPic.jpg
I am confused at what is actually happening

SOLVED!
I decided to go back and check on my user.php model class and realized that I had attempted to use MeioUpload before and gave up, but I never removed the var actsAs entry.
As soon as I commented it out, I am now able to upload pictures.
For anyone else that might come across this issue, beforeSave might also caused these kind of problems, according to the following blog: http://blog.phplabs.net/2011/11/cakephp-savefield-not-working.html
Thanks,

What does the sql log say is happening?
My guess is you are actually doing something like
$this->User->saveField('image', $variable)
and $variable is either misspelled or is empty.

Related

Custom webform-mail template in Drupal 7 does not work

I'm trying to customise the webform email template for a specific webform following the steps in THEMING.txt, but those changes aren't being reflected in the form's default email template. I may have made a mistake in multiple places so I'm going to walk through my steps and hopefully someone will be able to spot what I did wrong :)
1) I copied the webform-mail.tpl.php template from /sites/all/modules/webform/templates directory over into the /themes/mytheme/ directory. Is that the correct place to drop it?
2) To test it, I simply changed some of the text. So I just changed 'Submitted on %date' to 'Entered on %date'.
3) I then renamed the page to webform-mail-1226.tpl.php, where 1226 is the number I see in the url when I go to edit the webform.
4) Then I tried to clear the cache, but I think this is the step I did wrong. The THEMING.txt file says to visit admin/settings/performance, but that path doesn't seem to work/exist for me. What I tried instead was admin/config/development/performance/ and then cleared the cache with the options here. Am I supposed to go somewhere else to clear a different cache?
5) I then went to the emails section corresponding to this form, and when I either go to an existing email or create a new one, the default email template does not reflect the changes I tried to implement.
Does anyone have any ideas why this isn't working? Thanks for your time and help :)
Here is checklist you need to verify:
1) Your Step 1 is okay nothing to worry.
2) If it is reflecting the change then it means default webform email template file is working fine.
3)* Here you need to verify node-id you used in filename. www.yoursite.com/node/xxx/webform, xxx = 1226 in the filename.
4) The Drupal 7 - Clear cache correct URL is admin/config/development/performance.
5)* Here you need to check in webform email setting you have to select "Default template".
Try selecting "Default template" the clear Drupal cache and then test.
Helpful link.

CakePhp : new field in the database does not appear on find

I've added a new field in the database but when I retrieve the information regarding that model the new added field does not appear. I've deleted my cache (app/tmp/cache) but this doesn't seems to work.
Putting this line Configure::write('Cache.disable', true); in bootstrap.php make that field magically appear, but disabling the cache isn't something that I want to do, so I've deleted the line and the field is gone.
Does somebody have any idea what am I doing wrong?
Thanks
go to app/Config/core.php and change Configure::write('debug',2);
then run your code

Bugzilla: bugs are not showing up (show up in DB and everything seems to be fine)

I just installed Bugzilla locally and it seems that everything is fine. I can create new products and components. I can also file new bugs and they show up in the database.
But when I want to view them in the web interface, they won't show up.
Instead, at the top of the page this shows up:
Product: ARRAY(0x3735378 Component: ARRAY(0x4275650) Resolution: ARRAY(0x42755a8)
and then below the "Zarro Boogs found."
I couldn't find any information on that on the web, did anybody have similar issues? Thank you!
Please check the bugs table in techzilla database and verify if the bug details are getting updated.
The cgi file which corresponds to the listing of bugs is buglist.cgi.
Template file is:-global/message.html.tmpl
"Zarro Boogs found." is showing because, the values are not correctly entering in the query to display the buglist.
It is evident from the display,
Product: ARRAY(0x3735378 Component: ARRAY(0x4275650) Resolution: ARRAY(0x42755a8)
it is because of the looping problem.
check the display code in the template file or buglist file and correct the loop, then it will dsiplay properly
Jenifer,
Yes, It is because of the zero value in the query. We can check it, by printing the query and checking the value in DB.
Inserts a Named Query (a "Saved Search") into the database, or updates a Named Query that already exists..
We had similar problem. Bugs were not showing in search result list. The problem was in the name of the product when the name of the product was with diacritics (e.g. Czech, Slovak, etc...). When the name of the product is in US ASCII it is all Ok.

Cakephp SQL dump not showing queries

For some reason my cakephp application is not showing any of the queries made to the database. It prints the table fine, but there are not records. What could cause this?
Check to make sure you are pulling the records correctly.
$models = $this->Model->find('all');
// or
$this->Model->recursive = 0;
$this->set('models', $this->paginate());
Then when you add them in the view, be sure you are looping through them correctly:
foreach ($models as $model) {
echo $model['Model']['field_name'];
}
UPDATE
To show the SQL statements, be sure you have the following set in core.php
Configure::write('debug', 2);
Also, in the Layout, besure you have this included someone between the <body> and </body> tags:
<?php echo $this->element('sql_dump'); ?>
I assume that you are getting an empty table with just the "Nr","Query","Error", etc. column headers?
You are getting the empty table because you have "Configure::write('debug',0);" set somewhere before you have "Configure::write('debug',2);" set. Find the first instance of it and delete it or change it to "2".
I know that you have long since fixed this problem but hopefully it helps somebody else in the future.
The CakePHP debug kit can help you. After you install it, you will notice a small (pie-chart) icon on the top right of your CakePHP pages. Clicking on that will allow you to see various useful information, and most importantly for this issue, all the SQL queries that occurred in the back-end upon the page loading.
I faced a similar problem in cakephp. I found that debug($variable) has limitation to the content size. Since you are fetching huge sized content from database, it is not able to print. Try doing print_r($variable) instead. To format it properly, you can do like this
echo "<pre>".print_r($variable)."</pre>";

Controller Redirect issue in CakePHP

I have a controller with name users_controller, within the login action I want to redirect to my affiliate_redirect_controller.php, now I the following code in the users controller to redirect
$this->redirect(array(
'controller'=>'affiliate_redirect',
'action'=>'logRedirect' ));
And then I get the following error which I can't seem to resolve
Error: The requested address '/affiliate_redirect/logRedirect' was not found on this server.
I honestly do not know what this could be, quite new to cakePHP and none of the solutions found work for me.
the contents of affiliate_redirect_controller.php looks like this
class AffiliateRedirectController extends AppController
{
var $name = 'AffiliateRedirect';
function logRedirect(){
}
}
I can see there is a mistake in your code its because of naming convention.
$this->redirect(array(
'controller'=>'affiliate_redirects',
'action'=>'logRedirect' ));
Please see the above changes when you are writing your controller name in lowercase like above it should be plural affiliate_redirects and should not be affiliate_redirect
Apart from this you can use directly redirect as like this also.
$this->redirect('affiliate_redirects/logRedirect');
Please try, it should work.
Do you have a table in your database that corresponds to affiliate redirect controller?
You might want to rethink your logic, and use CakePHP routes to set the URL to what you want. Having a controller named affiliate_redirect_controller doesn't follow CakePHP's naming conventions.
Since I don't know exactly what you're trying to do, I don't know if this will work for you, but maybe consider redirecting to a separate action in UsersController like /users/affiliate_redirect/
Or you can create an AffiliatesController and then redirect to /affiliates/redirect/
Also, if you don't have debug mode set to 2, you should do that. It may help reveal what the actual issue is.
What debug level do you have in app/config/core.php ? Most of the time, when you get the message
Error: The requested address '/controller/action' was not found on this server.
it means you have a debug level set to 0 and increasing it to 1 or 2 allows to get more details about the error.

Resources