Setting up Cakephp for Application Development
Posted on | July 5, 2009 | No Comments
I like to keep the CAKPHP ROOT files (/cake/) in a folder of its own and my /app in the working folders. This way, the CAKEPHP ROOT files are not SVNed and that keeps my repos smaller.
My folder structure:
D:\www\cakephp_1_2
D:\www\video_tutorial\app
D:\www\video_tutorial\vendors
D:\www\project 1\app
D:\www\project 1\vendors
All my vendors files for all projects are stored in D:\www\cakephp_1_2\vendors. If it is project specific, it goes to the project’s own folder.
In the project’s folder, index.php in webroot folder, change the CAKE_CORE_INCLUDE_PATH constant to allow the app to locate the CAKEPHP ROOT files and include them.
D:\www\video_tutorial\app\webroot\index.php
/**
* The full path to the directory which holds "app", WITHOUT a trailing DS.
*
*/
if (!defined('ROOT')) {
define('ROOT', dirname(dirname(dirname(dirname(__FILE__)))));
}
/**
* The actual directory name for the "app".
*
*/
if (!defined('APP_DIR')) {
define('APP_DIR', basename(dirname(dirname(dirname(__FILE__)))).DS.'app');
}
/**
* The absolute path to the "cake" directory, WITHOUT a trailing DS.
*
*/
if (!defined('CAKE_CORE_INCLUDE_PATH')) {
define('CAKE_CORE_INCLUDE_PATH', ROOT.DS.'cakephp_1_2');
}
Video Sharing Website Part 2 : Converting the uploaded video to FLV
Posted on | June 30, 2009 | 2 Comments
This series of blog post will talk about how to setup a Video Sharing Website.
Converting the uploaded video to FLV
This is a ‘on the fly’ conversion example, using Cakephp Framework. I am using the ffmpeg library for the transcoding in my example. The ffmpeg converter supports FLV, MP4 and many more.
ffmpeg supported formats: http://ffmpeg.org/general.html#SEC8
For the most basic video sharing, the user will upload a video, enter a title and a description. The VideoConvertorComponent will take the uploaded video, extract a thumbnail and convert it to FLV. Other users can view the FLV in the flash player.
VideoConvertorComponent:: flv_import() is called in the controller. FLV and thumbnail image is created.
Video Sharing Website Part 1 : Introduction to Video Streaming
Posted on | June 30, 2009 | 1 Comment
This series of blog post will talk about how to setup a Video Sharing Website.
Definition to various methods of video downloads and video format
- Streaming
- HTTP Download
- HTTP Streaming – A combination of Streaming and HTTP Download
Streaming
Use of Video Stream Application servers. Examples of Video Stream Application servers include: Video Desk, Adobe Flash Media Server. To use a Streaming Application Server, you need to have a dedicated server with dedicated bandwidth. Such setups are expensive and can run up to a few thousand dollars per month. This is not for the average user. But more suited for the needs of content delivery network. Like news streaming, on demand TV or Movies. Requires a lot of specialized server setup and maintenance knowledge.
HTTP Download
The usual way files are downloaded completely before you can view them. Longer waiting time. This method would require user to have the plugin that supports the playback installed.
HTTP Streaming
A flash player will play part of the video when it is downloaded. With this method, you can fast forward to any segment you want to watch before the video is downloaded fully. The player will send a request to the server for the seeked segment of the video and the start playing from there. This is call pseudo streaming.
This streaming setup uses three components:
- A Flash Player
- A server side script for the transcoding of uploaded video to different formats, and the pseudo streaming of the video
- An FLV video
The server side script needs to take care of bandwidth throttling, securing the video to prevent leeching, detection of bandwidth to if variable bandwidth video is supported. This will be covered in further posts.
Video Formats Suitable for Online Stream
- FLV (H.263/MP3) – 320px in width
- MP4 (H.264/AAC) – 320px in width ~500kbps
- A TV conversion (720px wide, H.264/AAC, ~1000kbps)
- An HD conversion (1280px wide, H.264/AAC, ~2000kbps)
Higher bitrates or bigger file size will result in longer transcoding time. Since this is the case, the transcoding process has to be ‘behind the scenes’ to avoid letting users wait for a long time. The FLV version is the most commonly used format.
Network Architecture

Working with Cakephp Ajax (Prototype)
Posted on | January 30, 2009 | 1 Comment
I have been working on a project that is quite heavy in ajax, using the AjaxHelper in Cakephp.
To note down a couple of things:
- Set up content type for Ajax response
- Pitfall when commenting out codes
- Callback types
1) Set the content type of Ajax response in app_controller beforeFilter()
if($this->RequestHandler->isAjax()) {
Configure::write('debug', 0);
$this->RequestHandler->setContent('javascript', 'text/javascript');
$this->RequestHandler->respondAs('javascript');
$this->layout = 'ajax';
}
Javascript codes returned in the response will be eval as javascript automatically without setting the evalscript:true in the Ajax options.
2) Always use <?php /* ?><?php */ ?> to comment out. I can’t remember how many times this has got me. I always comment out my html instead of deleting them in case they are needed again. Using html <!– //–> to comment out the html code which is mixed with php codes to generate the ajax sorting headers for table or ajax links, will cause javascript errors.
The error message is usually ‘element is null’, triggered somewhere in prototype.js.
Note to myself: Always use php comments to comment unused codes out!
3) The return callbacks to take note of
- loading (onLoading) : this is where you will want to show your loading message, disable the form to prevent user from submitting again by showing a modal message, etcUse $(’msg’).show() to display the loading spinnerResources for spinners
Generator – http://www.ajaxload.info/
More spinner images – http://www.loadinfo.net/ - complete (onComplete) : This is where you will deal with the response from the server. When using Ajax.Updater, the element will be updated automatically with the response. I am also enabling the form or removing the loading message in this callback.Use $(’msg’).hide() to hid the loading spinner
Reuseable page elements with renderElement()
Posted on | November 18, 2008 | 2 Comments
When you find yourself repeating HTML codes in pages of your website or web application, this is a useful function for factoring your codes. Whenever I make changes to my codes, I will make it a point to refactorize as much as possible. It keeps the codes managable. But over factorizing will make it hard for the next programmer taking over the maintenance of the application.
renderElement() is just one of the ways to factorizing your codes. In Cakephp, you can make use of custom helpers, tempalates, plugins, components to make your code reuseable and tidy.
keep looking »



















