Archive for category CakePHP
Miss Universe goes Open Source

Miss Universe 2009
Miss Universe goes Open Source! The Miss Universe 2009 website was baked in CakePHP – the PHP MVC framework.
Check out the beauty of the CakePHP and the babes ;)
http://www.missuniverse.com/
Make Ubuntu PHP Localhost Mail Function Work
Posted by admin in CakePHP, JavaScript Core, Linux, PHP Core on January 14, 2009
This article teaches you how to make Ubuntu PHP localhost mail function work, using PHP to send mail from localhost is easy. First, you need to install some PEAR mail packages.
In terminal, run the following command one by one:
sudo pear install mail
sudo pear install Net_SMTP
sudo pear Auth_SASL
sudo pear install mail_mime
After installing the pear packages, you need to install and configure postfix, first, run the following command to install postfix:
sudo apt-get install postfix
after installation, a configuration window will be displayed, you need to configure it:
Step 1: Choose Internet Site
Step 2: Enter localhost at the input area
For the rest of the steps, just follow the default settings. After complete the configuration, it’s time to test the PHP script. Create a PHP file called sendmail.php at your localhost, and copy and paste the code below into it (remember to change the email addresses to yours)
<?
include('Mail.php');
include('Mail/mime.php');
// Constructing the email
$sender = "shi <shichuanr@msn.com>";
$recipient = "Leigh <shichuanr@gmail.com>";
$subject = "Test Email";
$text = 'This is a text message.';
$html = '<html><body><p>This is a html message</p></body></html>';
$crlf = "\n";
$headers = array(
'From' => $sender,
'Return-Path' => $sender,
'Subject' => $subject
);
// Creating the Mime message
$mime = new Mail_mime($crlf);
// Setting the body of the email
$mime->setTXTBody($text);
$mime->setHTMLBody($html);
// Set body and headers ready for base mail class
$body = $mime->get();
$headers = $mime->headers($headers);
// SMTP params
$smtp_params["host"] = "localhost"; // SMTP host
$smtp_params["port"] = "25"; // SMTP Port (usually 25)
// Sending the email using smtp
$mail =&amp; Mail::factory("smtp", $smtp_params);
$result = $mail->send($recipient, $headers, $body);
if($result == 1)
{
echo("Your message has been sent!");
}
else
{
echo("Your message was not sent: " . $result);
}
?>
Now you should be able to receive the mail sent from your localhost. Good Luck! :-)
CakePHP Solution for Could not open input file: acl.php
If you are a reader of the IBM tutorial Cook up Web sites fast with CakePHP, Part 2, and execute the following line of code to create aro named Users:
php acl.php create aro 0 null Users
you may end up get the error message like the one below:
Could not open input file: acl.php
The correct syntax should be, from your cakephp_site/app directory, execute the following line
../cake/console/cake acl create aro root Users
for Dealers, it should be
../cake/console/cake acl create aro root Dealers
Hope this helps :)
CakePHP Solution for Warning: Cannot modify header information – headers already sent
If you are using CakePHP to develop your website, you may get the error message:
Warning: Cannot modify header information - headers already sent
This error is not uncommon, many people bump into this problem, especially for beginners. This error message makes the problem sound very serious, but the problem itself is not that complicated at how. By interpreting the message ‘literally’, you will find that the default error message instruct you to do something you have already done, for instance: create method in controller.
The actual problem is whitespace, yes, it must be somewhere, a whitespace is hiding somewhere, it can be at view, model or controller, it may not be in the file you are opening, because of the way CakePHP works, you might be editing several files before run the test, so the whitespace at the end of the file could be anywhere in the MVC, if you searched and removed all the whitepace, extra empty line, the error should go away.
What if it still doesn’t work?
The solution is simple, search again! People always miss to search Model, because they focus on controller and view and may assume Model just works. Go and do a thorough search again – Seek, you shall find!
Hope this helps! :)
Cook up Web sites fast with CakePHP knownusers.thtml
If you are a reader of Cook up Web sites fast with CakePHP published on IBM, you may find the following line from part 1 of the tutorial:
Replace the contents of knownusers.thtml with the following.
So what the heck is this knowusers.thtml? It’s mentioned nowhere else in the book. Actually it should be knownusers.ctp.
In CakePHP 1.1, .thtml is the extension for view template files, in CakePHP 1.2, it’s changed to .ctp. This tutorial was published sometime ago, in this republished one, the author may forgot to change the syntax.
Hope this helps! :)
CakePHP acl delete aro Correct Systax
For people who use CakePHP cake console to execute ACL command:
acl delete aro Users
You may receive error response, the reason is because you must use the id not the Alias when delete, for instance, if Users has an id of 2, you should execute the command in the following way:
acl delete aro 2
Hope this helps!
Cook up Web sites fast with CakePHP – Invalid Login
If you have been reading and learning from Cook up Web sites fast with CakePHP, and found that after complete Part 1 and Section 2 of part 2, when you try to log in, you may get the error says: Invalid Login.
The reason is because of the md5 password, the users you previously registered using plain text as password are now treated as md5 hashed password, so of course there will be a login problem, the solution is simple, simply delete the existing user rows and register some new users, and the problem will automatically go away.
Hope this helps! :)
CakePHP – the right syntax to use near ‘generateList’
If you have been using the cakePHP 1.2 beta’s scarfold to bake (generate) your controller, when you go to the add article page, there will be an error message like the one below:
Warning (512): SQL Error: 1064: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘generateList’ at line 1 [CORE/cake/libs/model/datasources/dbo_source.php, line 512]
If this happens to you, then that means your cake baked the wrong version of CRUD code for you, to fix the problem, you first locate the controller file, my controller’s name is posts, so my controller file is located at: cake/app/controllers/posts_controller.php.
Looking for the code:
generateList();
It may appear more than once in your code, replace it with:
find('list');
Since CakePHP 1.2, the CakePHP 1.1 syntax generateList(); has been replaced by the powerful find(”).
Hope this helps! :)
Cook up Web sites fast with CakePHP MySQL Syntax Problem
If you have read the CakePHP tutorial Cook up Web sites fast with CakePHP MySQL Syntax Problem, Part 2 from IBM, you may have encountered a problem at Section 3. Scaffolding -> Setting up the product tables -> Creating tables to hold product information. When you run the following MySQL query:
CREATE TABLE 'products' (
'id' INT( 10 ) NOT NULL AUTO_INCREMENT ,
'title' VARCHAR( 255 ) NOT NULL ,
'dealer_id' INT( 10 ) NOT NULL ,
'description' blob NOT NULL ,
PRIMARY KEY ('id')
) TYPE = MYISAM ;
CREATE TABLE 'dealers' (
'id' INT( 10 ) NOT NULL AUTO_INCREMENT ,
'title' VARCHAR( 255 ) NOT NULL ,
PRIMARY KEY ('id')
) TYPE = MYISAM ;
You will get an error message like the one below:
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''products' (
'id' INT( 10 ) NOT NULL AUTO_INCREMENT ,
'title' VARCHAR( 255 ) N' at line 1
The syntax error is that all the ‘ in the query should be `, so the following queries will work fine:
CREATE TABLE `products` (
`id` INT( 10 ) NOT NULL AUTO_INCREMENT ,
`title` VARCHAR( 255 ) NOT NULL ,
`dealer_id` INT( 10 ) NOT NULL ,
`description` blob NOT NULL ,
PRIMARY KEY (`id`)
) TYPE = MYISAM ;
CREATE TABLE `dealers` (
`id` INT( 10 ) NOT NULL AUTO_INCREMENT ,
`title` VARCHAR( 255 ) NOT NULL ,
PRIMARY KEY (`id`)
) TYPE = MYISAM ;
Cook up Web sites fast with CakePHP ACL Problem
In Cook up Web sites fast with CakePHP, Part 2: Bake bigger and better with CakePHP by IBM, you may have problems working with Access Control Lists (ACL).
In your app directory the tutorial states within the terminal define your groups with the following code.
php acl.php create aro 0 null Users
php acl.php create aro 0 null Dealers
When you do this you will get the following response:
Could not open input file: acl.php
Now instead of using
php acl.php create aro 0 null Users
php acl.php create aro 0 null Dealers
try the following code:
../cake/console/cake acl create aro root 'Users'
../cake/console/cake acl create aro root 'Dealers'
now you may get an error message similar to the one below:
Fatal error: Class 'String' not found in /mycakelocation/cake/libs/model/datasources/dbo_source.php on line 1455
Now open the dbo_source.php, on line 29, replace
uses('set');
with
uses('set', 'string');
save the file and run the following lines of code again:
../cake/console/cake acl create aro root 'Users'
../cake/console/cake acl create aro root 'Dealers'
Now you are done!












































