Dec 22

cakephp with mysql running as virtual host on 10.5 os x leopardThe simpler alternative to running MAMP or XAMPP on Os X is using the built-in PHP, APache and getting a binary of Mysql. Although MAMP and XAMPP are simple ways also.

When I first installed mysql for my mac running Leopard just after it came out (end 2007), it was a bit flakey and casued a lot of people problems. So here is a mini tutorial for putting MySQL on Leopard now, since it is easy now, and more timely given cake php RC4 just got released :)

I can recommend these 2 guides as well as my notes here.

1) http://www.keithmedlin.com/2008/01/installing-cakephp-on-os-x-leopard-1051/

2) http://www.givegoodweb.com/post/53/cakephp-leopard-virtual-hosts

This pic is what we are aiming at with this install!


Right,let’s go! I am just installing Cake on a Mac mini running 10.5.2 and I noticed that finally Mysql seem to have provided a binary .dmg mac package on their website.(I think this came out in November as far as I can tell).

So go get the package from mysql:

http://dev.mysql.com/downloads/mysql/5.0.html#macosx-dmg

make sure and pick the right processor type for your machine!

while waiting for that to download, I recommend also checking out the guides I linked above and set up your shell / profile and Apache for PHP with virtual hosts. This will allow easy development set-up where you can change from one app to another.

Now you should have your mysql .dmg ready by now, and you can just run that. So iside the .dmg you shd have a .pkg for mysql itself. install that first. Then run the start-up item and then finally the preference pane. ( this had problems before with Leopard, I think it is fixed now though!) When it asks I would install for all users, rather than current user only.

try a logout and back in and mysql should start automatically.

that’s pretty much it - check out the 2 linked tutorials to get any more info you need on PHP and so on!

The final gotcha is a weird one. I odn’t know why but if you put localhost as the @host@ in your cake database.php config…you’ll get a socket error in your PHP, when you load up a cakephp app (once you have followed the instructions for virtual hosts and so  on).

So, despite having a working mysql and mysql-connectability via something like CocoaMysql, or the terminal, it does not conenct via PHP.

Then I googled a bit and found arecent blogpost with a simple fix! Just put 127.0.0.1 instead. Or indeed read the rest of the blogpost and get a fuller answer/solution.

luv boobyWomack xxx and a Merry Chrimbo to all cakettes everywhere :)

Oct 31

*updated Jan 30th 08*

Snook blog post

Jonathan Snook points out another solution to an easy http-auth implementation for Cake’s directories (that are really rewrites).

the gist is that you put a <Location “/name_of_dir/”> in your httpd.conf, which you may well have access to if you are telling it the webroot of Cake is the webroot anyway.

Works like a charm with 1.2 for me! Very useful - the original post was in the group.

Hey dudes, second in my Cake tips posts :o

This took me a while to get my head round, since I’m nada. I was wanting incorrect user details for an HTTP authentication to give the user a prompt again, upon a refersh. I struggled to get the Cake default to do this for me, other than in Safari .

And I am still not sure why. But my callback function (as the component has provision for!) below, will allow you to do this. So I can give a user friendly mesage to someone who has got their details wrong.

Handy method then for single admin mini sites:

(in app/app_controller.php)


function beforeFilter() {
if (isset($this->params["admin"])) {
$this->Security->blackHoleCallback = 'incorrect';			$this->Security->requireLogin('*',array('type'=>'basic','realm' => Configure::read('Settings.title')));$this->Security->loginUsers = array("admin" => 'password');}
} 

function incorrect () { 

header('WWW-Authenticate: Basic' .' realm="' . Configure::read('Settings.title') . '"'); 

header('HTTP/1.1 401 Unauthorized'); 

$this->autoRender = false;
$this->layout = ''; 

die('
HTTP/1.1 401 Unauthorized.
Details incorrect. Please refresh.');
} 

Sep 18

update: More on the XHTML technique popup  

I wanted to make a simple popup in my latest Cake app, and so needed to set a blank layout just from looking at the URL, as the page was essentially static that I was going to pop up.

e.g. then my little popup URL caller (hyperlink ;) ) would look like

for a link to http://example.com/pages/coverage/layout:popup

echo $html->link('my popup linky',
array('controller'=>'pages',
'action'=>'coverage',
'layout'=>'popup')
,array(
'onclick'=>
'return Popup.open({url:this.href});'));

that’s the cake url syntax parser doing all the magic there - as in 1.2 the new named paramaters, where one passes the info via GET separated by a : is nimbly handled by just taking its key in the array — e.g. ‘layout’ in this case resolves to popup.

Then I made a quick popup in my layouts folder. It’s totally blank.

But the pages controller display() action usually calls ‘default’ layout. I could simply just make a action in another controller, but this is not very DRY.

So I copied pages_controller to my controllers (overloading the typical one), then added a little switch statement:

// set a custom layout

switch ($this->passedArgs['layout']) {

case 'popup':

$layout = 'popup';

break;default:

$layout = 'default';

break;

}

// change the final line too:

$this->render(join('/', $path),$layout);

the javascript is a slick script that is accessible and uses prototype:

you can also pass it options like width:300 etc so that your popup is not a jumbotron popup.

The magic of CakePHP and Prototype :)

this is my first cake post, might do some more hopefully soon…