Fork me on GitHub

Tagged: cakephp RSS

  • britg 10:09 am on January 30, 2009 Permalink | Log in to leave a Comment
    Tags: cakephp   

    Love the new CakePHP API browser! 

    I’ll let the app itself do the talking, but just let me say that I love what the Cake team has done with the new API browser. The best part is the API generator is released as a plugin so we can all enjoy sexy APIs with our cake apps!

    cakeapi

     
    • sex toys 8:31 am on February 7, 2009 Permalink

      thanks!

    • sex toys 4:31 pm on February 7, 2009 Permalink

      thanks!

    • Web Design Lexington 1:50 pm on November 1, 2009 Permalink

      This new plug in helps us implement; allowing other software to interact same way that software might implement a user interface allowing easy interaction for us, humans too.

    • Sex Toys 8:39 am on April 2, 2010 Permalink

      Great app

    • bullet vibrator 6:57 am on March 20, 2012 Permalink

      So many loved to have this kind of app. well, customers’ are hoping to have more this kind of apps. 

  • britg 9:22 am on January 27, 2009 Permalink | Log in to leave a Comment
    Tags: cakephp, ,   

    Three Cheers for CakePHP Backwards Compatibility 

    cake-logoI would make a horrible framework developer.  Why?  Because I don’t have the patience to put the effort into making my code backwards compatible (unless I really, really have to).  Thankfully, the developers of CakePHP are not like me.

    I just had cause to take an old client site that was built on CakePHP 1.0.x and move it over to a new platform with some upgrades in functionality.  Since we are most likely going to be developing a bunch of new features on the site I felt it was important to go ahead and upgrade the cake core libraries to the recently-released 1.2 — a task I was dreading from the moment I thought it.

    But, surprise surprise, the whole ordeal wasn’t an ordeal at all.  In fact was incredibly easy because the Cake devs made it a point to include backwards compatibility. As a result a lot of my legacy code could remain in place to be upgraded gradually.

    Take for instance the following gem.  I was a rough and tumble Cake developer back when I first wrote this and this format was actually never really acceptable in the first place, but it worked in 1.0.x:

    $this->Order_frame->findAll();
    // correct way to access the order_frames table: $this->OrderFrame->findAll();
    
    // in view
    echo $orderFrames['Order_frame']['type'];
    // correct way to access the data: $orderFrames['OrderFrame']['type'];
    

    Now, having used Cake for a couple of years I know the error of my ways. But, to my surprise, when I ran this legacy code locally on a fresh 1.2 core it worked. Huh? There was no way they would still support this ancient syntax! Heck, I dont think they ever supported it, really.

    Anyways, this is a long way of showing my appreciation to the CakePHP devs for building the framework with all the legacy code out there in mind.

     
    • mattmillr 8:41 am on January 27, 2009 Permalink

      Neat. Looks like they *just don't care* whether you use underscore_separation or CamelCase to access properties. I've been mulling something like this over in the back of my mind for our own ORM layer, where we have database tables with underscores but would like to automagically expose them in ActionScript objects where the underscores would just be ugly.

      IIRC, Flex styles do something similar depending on whether you access them as class properties or through CSS. The difference is that it matters that you use the right format in the right place.

    • britg 9:01 am on January 27, 2009 Permalink

      Yeah, I agree about ActionScript camel casing. Some languages just _feel_ like they should be camelcased and other _feel_ like they are underscored — usually correlated to whether they are OO or not.

    • mattmillr 4:41 pm on January 27, 2009 Permalink

      Neat. Looks like they *just don't care* whether you use underscore_separation or CamelCase to access properties. I've been mulling something like this over in the back of my mind for our own ORM layer, where we have database tables with underscores but would like to automagically expose them in ActionScript objects where the underscores would just be ugly.

      IIRC, Flex styles do something similar depending on whether you access them as class properties or through CSS. The difference is that it matters that you use the right format in the right place.

    • britg 5:01 pm on January 27, 2009 Permalink

      Yeah, I agree about ActionScript camel casing. Some languages just _feel_ like they should be camelcased and other _feel_ like they are underscored — usually correlated to whether they are OO or not.

  • britg 1:44 pm on August 26, 2008 Permalink | Log in to leave a Comment
    Tags: cakephp,   

    GeoCouch in CakePHP 

    I released a small php script for easily handling geodata in couchdb via php a while ago, check it out here.  I also put together a short tutorial on how to integrate this script in your CakePHP application.  The article is available here on the CakePHP Bakery.

     
  • britg 7:50 am on August 25, 2008 Permalink | Log in to leave a Comment
    Tags: , cakephp   

    Integrating CakePHP with bbPress – Part 2 

    This is the second of a 3 part tutorial on how to integrate bbPress with CakePHP 1.2.x. When complete, these 3 tutorials will accomplish:

    1. Integrating bbPress in a sub-folder (not a subdomain) of your cake install (part 1 here)
    2. Integrating user registration – when a user registers through your cake application they are automatically registered in bbPress.
    3. Integrating the login – when a user is logged in via the cake application they are automatically logged in in bbPress.

    Part 2 – Integrating User Registration

    This part is a little more tricky, but not unmanageable.   The challenge here is that your Cake application probably uses the Auth component, or a custom user setup.  So you probably have a prebuilt users table and chances are it does not conform to what bbPress is looking for in it’s users table.  Also, the encryption scheme between the two is probably different.

    With that in mind, I’ve made the following design decisions

    1. My Cake users schema will remain intact AND the bbPress users schema will remain intact.
    2. Users must register through my Cake application only
    3. CakePHP is using the built-in Auth component.
    4. When a user registers through my Cake application – I run the necessary logic from the Cake User model to update the bbPress users table.
    5. The bbPress tables are in the same database as my CakePHP tables
    6. I change the encryption scheme of bbPress to conform to my Cake app.

    Step 1: changing the bbPress password encryption.

    If you’ve followed Part 1 of this tutorial, you’ve successfully installed and ran bbPress in a subfolder of your cakephp install.  Navigate to that subfolder, then open following file: bb-includes/backpress/code.wp-pass.php

    Notice two functions, hash_password(...) and check_password(...).  We will overwrite these two functions to match the hashing that takes place in our CakePHP install.  If, as I denoted above, you are using the built-in CakePHP Auth component, this is very simple – just comment out the existing functions and replace them with the following:

    	function hash_password($string) {
    		$string = 'YOUR CONFIGURE::SALT VALUE'.$string;
    		return sha1($string);
    	}
    
    	function check_password($password, $hash, $user_id = '') {
    		$string = 'YOUR CONFIGURE::SALT VALUE'.$password;
    		if(sha1($string) != $hash) {
    			return false;
    		} else {
    			return true;
    		}
    	}

    Replace the YOUR CONFIGURE::SALT VALUE with the appropriate value from your CakePHP application. This can be found in app/config/core.php.

    With these two functions in place, your bbPress user system should be hashing and checking the passwords the same way.

    Step 2: Saving a bbPress user from the CakePHP install.

    Fortunately, CakePHP provides an easy hook into the ORM saving process with the afterSave() model callback.

    To get your User model to save a new bbPress user when a new Cake user is created, add the following functions to your User model script:

    	function afterSave($created)
    	{
    		if($created)
    		{
    			$sql = "INSERT INTO `bb_users`
    			(`user_login`, `user_pass`, `user_nicename`,
    			`user_email`, `user_url`, `user_registered`,
    			`user_status`, `display_name`)
    			VALUES(
    			'".$this->data['User']['username']."',
    			'".$this->data['User']['password']."',
    			'".$this->data['User']['username']."',
    			'".$this->data['User']['email']."',
    			'',
    			NOW(),
    			0, '".$user['User']['username']."')";
    			$this->query($sql);
    		}
    	}

    Notice that we are just creating an SQL statement with all the necessary fields required to successfully insert the user into the bbPress system, and then executing that SQL. Also, if you are using the default functionality of the Auth component, $this->data['User']['password']; should automatically be hashed with the same scheme as Step 1.

    Step 3 – Preventing registration from bbPress

    This is the easy part. Simply add the following line to the top of your register.php script in you bbPress install and replace the path with the correct path to your cake registration page.

    die(header('Location: /path/to/your/cake/registration/page'));

    So, that’s it! Now, when you register a user through your Cake application, they should also appear in the bbPress users table, and you should be able to successfully log into both with the exact same credentials.

    But, the plot thickens – we don’t want our users to have to log in to both the cake app and bbpress. We want them to be logged into both automatigically. Stay tuned for part 3 of this tutorial and I’ll attempt to tackle this very conundrum.

     
    • pengekcs 9:53 am on August 31, 2008 Permalink

      Nice explanation. Simple and easy to follow.

    • pengekcs 9:53 am on August 31, 2008 Permalink

      Nice explanation. Simple and easy to follow.

    • britg 11:20 am on August 31, 2008 Permalink

      Thanks!

    • britg 11:20 am on August 31, 2008 Permalink

      Thanks!

    • Ruben 9:57 am on September 14, 2008 Permalink

      Brillian! cant wait for part 3

    • Ruben 9:57 am on September 14, 2008 Permalink

      Brillian! cant wait for part 3

    • britg 10:46 am on September 14, 2008 Permalink

      No problem! glad to help. Been slammed with other stuff and haven't been able to work on this project, but I'll definitely get around to writing part 3.

    • britg 10:46 am on September 14, 2008 Permalink

      No problem! glad to help. Been slammed with other stuff and haven't been able to work on this project, but I'll definitely get around to writing part 3.

    • Harry 1:32 am on October 24, 2008 Permalink

      Hi. I just came across your article while looking for a forum to use with my cakephp app. I'm so glad you wrote something like this up, it has saved me hours of digging through code. Will you still be witting part 3?

      Anyways, thanks again!

    • Harry 1:32 am on October 24, 2008 Permalink

      Hi. I just came across your article while looking for a forum to use with my cakephp app. I'm so glad you wrote something like this up, it has saved me hours of digging through code. Will you still be witting part 3?

      Anyways, thanks again!

    • britg 6:10 am on October 24, 2008 Permalink

      Thanks, yes I really intend to write part 3 – but unfortunately the project
      I was doing this for has been put on hold for the moment!

    • britg 6:10 am on October 24, 2008 Permalink

      Thanks, yes I really intend to write part 3 – but unfortunately the project
      I was doing this for has been put on hold for the moment!

    • Rob 1:04 pm on March 10, 2009 Permalink

      Thank you, this is a great turoial and this is just what I was looking for!! Looking forward to part 3 if I dont figure it out first!! ;) Cheers

    • Rob 8:04 pm on March 10, 2009 Permalink

      Thank you, this is a great turoial and this is just what I was looking for!! Looking forward to part 3 if I dont figure it out first!! ;) Cheers

    • James 7:01 am on April 28, 2009 Permalink

      Is there any part 3 coming anytime soon?

    • Jeff 8:40 am on August 18, 2009 Permalink

      I'm sure you're sick of hearing it, but please write part 3 soon! Or just a code example! ;)

  • britg 5:13 pm on August 23, 2008 Permalink | Log in to leave a Comment
    Tags: , cakephp,   

    Integrating CakePHP with bbPress – Part 1 

    I’ve been working on StatForge.com for the past few days and one of the community features I want to integrate is a forum.  Rather than go for something bloated like phpbb or vanilla, I decided to go with bbPress from the makers of WordPress.

    This is the first of a 3 part tutorial on how to integrate bbPress with CakePHP 1.2.x.  When complete, these 3 tutorials will accomplish:

    1. Integrating bbPress in a sub-folder (not a subdomain) of your cake install
    2. Integrating user registration – when a user registers through your cake application they are automatically registered in bbPress. (UPDATE: part 2 here)
    3. Integrating the login – when a user is logged in via the cake application they are automatically logged in in bbPress.

    Part 1 – Integrating bbPress in a sub-folder (not a subdomain)

    It may be personal preference, but I’m not a big fan of subdomaining parts of an application.  There are definitely legitamite technical reasons to do so, but when I can get away with it, I try to use subfolders, i.e. http://statforge.com and http://statforge.com/forum/.

    There’s a small hurdle here since CakePHP wants to ReWrite all your paths (if you’ve installed it in your domain root), but it’s easy to overcome.  Find the .htaccess file in the root of your cake install.  It should look like this:

       RewriteEngine on
       RewriteRule    ^$ app/webroot/    [L]
       RewriteRule    (.*) app/webroot/$1 [L]

    This is rewriting all of your requests to the webroot folder. Assuming you want to install bbPress into a subfolder called forum (i.e. http://statforge.com/forum/) the change this .htaccess file to the following:

       RewriteEngine on
    
       RewriteCond %{REQUEST_URI} ^/forum/(.*)$
       RewriteRule ^.*$ - [L]
    
       RewriteRule    ^$ app/webroot/    [L]
       RewriteRule    (.*) app/webroot/$1 [L]

    This simply reads – if the Request starts with /forum/ pass it through normally. If not, let Cake handle it. The only limitation here is that you cannot have a controller named ‘forum’ in your cake application.

    That’s it – you should be able to drop a fresh bbPress install into the /forum subfolder and access it normally without Cake interfering.

    I’ve already integrated the user registration between my CakePHP install and my bbPress install, but I’ve gotta run for the time being. Hopefully tomorrow I’ll throw up part 2 – it’s a bit more complicated. (UPDATE: part 2 here)

     
    • Luke 5:19 am on January 8, 2009 Permalink

      have any luck with the logging in to BBPress at the same time with a single log in?

    • britg 8:18 am on January 8, 2009 Permalink

      No, unfortunately I haven't taken the time to finish this out or the project
      that this was for! I really hope to revisit soon.

    • Luke 7:08 am on January 9, 2009 Permalink

      oh, what a pity :(

      I have seen some posts on a forum of people trying to do the same thing. I don't think it can be too difficult – A matter of an afterFind callback in Cake I suppose once th e User is found?

      not sure about the BB Press end as I have not used it yet, although it looks promising compared to other forum choices. Any thoughts?

      Luke

    • britg 2:19 pm on January 9, 2009 Permalink

      Well, my first approach when I get time to revisit would be to use the same
      cookie mechanism i'm already using in my cake app – namely the cookie
      handler. I usually dont rely just on Sessions for my user login, but set a
      cookie also.

      I would extend the Cookie handler built into cake to tap into the same
      libraries that BBPress is using (either by duplication or inclusion), and
      when I set my cake cookie I also set a BBPress cookie, and a session
      variable if BBPress requires one.

      Hope that helps – and yes, I apologize that I have not finished part 3 – it
      kills me as well!

    • Luke 3:08 pm on January 9, 2009 Permalink

      oh, what a pity :(

      I have seen some posts on a forum of people trying to do the same thing. I don't think it can be too difficult – A matter of an afterFind callback in Cake I suppose once th e User is found?

      not sure about the BB Press end as I have not used it yet, although it looks promising compared to other forum choices. Any thoughts?

      Luke

  • britg 9:49 am on August 8, 2008 Permalink | Log in to leave a Comment
    Tags: cakephp, cms, edit anywhere, , thickbox   

    Code Drive-By: Edit Anywhere Component for CakePHP 

    I call this a code drive-by because I’m just going to dump the code without much explanation.  When I have time I’ll come back and walk through it and turn it into a useful article on the CakePHP bakery.

    This component allows you to manage content (primarily text blocks) on a site if you’re logged in.  The editor pops up in a thickbox.

    Some requirements off the top of my head:

    • CakePHP, duh.
    • jquery
    • thickbox
    • Auth Component

    Again, sorry for the drive-by but hopefully someone will get use out of this.

    controller =& $controller;
    			App::import('Model', 'Setting');
    			$this->Setting = new Setting();
    		}
    
    		function read($field = null) {
    			return $this->render($field);
    		}
    
    		function render($field = null)
    		{
    			$content = $this->Setting->findByField($field);
    
    			if(!empty($content)) {
    				return $this->output($field, $content['Setting']['value']);
    			} else {
    				return $this->output($field, '');
    			}
    		}
    
    		function output($field, $str)
    		{
    			$output = $str;
    			if($this->controller->u['User']['role'] == 'admin') {
    				$output .= $this->editButton($field);
    			}
    			return nl2br($output);
    		}
    
    		function editButton($field) {
    			return '';
    		}
    	}
    ?>
    

    And my Settings Controller looks like:

    Setting->findByField($field);
    
    			if(!empty($content)) {
    				$this->Setting->id = $content['Setting']['id'];
    			}
    
    			if(!empty($this->data))
    			{
    				$content['Setting'] = array(
    					'field' => $field,
    					'value' => $this->data['Setting']['value'],
    				);
    
    				$this->Setting->save($content);
    				die($this->redirect($_REQUEST['r']));
    			}
    
    			$this->set(compact('field', 'content'));
    		}
    	}
    ?>
    
     
    • Romiz 2:47 am on January 12, 2009 Permalink

      It`s cool decision! Inline editors rules!
      Whether you thought about automatic rendering of text blocks?
      I mean that view itself should to know what blocks needed and will call render method of some helper…

    • Romiz 10:47 am on January 12, 2009 Permalink

      It`s cool decision! Inline editors rules!
      Whether you thought about automatic rendering of text blocks?
      I mean that view itself should to know what blocks needed and will call render method of some helper…

  • britg 5:58 pm on July 7, 2008 Permalink | Log in to leave a Comment
    Tags: cakephp, google data api, zend framework   

    Using the Zend Framework in CakePHP 

    What do you get when you combine the powers of CakePHP 1.2.x and the Zend Framework?

    No, not Captain Planet… something much more powerful – the ability to use the Google Data API PHP library! This is useful if you want to use Google Calendar or any of the other services supported by the data API.

    Loading the Zend Framework isn’t as straightforward as App::Import(…), since Zend’s libraries assume that the Zend Framework folder is in your include path. To get around this simply:

    1. Drop the Zend Framework Library folder into your vendors folder
    2. Create a script in your Vendors folder called something like zend_include_path.php with the following statement:
      ini_set('include_path', ini_get('include_path').dirname(__FILE__));
      
    3. In your action, just do the following, replacing Gdata.php with whatever library you wish to load (i.e. Loader.php):
      function myAction() {
           App::import('Vendor', 'zend_include_path');
           App::import('Vendor', 'Zend_Gdata', true, false, 'Zend/Gdata.php');
      
           ...
      }
      

    Voila! You should now be able to instantiate your loaded Zend Library Class and work with it normally.

     
    • David Spreekmeester 10:37 am on September 17, 2008 Permalink

      Hey there, thanks for the advice. Works great, adjusting the include path on the fly like this.

      However, my include path was not ending in a semicolumn, so I had to adjust this in zend_include_path.php:

      ini_set(‘include_path’, ini_get(‘include_path’).';'.dirname(__FILE__));

    • britg 12:43 pm on September 17, 2008 Permalink

      Interesting – i guess the most extensible solution would be to check if
      there is a semicolon and add it if there is not – like your case.
      Thanks for sharing

    • davidcm 7:10 am on October 1, 2008 Permalink

      In fact, is better to use the PATH_SEPARATOR constant to determine the character to use. And there is no need to check if the include path ends with it or not, because an empty entry should no affect.

      ini_set('include_path', ini_get('include_path') . PATH_SEPARATOR . dirname(__FILE__));

    • davidcm 2:10 pm on October 1, 2008 Permalink

      In fact, is better to use the PATH_SEPARATOR constant to determine the character to use. And there is no need to check if the include path ends with it or not, because an empty entry should no affect.

      ini_set('include_path', ini_get('include_path') . PATH_SEPARATOR . dirname(__FILE__));

    • JoshReedSchramm 10:35 pm on September 26, 2009 Permalink

      You good sir are a rockstar. Just found this post and it saved me a ton of headache. *tips hat*

    • Alexmbarton 9:37 am on June 30, 2010 Permalink

      It's been a while since you posted here but i'm having an issue with it.

      I'm getting Warning: require_once(Zend/Gdata/App.php) failed to open stream.

      Fatal error: require_once() [function.require]: Failed opening required 'Zend/Gdata/App.php' (include_path='/Applications/MAMP/bin/php5/lib/php/Users/dir/Sites/student/app/vendors') in /Users/dir/Sites/student/app/vendors/Zend/Gdata.php on line 27

      Any ideas?

      Thanks

      AB

    • kavoreo 1:40 pm on September 12, 2010 Permalink

      Thanks for the advice. This is spiffy! Best of both worlds.

      By the way, does anybody know if convention prefers placing the zend lib files in /vendors or /app/vendors? I have them in /vendors and it seems to work (found out the hard way that it doesn't if you put them in both).

    • skybear 12:31 am on April 5, 2012 Permalink

      I have a web application by zend framework.
      I want to convert to cakephp framework this.
      By the way, do you think I can use this application without converting ?

c
compose new post
j
next post/next comment
k
previous post/previous comment
r
reply
e
edit
o
show/hide comments
t
go to top
l
go to login
h
show/hide help
esc
cancel