Latest Post
Tampilkan postingan dengan label cakephp. Tampilkan semua postingan
Tampilkan postingan dengan label cakephp. Tampilkan semua postingan

Add span tag( or any html tag) to link in cakephp

Written By Unknown on Selasa, 08 Oktober 2013 | 02.08

To add <span> tag to cakephp link add span to label

"<span>Label name</span>"

and add

"array('escape' => false)"

to link as shown in below example.

Example:
<?php echo $this->Html->link(
    '<span>My Label</span>',
    array('action' => 'add'),
    array('escape' => false)
// This line will parse rather then output HTML
); ?>
One thing to note here 'escape' => false' must be added to 3rd parameter of link.
You can see the structure of cakephp link for more information at

http://book.cakephp.org/2.0/en/core-libraries/helpers/html.html

Upload file in cakephp using move_uploaded_file function

Written By Unknown on Sabtu, 21 September 2013 | 03.39

move_uploaded_file()

Easiest way to upload file in cakephp is by using move_uploded_file function.
But it beneficial when you have to put file uploader at few place. If you need
to place large number of form which upload file then use component method otherwise
this is easier and much faster way.

I need one multipart form which can select file to upload i have  created one in
index.ctp and rest of the work will be done by index function in controller.



This is my controller file

<?php
class ContactsController extends ContactManagerAppController {
    public $uses = array('ContactManager.Contact');

    public function index() {
        if($this->request->is('post')){
            pr($this->request->data);
            $filePath = "./img/".$this->request->data['Contact']['image_file']['name']; 
            if(move_uploaded_file($this->request->data['Contact']['image_file']['tmp_name'], $filePath)){
            echo "File uploaded Successfully";
            }
       }
     } 
}








This is view for my Controller


index.ctp
<?php
    echo $this->Form->create('Contact', array('enctype' => 'multipart/form-data', 'class'=>'form-horizontal'));
?>
    <label class="control-label" for="inputError">Image</label>
<?php
    echo $this->Form->file('image_file');
    echo $this->Form->submit(__('Submit') , array('class'=>'btn btn-primary'));
?>




Write sql queries in cakephp controller

Written By Unknown on Kamis, 12 September 2013 | 23.36

How to write sql queries in cakephp controller 

public function index(){
    $result= $this->User->query("SELECT * FROM users ;");  
}

User :- It is the name of my Model
users:- Table name in database

$result:- contain array of result of sql query

Get session information in cakephp

How to get session information in cakephp 

In the controller you can use

$this->Session->read();

to get all details of session variable . And you can use

$this->set('session',$this->Session->read());


to use these values in corresponding view page.

-----------------------------------------------------------------------------------------------------------------------

If you wish to use session variable in each page then use set method in appcontroller to set its value

public function beforefilter(){
$this->set('session',$this->Session->read());
}

Now this session variable is accessible in every page of view.

Note: this should be placed in Appcontroller...

Cakephp 1.2 - include problem of css and js , and improper functioning

Written By Unknown on Rabu, 11 September 2013 | 05.40

Changes to made to be made cake php version 1.2 properly :

1. uncomment the statement in file apache2/conf/httpd.config on wamp server

LoadModule rewrite_module modules/mod_rewrite.so

2. In the same file make sure

 AllowOverride all (if there is none in place of all .. change it to all for your "C:/wamp/www" directory)

3. Make sure that all three .htaccess files have default configuration .. there must not me any change ..

Design form in cakephp

Written By Unknown on Senin, 09 September 2013 | 04.28

Note:Input name should be same as field name in database

Form to be written in .ctp in view

<?php
echo $this->Form->create('Model_name');
echo $this->Form->input('field1');
echo $this->Form->input('field2', array('rows' => '3'));
echo $this->Form->end('submit');
?>

Create two different url for admin and front site in cakephp

Written By Unknown on Jumat, 06 September 2013 | 22.28

Most easy way to do this is by the use of scaffold variable.

Open the controller for which you want to make different admin page
and add the following statement:

public $scaffold='admin';

Now to go to app /config/core.php
and add the following statement:

Configure::write('Routing.prefixes', array('admin'));

Now create function for admin in controller like
public function admin_index(){
   
}


Now you access your admin using http://www.domain.com/admin/controller_name
and site using http://www.domain.com/controller_name

Easy AJAX Pagination Using JQuery CakePHP

Written By Unknown on Minggu, 01 Januari 2012 | 09.05


I was working with CakePHP's Easy AJAX Pagination Using JQuery. I found this as a great code for sorting and paging with jQuery inCakePHP. But i faced a problem in Mozilla Firefox. It is not working in Mozilla Firefox. While in IE and Crome it works fine for me.


For Mozilla Firefox when i debug it, it shows an error like "501 Method Not Implemented". I searched for this error and Google gives the solution likeClearing Cache and Cookie. But neither works for me. Finally i got the issue and the problem is in jQuery load function.



/** 
 * Loads in a URL into a specified divName, and applies the function to
 * all the links inside the pagination div of that page (to preserve the ajax-request) 
 * @param string href The URL of the page to load 
 * @param string divName The name of the DOM-element to load the data into 
 * @return boolean False To prevent the links from doing anything on their own.
 */ 
function loadPiece(href,divName) {     
    $(divName).load(href, {}, function(){ 
        var divPaginationLinks = divName+" #pagination a";
        $(divPaginationLinks).click(function() {      
            var thisHref = $(this).attr("href"); 
            loadPiece(thisHref,divName); 
            return false; 
        }); 
    }); 

If you open the above link and look at jQuery load function. They have passed the second parameter as {} for data. So that was the problem in Mozilla Firefox. You can remove the {} from jQuery load function. If you find any problem in this than let me know by comment.

 
Support : Creating Website | Johny Template | Mas Template
Copyright © 2011. Kumpulan Kata Broadcast Blackberry - All Rights Reserved
Template Created by Creating Website Published by Mas Template
Proudly powered by Blogger