Using FCKEditor with Zend Framework (File Browser Enabled)

Filed Under (General) by Wenbert on 28-11-2007

Tagged Under : ,

If you are trying to use FCKEditor with Zend Framework, you might be getting errors where ZF is trying to look for a controller named: “FCKEditor”.

To fix this, open your .htaccess file in your /html directory and add “xml” and “php”. Like something below:

RewriteEngine on
RewriteRule !\.(htm|html|txt|swf|js|ico|gif|jpg|png|css|php|xml)$ index.php

This is so that all files with xml and php extension does not thrown to index.php - which is the bootstrap file of the Zend Framework. You might be asking why add “php” in the .htaccess. Well, FCKEditor has a built-in File Browser. The File Browser has connectors for different server side programming languages - and the default is PHP. So in short, there are PHP files inside the FCKEditor directories. It gets executed when you enable the File Browser in FCKEditor. And FCK also loads XML files. Adding both xml and php in the rewrite rule would allow FCKEditor to run properly inside a Zend Framework application.

The View File
Now, in your view file, you can have something like this:

  1.  
  2. < script type="text/javascript" >
  3.     window.onload = function()
  4.     {
  5.         if(document.getElementById(‘content_text’)) {
  6.             var oFCKeditor = new FCKeditor(‘content_text’) ;
  7.             oFCKeditor.BasePath = "< ?=$this->baseUrl ?>/js/fckeditor/" ;
  8.             oFCKeditor.Height = 500;
  9.             oFCKeditor.ReplaceTextarea() ;
  10.         }
  11.     }
  12. < / script >

Notice the $this->baseUrl in the oFCKeditor.BasePath? Take note of it.

The File Browser Config
Now in /home/ekini/public_html/js/fckeditor/editor/filemanager/connectors/php/config.php I have UserFilesPath set to /images/uploads/ - see below:

$Config['UserFilesPath'] = '/images/uploads/' ;

Make sure the you have CHMOD to 777 the uploads directory.

Bilgehan, got his FckEditor working in Windows using the following config for FckEditor:

$Config[’UserFilesPath’] = ‘/user/’ ;
$Config[’UserFilesAbsolutePath’] = ‘C:/Documents and Settings/Bill/Desktop/v.2.subversion/httpdocs/user/’;

Thanks Bilgehan ;)

I hope that I didn’t miss anything. It took me more than an hour to figure things out :-(
If you have comments, suggestions or corrections feel free to post them below.

Using Zend Framework for a CMS

Filed Under (General) by Wenbert on 25-11-2007

Tagged Under : ,

I have just completed (well almost - but it is now fully functional) my CMS (Content Managment System) using the Zend Framework. I’m calling it “Hamburger” - after the current project I am working on, WorldsGreatestHamburgers.com. I am excited to release this publicly, but I am still working on the Categories and User Management. For now, you can get a preview of the CMS here.

Handling HTML Checkboxes. Execute something when checked/unchecked.

Filed Under (General) by Wenbert on 23-11-2007

Tagged Under : ,

In some cases, you are required to do something (EG: show/hide divs) when a checkbox is clicked. Here is an example using jQuery.

First your checkbox will look like this:

...html code here...

< input name="myCheckBox" id="myCheckBox" value="yes" type="checkbox" /> This is a sample checkbox.

Then somewhere in your HTML head, your Javascript code will look like this:

  1.  
  2. other code here…
  3.  
  4.     $(‘#myCheckBox’).click(function(){
  5.         if (this.checked) {      //this.checked is NOT from jquery
  6.             alert(‘Do any action here.’);
  7.         } else {
  8.             alert(‘Undo the action here.’);
  9.         }
  10.     });
  11.  
  12. other code here…

NOTE: Do not forget to download and then include the required jQuery files in your HTML File.

PHP 5: MySQL Singleton Example

Filed Under (General) by Wenbert on 23-11-2007

Tagged Under : , , ,

What is a Singleton?

In software engineering, the singleton pattern is a design pattern that is used to restrict instantiation of a class to one object. This is useful when exactly one object is needed to coordinate actions across the system. Sometimes it is generalized to systems that operate more efficiently when only one or a few objects exist.

Here is a good example of using a Singleton.

Basically, after including your class, you can do something like this:

  1.  
  2. include_once("MysqlDb.php");
  3. MysqlDB::getInstance()->select("SELECT * FROM `help_category` LIMIT 5");

jQuery on Ruby on Rails

Filed Under (General) by Wenbert on 22-11-2007

Tagged Under : , , ,

I found this:

jRails is a drop-in jQuery replacement for Prototype/script.aculo.us on Rails. Using jRails, you can get all of the same default Rails helpers for javascript functionality using the lighter jQuery library.

jRails provides drop-in functionality for these existing Rails methods.

o Prototype
o form_remote_for
o form_remote_tag
o link_to_remote
o observe_field
o observe_form
o periodically_call_remote
o remote_form_for
o submit_to_remote

o Scriptaculous
o draggable_element
o drop_receiving_element
o sortable_element
o visual_effect

o RJS
o hide
o insert_html
o remove
o replace
o replace_html
o show
o toggle

Click here.

Zend Framework Training

Filed Under (General) by Wenbert on 15-11-2007

Tagged Under : ,

I found this at the Zend Website. The training costs $800 using WeBex - an online training tool.

The Zend Framework (ZF) course is designed for experienced PHP programmers who want to learn to combine ZF concepts and structural elements to utilize the full power of this software development kit for PHP 5 applications.

Zend Framework is an open-source class library with a central theme of “extreme simplicity”. ZF helps you to reduce the tedious details of coding and instead allows developers to be more productive as they focus on the big picture. Utilizing a collection of customizable PHP classes, ZF provides robust functionality suitable for both large and small tasks.
This course combines teaching ZF with the introduction of the Model-View-Component (MVC) design pattern, to ensure you learn current best practices in PHP development.

The Zend Framework course helps you to learn by doing. Each discussion of related components is presented with examples of how best to utilize them in your applications, followed by hands-on exercises. The mini-projects you develop during the course reinforce the concepts you have learned.
The online Zend Training Center allows participants to develop code during the course with your instructor able to see and coach your progress.
Topics include:

* Authentication and Authorization
* Core Infrastructure
* Databases
* Model-View-Controller
* Web and Web Services
* Search
* Mail

File Downloads With Zend Framework

Filed Under (General) by Wenbert on 14-11-2007

Tagged Under : , ,

I have been handling file uploads in most of my web applications. Sometimes, I store them in databases and sometimes I feel like storing them in directories. This post will not deal with uploading files, but rather downloading them. Basically, I used PHP’s readfile() function to read the file and then output it - with the headers set. So here goes…


  1.  
  2. < ?php class ResearchController extends Zend_Controller_Action
  3. {
  4. …rest of the code here…
  5.  
  6.     function downloadFileAction()
  7.     {
  8.         $id = $this->getRequest()->getParam(‘id’);
  9.         $filename = $this->getRequest()->getParam(‘filename’);
  10.         $path = Zend_Registry::get(‘uploadDir’).$id.‘/’.$filename;
  11.         header(‘Content-Type: application/octet-stream’);
  12.         echo readfile ($path);
  13.         exit;  //this is important! you will get a corrupted file if you do not put exit;
  14.     }
  15. }
  16. …rest of the code here…

uploadDir is not accessible through the URL. This is an instance of Zend_Registry which is coded inside the bootstrp file (the index.php in ZF). Let’s just say that it is located in /home/ekini/uploads. While the website is located at /home/ekini/public_html/. The reason for storing the files outside the publicly accessible directly is so that no body can access the file using the URL. For example, if you put your upload directory inside public_html, anyone can access it using this URL: http://www.mysite.com/uploads/confidential_file.pdf. You can avoid this by simply putting out anywhere outside the public_html directory.

In my view file, I would have something like this:

  1.  
  2. http://www.mysite.com/research/downloadFile/id/16/filename/HelloWorld.pdf
  3.  

Where research is the controller, downloadFile is the action, id is the directory inside uploadDir which stores the file that is named: HelloWorld.pdf.

The post is pretty rough on the edges, but I hope you got the idea.

10 projects every php developer should use

Filed Under (General) by Wenbert on 13-11-2007

Tagged Under : , , ,

This news has circulating around the PHP Community for a few days already - posting it here for record purposes.

As a php web developer, you should know that php is probably the language that has the biggest code repository. So no matter what module you want to include in your project there should be an open source solution.

This can help in various ways, but just in case you can’t think of one, here I put a few :

  • Open source is worked by many people, so the result is for sure better than one man’s work
  • You can have free updates to your code, while otherwise you should code the updates each time something new comes up
  • You save development time while your project is getting better

Anyway, after many years as a web developer, I’ve compiled a list of php classes that can be easily integrated in any project and I am regularly use.

  1. For sending emails - phpMailer
  2. User manipulation
  3. Fetching RSS Feeds - magpie rss
  4. Geotargeting - maxmind
  5. Data mining - htmlSQL (i can’t wait to use this!!! :) )
  6. Trackback
  7. Templating System
  8. BBCode
  9. Paypal
  10. WYSIWYG Editor - my favorite! - tinyMCE

Click here for the entire article.

Zend Framework with Smarty Templates

Filed Under (General) by Wenbert on 04-11-2007

Tagged Under : ,

Here is a post by zomg from #zftalk.

So, we want to have a nice syntax for calling Zend’s viewhelpers from Smarty templates. First, we have some issues we have to find solutions for:

* Smarty does not “know” about View Helpers
* View helpers may need arrays or associative arrays as parameters. Smarty has no support for doing this out-of-the-box

The first one is quite simple to solve: Since the Zend_View class knows about viewhelpers and can call them, the SmartyView class also does that. Since we need to create a new class based on Smarty anyway, we can add a method for saving the View instance to it so that the new Smarty class can also call view helpers.

The second one needs more work. Since Smarty’s syntax for passing parameters to functions differs a lot from the typical syntax, we need to think of a nice Smarty-like way of passing arrays and associative arrays as parameters. We also need to dig in the Smarty compiler class which converts the Smarty templates into PHP code. Isn’t it great that I did the digging for you and you can just read about it here?

Click here.

OT: Smarty reminds me of Xoops. I am following the ACL of Xoops in my Zend Framework Apps. Zend_Acl is too complicated for me :(

Subscribe to Rss Feed : Rss