I have constantly labored with core PHP and was usually unwilling to use any CMS (Joomla, Drupal, etc). Coincidentally I hardly ever bought a probability to perform on any of the frameworks in PHP. But in the recent undertaking at operate, we have resolved to use CodeIgniter.
CodeIgniter is a light-weight open up source website software framework. In short, it offers you a directory framework of a suitable MVC pattern together with a lightweight built-in templating motor of its very own. MVC sample allows developers to individual business logic and the presentation layer. It requires a really negligible setup, as opposed to the well-known PHP framework, Zend. Zend is mostly used in acquiring enterprise applications and is a extensive framework, therefore creating the discovering curve additional difficult. On the other hand, CodeIgniter is easy to established up and less complicated to master.
Utilizing Appropriate Frameworks
It is so really important to apply the proper frameworks to any challenge that you are doing the job on. When you use the best coding frameworks, you can execute a whole lot extra than you may possibly have ever dreamed was feasible.
Eradicating some of the noise and interruptions that can choose you absent from actually carrying out all that you require to is a huge move in the suitable way, and you will find that acquiring started off with the right frameworks is in all probability what you have to have to do as a initial phase towards that objective. Or else, you will obtain you floundering for the correct responses, and your tasks just won’t flip out the way that you may possibly have hoped that they would.
Let’s Get began with CodeIgniter
Of program, the initial step is to down load the codeigniter framework. You can download the most recent steady model of Codeigniter from the next URL http://codeigniter.com/downloads/ . It will be a compressed file (zip file) that will be downloaded, just unzip it and retain it in a folder, say Codeigniter. Make guaranteed you keep it inside of the htdocs or webserver’s listing.
Now it really is time to configure the Codeigniter which original configurations to start out performing on. To do so, open the file config.php in your most loved editor. The file resides inside process/application/config directory. You will see an array known as $config which outlets all the configuration facts, we will change only the next values and go away the relaxation as it is.
/* |-------------------------------------------------------------------------- | Foundation Web page URL |-------------------------------------------------------------------------- | */ //do not forget about the TRAILING slash (/) $config['base_url']= "http://localhost/codeigniter/"
Rely on me, that shall be all to get you started. Some blogs/internet sites have demonstrated a lot of changes in this file, but you can perform all around with them when required. You can improve a ton about your application from this single file. Like you can shop the session details inside a databases, by just location up the config var $config[‘sess_use_database’] as TRUE, which is FALSE by default. You can also adjust the name of the session table from default “ci_sessions” to just about anything you like.
Due to the fact none of the web applications runs with out database, allow me demonstrate you how to configure a databases in this set up. I determined to select this up in the following tutorial, but considering the fact that it can be fairly simple, let’s do it. To configure the databases, open databases.php which is located in the similar listing as config.php i.e. procedure/software/config . Now transform the values of the next array keys with the genuine values of your MySQL server.
$energetic_team = "default" $energetic_record = Correct $db['default']['hostname'] = "localhost" $db['default']['username'] = "" //databases username $db['default']['password'] = "" //database password $db['default']['database'] = "" //name of the databases $db['default']['dbdriver'] = "mysql" $db['default']['dbprefix'] = "" //any table prefix, if you want to preserve one $db['default']['pconnect'] = Correct $db['default']['db_debug'] = Accurate $db['default']['cache_on'] = Phony $db['default']['cachedir'] = "" $db['default']['char_set'] = "utf8" $db['default']['dbcollat'] = "utf8_general_ci"
As you see the databases configuration was also straightforward. Now it is really time to acquire a simple application employing the CI framework. At the pretty starting of this post I stated that CodeIgniter presents you an MVC sample structure, so each and every aspect has a different folder. Let us develop a straightforward controller class to start off with.
To do this, let us make a course identified as Hi which will be prepared in the file referred to as hi there.php, saved inside of procedure/application/controllers/ folder. The written content of the file can be : (you can have a unique course, after all, it really is just a PHP class).
class hi extends Controller functionality __build() //contact father or mother constructor guardian::__build() purpose index() $output['header'] = "My page's header" $output['content'] = "Listed here is the information of the webpage" //load from from the process/software/views/hi there.php $this->load->view('hello',$output)
Dissect the code
Now permit us comprehend the code line by line. It truly is a controller course called good day which extends the default guardian class called Controller. Extending the Controller class facilitates the execution of this controller. The constructor of this contact simply masses the constructor of the parent course, which seemingly is Controller. Next is the index() function which has a exclusive indicating in the CI framework. If it truly is present in a controller, it is executed instantly when the controller is loaded/executed.
Now we output the details employing the see element of the MVC pattern. if you notice the previously mentioned code loads a check out identified as hi there which is a file retained within the program/application/views/ folder. The file title should really be the identical as the identify of the controller. And the info is furnished in the variety of an array, in which header,material are the template variables, as revealed beneath in the hello there.php
My very first CodeIgniter Controller and Look at
The higher than see renders the knowledge which is passed on by the calling controller. Now let’s attempt and check if every little thing performs as we anticipated, phew! Open your browser and hit
If every thing is perfectly, you ought to see a webpage, with a header and entire body content material as specified in the controller. Surprise, how did that get rendered? CodeIgniter presents a quite great routing system dependent on Relaxation. The URL is so that you can phone a distinct controller and a method from inside of the controller. But if you recognize, in the above URL we have stated only the controller identify i.e. hello, and not the operate identify index(). As outlined formerly, This is thanks to the simple fact that index() purpose receives referred to as instantly if it exists. May it have been an additional functionality identified as render then the earlier mentioned URL would have been changed to
The over URL which now simply call the render() functionality from the howdy controller.
CodeIgniter was uncomplicated, no? If you feel that was hard, just go by way of the methods all over again and I am sure you will have an understanding of. Considering that CI is the easiest framework and it allows you get started quite swiftly with the progress.
Remain Dignified !!