Configure::write('baseUrl', 'http://localhost:9090/cakefoodnew/');
-
Rewrite URL in cakephp core.php
Friday, 3 May 2013
Add this code in core.php
Configure::write('baseUrl', 'http://localhost:9090/cakefoodnew/');
Posted by Unknown at 19:08 | Labels: cakephp | 0 comments | Email This BlogThis! Share to X Share to Facebook |
-
Disabling Layouts and Views in CakePHP
It is easy to disable both the layout and view in CakePHP by putting the following line in your controller action:
$this->autoRender = false;
If you want to disable just the layout, use the following line in your controller action:
$this->layout = false;
And if you only want to disable the view for this action, use the following line in your controller:
$this->render(false);
Note that using $this->layout = false; and $this->render(false); together in your controller action will give you the same results as $this->autoRender = false;
Posted by Unknown at 03:43 | Labels: cakephp | 0 comments | Email This BlogThis! Share to X Share to Facebook |
-
Ajax function
function ajaxRequest(){
$this->layout = 'ajax'; // ajax plain layout
$this->params['data']; // to get form submit values
$this->params['url']; // to get query string
}
Posted by Unknown at 01:42 | Labels: ajax, cakephp | 0 comments | Email This BlogThis! Share to X Share to Facebook |
-
Disable default CakePHP form style
Friday, 26 April 2013
<?php echo $this->Form->create('Banner', array('action' => 'admin_add','type' => 'file','inputDefaults' => array('label' => false,'div' => false))); ?>Posted by Unknown at 19:01 | Labels: cakephp | 0 comments | Email This BlogThis! Share to X Share to Facebook |
-
Upload directory:
$filename = WWW_ROOT . 'uploads' . DS . $image['name'];Posted by Unknown at 18:46 | Labels: cakephp, php | 0 comments | Email This BlogThis! Share to X Share to Facebook |
-
Enable CK editor in CakePHP
Thursday, 4 April 2013
How to install and integrate CKEditor to CakePHP?
- Download CKEditor from www.ckeditor.com
- Copy files from the zipped folder to "webroot/js/ckeditor/"
- In the view where you want to display the editor, put the following script on the top of the page (or somewhere before textarea which you want to contain editor):
<?php echo $this->Html->script('ckeditor/ckeditor');?>
This scipt will include the "webroot/js/ckeditor.js" file to your view. - Create the textarea and give it a class named "ckeditor"
<?php echo $this->Form->textarea('content',array('class'=>'ckeditor'))?>
Posted by Unknown at 23:08 | Labels: cakephp | 0 comments | Email This BlogThis! Share to X Share to Facebook |
-
Multiselect Box CakePHP
Wednesday, 27 March 2013
Making dropdown as multiple select box
<?php echo $this->Form->input('origins', array('multiple' => 'true')); ?>Posted by Unknown at 00:49 | Labels: cakephp | 0 comments | Email This BlogThis! Share to X Share to Facebook |
-
Dynamic input field generation in CakePHP
Tuesday, 26 March 2013
CakePHP and jQuery problems.
This issue plagued me for way longer than it should. Due to lack of documentation online I figured it would be best to represent it here.
I kept getting Black-holed. The most common answer I found online was to disable security altogether. (Seriously, don’t do that). Rather, the correct answer via consensus in the #CakePHP IRC, as well as multiple other hidden forum posts was to disable it on a per hidden field basis.Easy answer. Make this:1echo $this->Form->input('w', array('type' => 'hidden'));Into this:1echo $this->Form->input('w', array('type' => 'hidden', 'security => false));(The last one didn’t work for me as was vastly suggested, but the following worked for me and should be an alternate)1<?php $this->Form->unlockField('Purchase.x'); ?>Happy coding!Refer:http://www.sixteenink.com/tag/unlockfield/Posted by Unknown at 23:48 | Labels: cakephp | 0 comments | Email This BlogThis! Share to X Share to Facebook |
-
Cakephp Admin routing
Sunday, 24 March 2013
Add this in routes.php
if ($plugins = App::objects('plugin')) {
$pluginMatch = implode('|', array_map(array('Inflector', 'underscore'), $plugins));
Router::connect(
"/admin/:plugin/:controller/:action/*",
array('action' => null, 'prefix' => 'admin', 'admin' => true),
array('plugin' => $pluginMatch)
);
}
Router::connect("/admin", array('action' => 'index', 'controller' => 'settings', 'prefix' => 'admin', 'admin' => true));
Router::connect("/admin/:controller", array('action' => 'index', 'prefix' => 'admin', 'admin' => true));
Router::connect("/admin/:controller/:action/*", array('prefix' => 'admin', 'admin' => true));
Posted by Unknown at 19:31 | Labels: cakephp | 0 comments | Email This BlogThis! Share to X Share to Facebook |
-
To create a unique cakephp slug
Generate unique slugs in CakePHPI believe it was Wordpress who came up with the term "slug". It has been adopted by many other systems though, and it basically means the following: a unique identifier which can be used in a URL to create a permalink to a page.At least, that's my interpretation of it. In this article I will show you how you can generate a unique slug easily when working with the CakePHP Framework.Since the slug should be unique across records in the same database table, the best place to store slug-generating functionality is in the AppModel, which is, strictly speaking, the only business logic layer that may access the database.If you haven't got an AppModel created yet, add one in /app/app_model.PHP. You may fill it with the following code:1. <?php2. class AppModel extends Model {3.4. function createSlug ($string, $id=null) {5. $slug = Inflector::slug ($string,'-');6. $slug = low ($slug);7. $i = 0;8. $params = array ();9. $params ['conditions']= array();10. $params ['conditions'][$this->name.'.slug']= $slug;11. if (!is_null($id)) {12. $params ['conditions']['not'] = array($this->name.'.id'=>$id);13. }14. while (count($this->find ('all',$params))) {15. if (!preg_match ('/-{1}[0-9]+$/', $slug )) {16. $slug .= '-' . ++$i;17. } else {18. $slug = preg_replace ('/[0-9]+$/', ++$i, $slug );19. }20. $params ['conditions'][$this->name . '.slug']= $slug;21. }22. return $slug;23. }24. }25. ?>What this code does, is providing a method, createSlug (), which can be accessed from all models in your application. It'll normalize the string, make it URL-friendly and last but not least, it makes it unique.To demonstrate the "unique" part, let's say we've got a record with the title "I love CakePHP". The createSlug method will turn this into "i-love-cakePHP". Human friendly and search-engine friendly.
What happens when I wish to create two more items in my database called "I love CakePHP"? The createSlug method will generate the following two slugs: i-love-cakePHP-1 and i-love-cakePHP-2.This way users can bookmark your URLs and always end up in the right place, even though the titles of your records may be similar.How to use?It's simple, really. Since the method is created in the AppModel base class, you can invoke it from every model in your application. When saving a record, you can simply call...1. $slug = $this->createSlug ('my title');...from within your models, or...1. $slug = $this->MyModel->createSlug ('my title');2. $this->request->data['model']['slug'] = slug;...from within your controllers, right before you insert new data.Note that you have to pass the id from the current record when you're modifying existing records, so it can exclude that from its check, like this:1. $slug = $this->createSlug ('my title', 10);refer :http://www.whatstyle.net/articles/52/generate_unique_slugs_in_cakephpPosted by Unknown at 03:23 | Labels: cakephp | 0 comments | Email This BlogThis! Share to X Share to Facebook |
-
Using foreign key of related model in form field cakephp
Wednesday, 6 March 2013
Here Countrymaster is related to Customermaster as Customermaster belongs to Countrymaster, then Customermaster related to User as User has many Customermaster
To access the customermaster relation in user register form
Controller
$this->set('countrymasters', $this->User->Customermaster->Countrymaster->find('list'));
View file:
<?php echo $this->Form->input('email',array('label' => '')); ?> // this field is from user table
<?php echo $this->Form->input('Customermaster.dob',array('label' => '')); ?> // this field is from customermaster table
<?php echo $this->Form->input('Countrymaster',array('label' => '')); ?> // this field is from countrymster table related to customermaster
Refer
Here’s an example for creating a hasAndBelongsToMany select. Assume that User hasAndBelongsToMany Group. In your controller, set a camelCase plural variable (group -> groups in this case, or ExtraFunkyModel -> extraFunkyModels) with the select options. In the controller action you would put the following:$this->set('groups', $this->User->Group->find('list'));
And in the view a multiple select can be expected with this simple code:echo $this->Form->input('Group');
If you want to create a select field while using a belongsTo- or hasOne-Relation, you can add the following to your Users-controller (assuming your User belongsTo Group):$this->set('groups', $this->User->Group->find('list'));
Afterwards, add the following to your form-view:echo $this->Form->input('group_id');
http://book.cakephp.org/1.3/en/The-Manual/Core-Helpers/Form.html
Posted by Unknown at 23:10 | Labels: cakephp | 0 comments | Email This BlogThis! Share to X Share to Facebook |