



You can download the required files at RSS WRITER
Usage:
example:
$result = mysql_query(“select * from beritas ORDER BY DESC id limit 25″);
now, you can try this script. that is very simple. good luck………




TinyMCE is a nice WYSIWYG web editor by Moxiecode, giving your users a very convenient way to edit HTML content. And guess what, its very easy to use it in your Cake apps !
you need download tinyMCE code for using it on your program. you can download the code on this link download tinyMCE.
following this instruction:
1. you must copy tinyMCE code to app/webroot/js/.
2. place this code on your page if you need use tinyMCE
<?php
echo $javascript->link(‘tiny_mce/tiny_mce.js’);
?>
<script type=”text/javascript”>
tinyMCE.init({
theme : “advanced”,
mode : “textareas”,
theme_advanced_toolbar_location : “top”,
convert_urls : false
});
</script>
3. if you placed that code, tinyMCE an aoutomatically work on textarea input.
that is very simple. you must try this.




if you need thumnail the image, display on your page. you can use helper image thumbnail. this is helpers code for that :
1. you must copy this code on directory app/views/helpers/image.php:
<?php
class ImageHelper extends Helper {
var $helpers = array(‘Html’);
var $cacheDir = ‘imagecache’; // relative to IMAGES_URL path
/**
* Automatically resizes an image and returns formatted IMG tag
*
* @param string $path Path to the image file, relative to the webroot/img/ directory.
* @param integer $width Image of returned image
* @param integer $height Height of returned image
* @param boolean $aspect Maintain aspect ratio (default: true)
* @param array $htmlAttributes Array of HTML attributes.
* @param boolean $return Wheter this method should return a value or output it. This overrides AUTO_OUTPUT.
* @return mixed Either string or echos the value, depends on AUTO_OUTPUT and $return.
* @access public
*/
function resize($path, $width, $height, $aspect = true, $htmlAttributes = array(), $return = false) {
$types = array(1 => “gif”, “jpeg”, “png”, “swf”, “psd”, “wbmp”); // used to determine image type
$fullpath = ROOT.DS.APP_DIR.DS.WEBROOT_DIR.DS.$this->themeWeb.IMAGES_URL;
$url = $fullpath.$path;
if (!($size = getimagesize($url)))
return; // image doesn’t exist
if ($aspect) { // adjust to aspect.
if (($size[1]/$height) > ($size[0]/$width)) // $size[0]:width, [1]:height, [2]:type
$width = ceil(($size[0]/$size[1]) * $height);
else
$height = ceil($width / ($size[0]/$size[1]));
}
$relfile = $this->webroot.$this->themeWeb.IMAGES_URL.$this->cacheDir.’/’.$width.’x’.$height.’_’.basename($path); // relative file
$cachefile = $fullpath.$this->cacheDir.DS.$width.’x’.$height.’_’.basename($path); // location on server
if (file_exists($cachefile)) {
$csize = getimagesize($cachefile);
$cached = ($csize[0] == $width && $csize[1] == $height); // image is cached
if (@filemtime($cachefile) < @filemtime($url)) // check if up to date
$cached = false;
} else {
$cached = false;
}
if (!$cached) {
$resize = ($size[0] > $width || $size[1] > $height) || ($size[0] < $width || $size[1] < $height);
} else {
$resize = false;
}
if ($resize) {
$image = call_user_func(‘imagecreatefrom’.$types[$size[2]], $url);
if (function_exists(“imagecreatetruecolor”) && ($temp = imagecreatetruecolor ($width, $height))) {
imagecopyresampled ($temp, $image, 0, 0, 0, 0, $width, $height, $size[0], $size[1]);
} else {
$temp = imagecreate ($width, $height);
imagecopyresized ($temp, $image, 0, 0, 0, 0, $width, $height, $size[0], $size[1]);
}
call_user_func(“image”.$types[$size[2]], $temp, $cachefile);
imagedestroy ($image);
imagedestroy ($temp);
}
return $this->output(sprintf($this->Html->tags['image'], $relfile, $this->Html->parseHtmlOptions($htmlAttributes, null, ”, ‘ ‘)), $return);
}
}
?>
2. you need call image class on your controller. if you can use the helper
this is code on your controller:
<?php
class PagesController extends AppController{
var $name = ‘Pages’;
var $helpers = array(‘Html’, ‘Javascript’,'Ajax’,'image’);
function index(){
}
function image(){
}
}
?>
that code example use the pages controller.
3. you must call that helpers. place this code on app/views/pages/image.thtml for call the image helpers and copy example image to app/webroot/img/myimage.jpg , create directory app/webroot/img/imagecache for save the image thumbnail.
to call the helpers use this code on your view:
<?
echo $image->resize(‘myimage.jpg’, 150, 150, true);
?>
ok, that code can be use on yor program. good luck to try.




CAPTCHA
captcha is generating library for generating visual (completely automated public Turing test to tell computers and humans apart).
captcha can generate useing component on cake php:
<?php
vendor(‘CaptchaSecurityImages’);
class CaptchaComponent extends Object
{
var $controller;
var $captcha;
function startup(&$controller) {
$this->controller = $controller;
}
function initialize($width = 60, $height = 22, $char = 6, $sec_code = ”)
{
$this->captcha = new CaptchaSecurityImages($width, $height, $char, $sec_code);
}
function code()
{
return $this->captcha->getCode();
}
function secCode()
{
return $this->captcha->getSecCode();
}
function render() {
$this->captcha->render();
return true;
}
function check($userCode, $secCode = ”)
{
if(empty($secCode)){
if($userCode == $_SESSION['security_code']){
unset($_SESSION['security_code']);
return true;
}
}else{
if($userCode == $_SESSION['custom_security_code'][$secCode]){
unset($_SESSION['custom_security_code'][$secCode]);
return true;
}
}
return false;
}
}
?>
Use it in your controller:
<?php
class KomentarsController extends AppController{
var $name = ‘Komentars’;
var $components = array(‘Captcha’);
var $helpers = array(‘Html’,'Ajax’, ‘Javascript’);
function index(){
//echo $_SESSION['security_code'];
//echo @$_SESSION['custom_security_code'][$secCode];
if(!$this->Captcha->check($this->data['Komentar']['code'])){
$pc = ”
<script type=\”text/javascript\”>
Modalbox.show(‘<span>Wrong security code.</span>’, {title: ‘Status’, width: 300});
</script>
“;
$this->set(‘alert’,'Kode verifikasi salah atau belum di isi’);
$alert=”Kode verifikasi salah atau belum di isi”;
//$_SESSION['popupconfirm'] = $pc;
// $this->redirect(‘/request-a-quote’);
//exit;
}else{
}
}
function captcha_image(){
$this->Captcha->initialize();
$this->Captcha->render();
}
}
?>
Display captcha image, in your template view:
<img id=”finder_form_captcha” src=”<?php echo $html->url(‘/komentars/captcha_image’);?>” alt=”" />
place vendors class on vendor directory:
<?php
/*
* File: CaptchaSecurityImages.php
* Author: Simon Jarvis
* Copyright: 2006 Simon Jarvis
* Date: 03/08/06
* Updated: 07/02/07
* Requirements: PHP 4/5 with GD and FreeType libraries
* Link: http://www.white-hat-web-design.co.uk/articles/php-captcha.php
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details:
* http://www.gnu.org/licenses/gpl.html
*
*/
class CaptchaSecurityImages {
var $font = ‘monofont.ttf’;
var $code = ”;
var $width = 0;
var $height = 0;
var $characters = 0;
var $sec_code = ”;
function __construct($width = ’120′, $height = ’40′, $characters = ’6′,$sec_code=”) {
$this->code = $this->generateCode($characters);
$this->width = $width;
$this->height = $height;
$this->characters = $characters;
$this->sec_code = $sec_code;
$this->font = APP . ‘vendors/monofont.ttf’;
//$this->font = BASE_DIR . ‘vendors/monofont.ttf’;
//$this->font = ‘monofont.ttf’;
if(empty($this->sec_code)){
$_SESSION['security_code'] = $this->code;
}else{
$_SESSION['custom_security_code'][$this->sec_code] = $this->code;
}
}
/*$_SESSION['custom_security_code']['company'] = ‘DDRTYU’;
$_SESSION['custom_security_code']['blog'] = ‘ADDASU’;
$_SESSION['custom_security_code']['press'] = ‘ASDSAD’;*/
function getCode()
{
return $this->code;
}
function getSecCode()
{
return $this->sec_code;
}
function render()
{
/* font size will be 75% of the image height */
$font_size = $this->height * 0.75;
$image = @imagecreate($this->width, $this->height) or die(‘Cannot initialize new GD image stream’);
/* set the colours */
$background_color = imagecolorallocate($image, 255, 255, 255);
$line_color = imagecolorallocate($image, 0, 0, 0);
$text_color = imagecolorallocate($image, 0, 0, 0);
$noise_color = imagecolorallocate($image, 100, 120, 180);
/* create textbox and add text */
$textbox = imagettfbbox($font_size, 0, $this->font, $this->code) or die(‘Error in imagettfbbox function’);
$x = ($this->width – $textbox[4])/2;
$y = ($this->height – $textbox[5])/2;
imagettftext($image, $font_size, 5, $x, $y, $text_color, $this->font , $this->code) or die(‘Error in imagettftext function’);
imagerectangle($image, 0, 0, $this->width-1, $this->height-1, $line_color);
/* output captcha image to browser */
header(‘Content-Type: image/jpeg’);
imagejpeg($image);
imagedestroy($image);
}
function generateCode($characters)
{
/* list all possible characters, similar looking characters and vowels have been removed */
$possible = ’23456789bcdfghjkmnpqrstvwxyz’;
$code = ”;
$i = 0;
while ($i < $characters) {
$code .= substr($possible, mt_rand(0, strlen($possible)-1), 1);
$i++;
}
return $code;
}
}
?>




Customizing Scaffold Views
If you’re looking for something a little different in your scaffolded views, you can create them yourself. We still don’t recommend using this technique for production applications, but such a customization may be extremely useful for prototyping iterations.
If you’d like to change your scaffolding views, you’ll need to supply your own:
Example 5.1. Custom Scaffolding Views for a Single Controller
Custom scaffolding views for a PostsController should be placed like so: /app/views/posts/scaffold/index.scaffold.thtml /app/views/posts/scaffold/show.scaffold.thtml /app/views/posts/scaffold/edit.scaffold.thtml /app/views/posts/scaffold/new.scaffold.thtml
Example 5.2. Custom Scaffolding Views for an Entire Application
Custom scaffolding views for all controllers should be placed like so: /app/views/scaffold/index.scaffold.thtml /app/views/scaffold/show.scaffold.thtml /app/views/scaffold/edit.scaffold.thtml /app/views/scaffold/new.scaffold.thtml
If you find yourself wanting to change the controller logic at this point, it’s time to take the scaffolding down from your application and start building it.
One feature you might find helpful is Cake’s code generator: Bake. Bake allows you to generate a coded version of scaffolded code you can then move on to modify and customize as your application requires.




So cool that you’ll want to use it in production apps. Now, we think its cool, too, but please realize that scaffolding is… well… just scaffolding. It’s a bunch of stuff you throw up real quick during the beginning of a project in order to get started. It isn’t meant to be completely flexible. So, if you find yourself really wanting to customize your logic and your views, its time to pull your scaffolding down in order to write some code.
Scaffolding is a great way of getting the early parts of developing a web application started. Early database schemas are volatile and subject to change, which is perfectly normal in the early part of the design process. This has a downside: a web developer hates creating forms that never will see real use. To reduce the strain on the developer, scaffolding has been included in Cake. Scaffolding analyzes your database tables and creates standard lists with add, delete and edit buttons, standard forms for editing and standard views for inspecting a single item in the database. To add scaffolding to your application, in the controller, add the $scaffold variable:
<?php
class CategoriesController extends AppController
{
var $scaffold;
}
?>
One important thing to note about scaffold: it expects that any field name that ends with _id is a foreign key to a table which has a name that precedes the underscore. So, for example, if you have nested categories, you’d probably have a column called parent_id. With this release, it would be best to call this parentid. Also, when you have a foreign key in your table (e.g. titles table has category_id), and you have associated your models appropriately (see Understanding Associations, 6.2), a select box will be automatically populated with the rows from the foreign table (category) in the show/edit/new views. To set which field in the foreign table is shown, set the $displayField variable in the foreign model. To continue our example of a category having a title:
<?php
class Title extends AppModel
{
var $name = 'Title';
var $displayField = 'title';
}
?>




There are some settings in /app/config/core.php you can take advantage of in order to organize your application and craft URLs that make the most sense to you and your users.
The first of these is admin routing. If your application has a ProductsController as well as a NewsController, you might want to set up some special URLs so users with administrative privileges can access special actions in those controllers. To keep the URLs nice and easy to read, some people prefer /admin/products/add and /admin/news/post to something like /products/adminAdd and /news/adminPost.
To enable this, first, uncomment the CAKE_ADMIN line in your /app/config/core.php file. The default value of CAKE_ADMIN is ‘admin’, but you can change it to whatever you like. Remember this string, because you’ll need to prepend it to your administrative actions in your controller. So, admin actions in this case would be named admin_actionName(). Here’s some examples of desired URLs and possible CAKE_ADMIN and controller action settings:
/admin/products/add CAKE_ADMIN = 'admin'
name of action in ProductsController = 'admin_add()'
/superuser/news/post CAKE_ADMIN = 'superuser'
name of action in NewsController = 'superuser_post()'
/admin/posts/delete CAKE_ADMIN = 'admin'
name of action in PostsController = 'admin_delete()'
Using admin routes allows you to keep your logic organized while making the routing very easy to accomplish.
![]() |
Note |
|---|---|
| Please note that enabling admin routes or using them does not enable any sort of authentication or security. You’ll need implement those yourself. |
Similarly, you can enable Cake’s webservices routing to make easier there as well. Have a controller action you’d like to expose as a webservice? First, set WEBSERVICES in /app/config/core.php to ‘on’. This enables some automatic routing somewhat similar to admin routing, except that a certain set of route prefixes are enabled:
What this does is allows you to provide an alternate views that will automatically be available at /rss/controllerName/actionName or /soap/controllerName/actionName. This allows you to create a single action that can have two views: one for normal HTML viewiers, and another for webservices users. By doing this, you can easily allow much of the functionality of your application to be available via webservices.
For example, let’s say I have some logic in my application that tells users who is on the phone in my office. I already have a HTML view for this data, but I want to offer it in XML so it can be used in a desktop widget or handheld application. First I need to enable Cake’s webservice routing:
Example 4.6. /app/config/core.php (partial)
/**
* The define below is used to turn cake built webservices
* on or off. Default setting is off.
*/
define('WEBSERVICES', 'on');
Next, I can structure the logic in my controller just as I normally would:
Example 4.7. messages_controller.php
<?php
class PhonesController extends AppController
{
function doWhosOnline()
{
// this action is where we do all the work of seeing who's on the phone...
// If I wanted this action to be available via Cake's xml webservices route,
// I'd need to include a view at /app/views/posts/xml/do_whos_online.thtml.
// Note: the default view used here is at /app/views/layouts/xml/default.thtml.
// If a user requests /phones/doWhosOnline, they will get an HTML version.
// If a user requests /xml/phones/doWhosOnline, they will get the XML version.
}
}
?>
(Optional) Custom Inflections Configuration
Cake's naming conventions can be really nice - you can name your model Box,
your controller Boxes, and everything just works out. There are occasions
(especially for our non-english speaking friends) where you may run into
situations where Cake's inflector (the class that pluralizes, singularizes,
camelCases, and under_scores) might not work as you'd like. If Cake won't
recognize your Foci or Fish, editing the custom inflections configuration file
is where you'll need to go.
Found at /app/config/inflections.php is a list of Cake variables you can use
to adjust the pluralization, singularization of classnames in Cake, along with
definining terms that shouldn't be inflected at all (like Fish and Deer, for you
outdoorsman cakers) along with irregularities.
Follow the notes inside the file to make adjustments, or use the examples in
the file by uncommenting them. You may need to know a little regex before diving
in.




CakePHP’s global configuration can be found in app/config/core.php. While we really dislike configuration files, it just had to be done. There are a few things you can change here, and the notes on each of these settings can be found within the comments of the core.php file.
DEBUG: Set this to different values to help you debug your application as you build it. Specifying this setting to a non-zero value will force Cake to print out the results of pr( ) and debug( ) function calls, and stop flash messages from forwarding automatically. Setting it to 2 or higher will result in SQL statements being printed at the bottom of the page.
Also when in debug mode (where DEBUG is set to 1 or higher), Cake will render certain generated error pages, i.e. “Missing Controller,” “Missing Action,” etc. In production mode, however (where DEBUG is set to 0), Cake renders the “Not Found” page, which can be overridden in app/views/errors/error404.thtml.
CAKE_SESSION_COOKIE: Change this value to the name of the cookie you’d like to use for user sessions in your Cake app.
CAKE_SECURITY: Change this value to indicate your preferred level of sessions checking. Cake will timeout sessions, generate new session ids, and delete old session files based on the settings you provide here. The possible values are:
CAKE_SESSION_SAVE: Specify how you’d like session data saved. Possible values are:


More Options ...
Categories
Tag Cloud
Blog RSS
Comments RSS


Void « Default
Life
Earth
Wind
Water
Fire
Light 