RSS Feed

More php / mySQL | html | css | js

     Notes: PHP / MYSQL | HTML | CSS | JS
free-php-scripts
free-joomla-extensions

Feb 02
2011

Using CodeIgniter with Joomla

Posted by kelchuk in Untagged 

Codeigniter can be used within Joomla. There is a component which can be installed so that this procedure can occur. The website for which there is some documentation and the download can be found here. When I first arrived at this website, I was relieved to find it had been developed by Azrul, since I have worked with their extensions and find them excellent. For Joomla 1.5, you can install the component through the backend installer and create a menu item. The external link works best with the proper url. The extension is a little dated since it uses Codeigniter 1.5.3. Codeigniter is now in version 2.0. You could upgrade to 1.7.3 or 2.0 using the files and instructions at the Codeigniter website. Personally, I will wait for new revised books about Codeigniter 2.0 before I move from a previous version. UNLIKE AZRUL'S EXAMPLE, if you want to use a newer version you can take your current Codeigniter application and insert it into the applications folder. Unlike, the 1.5.3 version, there will be no specific application folders for each application, unless you desire to make that happen. Now, the controller files called ciexample.php will reside in the controller folder with all the rest of them. If you make separate view folders for each controller all files will be nicely organized for as many applications and pages as you want. Alternatively, you could just change the name of the external link to the default controller (which is specified in the routes.php file) and the application can be up and running in minutes. For Joomla 1.6, or 1.5 for that matter, you can extract the files and dump them into the appropriate directories (root directory, administrator/component directory and the component directory), then make an external link to the appropriate path such as http://localhost/mysandbox/codeigniter/index.php/ciexample.

After the installation takes place, you will load the sample page. You will also notice that the page with the sample text is all white. Why? Well, when Codeigniter loads the ciexample controller, there is no header, content, footer nor stylesheet. At this point, you must make another template exactly like the Joomla installation, with an almost-identical menu. If this was done well, nobody would notice that Codeigniter is used within Joomla. However, the Codeigniter 1.5.3 application will load 1 view file. The more recent versions can load various views from 1 controller file. Therefore, all other files need to be included with the include() function if you are using the Codeigniter 1.5.3 code. The upside is that new folders can be added into the views directory to create various, organized pages. Another positive is security. But, fast development time and a nice model to create database driven components with CodeIgniter classes, pure php, one or two simple stylesheets, and Javascript / JS libraries make developing with Codeigniter a treat.

One downside to creating components with CodeIgniter is that the backend parameters will not work like Joomla components that use the typical Joomla MVC. If Joomla components were made with CodeIgniter, a strong CRUD method would help a layman update and modify databases. One more issue which could arise is coding the css. For example, using absolute urls will work in all cases on any server. In some instances, the index() and another function within the controller could have slightly different links to the stylesheet. You can always make specific stylesheets for each view or you can use absolute urls. If absolute urls are not used, the results can vary between a WAMP machine and the live site on a Linux Server.

You can read all sorts of opinions about speed and performance regarding using CodeIgniter within Joomla, but, it does load pages rather fast. On a WAMP server, a page with 300 words and an image can freshly load in .07 seconds and faster upon a loaded cache. Personally, I would not consider the speed performance as an issue for which not to use CodeIgniter within Joomla.
Comments (4)add comment
...
written by a guest , February 08, 2011

Speed isn't really an issue here, it will be the work down the road. Maintaining two frameworks is going to take more time than one.


...
written by kelchuk , February 09, 2011

I heard that comment before. The answer could be yes or no.

The Yes Solution:
If you had a custom application that took weeks of spare time to build for Codeigniter, it would be faster and simpler to just re-template it rather than make it a Joomla component. This where integrating Codeigniter is a valid solution. Recently, I took apart an Artisteer template index.php file. Since I wanted to use the existing Joomla template, I copied and pasted the index.php file into my Codeigniter view file. Since there was many php classes, I simply deleted them.

Basically, you can use the template css files from the head of the Joomla index.php file. To do this you copy the links to the css files from the head of the Joomla template index.php file. Then, you paste them into the Codeigniter view file and change the links to absolute urls like: localhost/myjoomlasite/templates/mytemplate/css/template.css.

Then, you can copy and paste everything within the body of the document and move it over. You can delete any code with php or Joomla classes.

Finally, the menu. You can add something like the following code and place it in the proper position. For example, Artisteer by default uses user3 for the menu. Therefore, remove the class and add a new menu with ul and li tags. Alternatively, you could use the same code as the original template. Here is a tutorial for which it is possible to use an Artisteer template menu for Codeigniter:

http://www.bohemiawebsites.com/Artisteer-Main-Menu.html

The same rules apply for any other Joomla menu from any other hand-coded or commercial template.

You can style the menu with the original template or use a different one.

With my conversion, it took 1.5 hours to make it look almost identical with Codeigniter; using the same menu and styling. With a simpler template, it could be done a little quicker. Unlike Joomla, modules will not exist with the new integrated Codeigniter application. You will use straight-up css styling to your hearts content. For example, you would simply use div tags and float new elements rather than using modules.

Once the template is built, it could be recycled for more Codeigniter applications, if desired.

Running the two frameworks is not much more work than running one. In the CodeIgniter case, it would be just like using CodeIgniter without Joomla. I don't see where the extra work is. Why is it more work using 2 if you have a solid understanding of both Frameworks? Also, using Codeigniter within Joomla allows you to use the same or a different database.

Another benefit I see for using 2 Frameworks is that Codeigniter allows more options for using 'pure languages'; although not always, depending upon the application. In the case where a stand-alone php/mysql application does not convert simply into a Codeigniter application, you can always dump the php/mysql application inside its root folder, or even inside a Joomla root folder, if necessary.

With Joomla, the ability to add framework and stand-alone php/mysql applications allows you to power within the framework and using other applications to create whatever you desire.

The No Solution:
If the new Codeigniter application needs existing Joomla modules to show on the page, or the the site menu will be continually changing with a large staff, then, maybe it is not a valid option to use Codeigniter inside Joomla.

Do not get me wrong, I love Joomla. That is why I published this article which helps explain more options for which how it can be used.



...
written by kelchuk , February 25, 2011

The usage for which the framework will be used is a key. If it absolutely needs to use the Joomla sessions and users database, its usage may not be desired; unless creating an application was oriented around the Joomla users and sessions.

But, if no database, or a second database can be implemented without the need for tying into Joomla, it could be a good option.

Since Joomla uses md5 + salt password encryption and Codeigniter may use the encryption key from config.php and the password together [sha1(encrypt_key+pass)] encrypted with sha1, moving and dumping uses is a pain in the butt.

Here is another take to integrate Codeigniter into Joomla:
http://xavoc.com/index.php?option=com_content&view=article&id=160&Itemid=156

Off the top off my head, here is where I would severerly prefer to add a Codeigniter folder inside Joomla; forms. Although Joomla has many form components, I have found they took a while to figure out how to use and the styles were often limited. In most cases, I needed to fix the php anyway. With Codeigniter I would only need a controller and a view file and could make and edit forms in a jiffy. Styling would also be a breeze using span tags in the views or alter the main css file. Examples of such form with rules are for job applications and contact. making forms with a php framework is a much more pleasant operation.

Another such use could be to make custom JQuery slideshows, pages, etc. By avoiding Joomla module rules, you can just dump code and test. Then, move it over. One example would be to write a simple JQUERY script for which all php tags would be removed from a Joomla template so that it is a simple template which could be used for php/sql or Codeigniter.

One more usage for which I would prefer to use Codeigniter would be to add a 3rd party application that was not available as a Joomla extension, although Codeigniter applications are not nearly as common as Joomla extensions.



...
written by a guest , July 31, 2011

Excelente, algo as



Write comment

busy