Tag Archives: Programming
Cakephp 3 Plugin – Changelogs
Ive finally gotten around to releasing this little app i was working on for Cakephp3. I decided a while ago to abandon Cakephp 2 and go with the new version 3.
Its been a steep learning curve so i wanted to learn as much as i could. So thats where this app/plugin came in.
The Aim:
The goal of the plugin was to allow a way to simply log tasks, changes or articles about the cakephp project your working on.
If your working on a website/project on your own you need a way to record your changes and tasks so i thought this would be an ideal way to learn and release something. Sure you could do the same with Github and better but i think its better to have something like this integrated into your application.
Github & Source:
https://github.com/gerrymcdonnell/cakephp-changelog
Cakephp Tips – Sort Data With the Pagnator Component
If you wanted to sort a Model by a certain field in this case take the field “created” which is a date. We can simply tell cakePHP to pagnate entries by the order they were created by the following example.
public function index() { // we prepare our query, the cakephp way! $this->paginate = array( 'limit' => 20, 'order' => array('created' => 'desc') ); $this->Link->recursive = 0; $this->set('links', $this->Paginator->paginate()); }
More Examples can be found here;
https://www.codeofaninja.com/2013/07/pagination-in-cakephp.html
CakePhp 2 Tip#8-Checking User Ownership
Another common task in Cakephp Applications or any Web Application is making sure that a user can only delete items they own otherwise anyone could erase your entire database.
An example you have created a users table and users can create posts, but we need to ensure that User A can only edit and delete posts belonging to them.
Solution: The isAuthorized() function.
This function will check that the user isAuthorized to do what ever action they are about to under take.
Assuming every posts has a user_id as a foreign key, we can check the current logged in user’s Id against the id stored in the post their about to modify and if they match allow and if not deny.
// app/Controller/PostsController.php public function isAuthorized($user) { // All registered users can add posts if ($this->action === 'add') { return true; } // The owner of a post can edit and delete it if (in_array($this->action, array('edit', 'delete'))) { $postId = (int) $this->request->params['pass'][0]; if ($this->Post->isOwnedBy($postId, $user['id'])) { return true; } } return parent::isAuthorized($user); }
// app/Model/Post.php public function isOwnedBy($post, $user) { return $this->field('id', array('id' => $post, 'user_id' => $user)) !== false; }
Entire User Auth Solution and Guide:
https://github.com/cakephp/docs/blob/master/en/tutorials-and-examples/blog-auth-example/auth.rst
CakePhp tip #5: Joining two fields to create one
Joining two fields to create one (eg to get somebodys name by combining firstname and surname)
You need to create a “VirtualField” in the model;
public $virtualFields = array('fullname' => 'concat(Patient.firstname, "-", patient.surname)');
Then in your controller, to get a drop downlist;
$patients = $this->Exercise->Patient->find('list',array('fields'=>array('fullname')));
Credit to:
http://stackoverflow.com/questions/11822942/cakephp-display-multiple-fields-in-a-single-drop-down
Html 5 Canvas Tutorials
Html 5 Canvas Image Rotation
Every thing you ever wanted to know about rotating an image on a canvas.
http://creativejs.com/2012/01/day-10-drawing-rotated-images-into-canvas/
Html5 Canvas Framework: KinexticJS Tutorials
Flip an Image:
handImg.setScale({x:-1});
JQuery & Flash Image Gallerys,Pagnation Links
Image Gallerys:
http://minishowcase.net/
http://www.dynamicdrive.com/style/csslibrary/item/css-image-gallery/
http://www.simpleviewer.net/simpleviewer/
http://www.cssplay.co.uk/menu/lightbox.html#flower8
http://www.no3dfx.com/polaroid/
http://www.simpleviewer.net/postcardviewer/
http://www.andrewberg.com/photobrowser/afpb_flash.html
http://imagin.ro/imaginLightbox/
http://www.sitepoint.com/photo-gallery-cakephp-flickr/
http://www.flash-gallery.com/zen-flash-gallery/demo/
http://www.flashimagegallery.com/
http://smoothgallery.jondesign.net/
Gallerific:
http://www.twospy.com/galleriffic/
http://www.scriptiny.com/2008/05/ajax-image-gallery-slideshow/
57 more:
http://www.1stwebdesigner.com/css/57-free-image-gallery-slideshow-and-lightbox-solutions/
JQuery Pagnation Plugins:
http://www.jquery4u.com/plugins/10-jquery-pagination-plugins/
Software:
Image Gallerys:
http://visuallightbox.com/
http://www.flashimagegallery.com
CSS3 Menus:
http://css3menu.com/index.html
Handy Web Development Links
CSS Gradients:
http://ie.microsoft.com/testdrive/graphics/cssgradientbackgroundmaker/default.html
CSS rounded Corners:
http://www.css3.info/preview/rounded-border/
36 JQuery Nav Menus:
http://www.1stwebdesigner.com/css/36-eye-catching-jquery-navigation-menus/
Drop Down JQuery Menus:
http://www.queness.com/post/1513/14-outstanding-jquery-navigation-menu-tutorials
45 Useful jQuery Menu Plugins For Better Navigation:
http://www.tripwiremagazine.com/2011/12/jquery-menu-plugins.html
Add Motion To Website: jQuery Animation Plugins From 2010
30 Stylish jQuery Tooltip Plugins For Catchy Designs
300+ Jquery, CSS, MooTools and JS navigation menus
WordPress: Fix missing Visual Editor Toolbar
Since a few of the last WordPress upgrades the Visual editor toolbar you get with wordpress broke and its taken me a while to find a solution but heres one that works.
Use your FTP Client yo login to your hosting account
Delete the following two folders;
- wp-includes
- wp-admin
Source;
http://wordpress.org/support/topic/wp-25-wysiwig-problem-tinymce-does-not-start?replies=18