Cara menggunakan what is cakephp w3schools?

In this section, you can walk through typical CakePHP applications to see how all of the pieces come together.

Alternatively, you can refer to the non-official CakePHP plugin repository CakePackages and the Bakery for existing applications and components.

CakePHP is a fast open-source platform for the development of the PHP framework. The objective of CakePHP is easy to create, distribute, and handle the web application. The CakePHP contains libraries, classes, and run-time infrastructure for creating web applications, which is inspired by the Ruby on Rails framework. It is based on the model–view–controller (MVC) approach that reduces the code length for creating a beautiful web application with less effort.

The CakePHP language began in April 2005, when a Polish programmer, Michal Tatyarownikz, wrote a short report of a rapid application development framework in PHP and named it Cake. He announced that CakePHP is used as an open framework under the MIT license and opened it for the online community of developers. In December 2005, L. Masters and G.J. Woodworth established a CakePHP Software Foundation to promote development programs related to CakePHP and in May 2006 released the first version of CakePHP.

Why we use CakePHP

Cara menggunakan what is cakephp w3schools?

CakePHP has several features that make it highly recommended as a framework for quick and risk-free implementation of applications.

CakePHP, the sweet cake. Ever you tested it? If not, then it is the time to test it’s sweetness. From this tutorial, I am starting new series of CakePHP. Progressively we will dig dipper into it, very fast.

Cara menggunakan what is cakephp w3schools?

What is CakePHP?
If you don’t know, what CakePHP is? Then, CakePHP is the old boy in the family of PHP framework. CakePHP is an open source web application framework. It is one of the oldest PHP frameworks in this world. CakePHP started from back end 2005. At that time Zend framework did not present. Since then to till now, CakePHP has very powerful existent in the world of development.

Let’s Run
I think you are happy with the CakePHP introduction. So, it is the time to crack it. You can download it from CakePHP home. That’s it. Extract and rename as cakephp24. Remember you can give this folder name whatever you like. Copy and paste this folder into your htdocs. Open your web browser and go to –

localhost/cakephp24

Make sure, you already run your apache and MySQL servers. What you see?
Some red, green and yellow boxes, right? All of these have some meaning. I will explain one by one.

Cara menggunakan what is cakephp w3schools?

Before explaining these colorful boxes, I think, we should get know with CakePHP folder structure.

Cara menggunakan what is cakephp w3schools?

Yes, this is the long listing folder you will get when you open the CakePHP folder. One thing need to mention, you may not see .htaccess and other (.) files if you open through normal window. I am using Sublime Text as an editor. Normally, it shows everything inside the folder.

Inside cakephp24 folder there are 4 folders.

  • app: This folder contains all the MVC contents, configuration and other necessary folders for the project.
  • lib: This folder contains CakePHP core files. Never touch this folder.
  • plugins: It contains third party plugins.
  • vendor: This folder contains vendor related files.

Now let’s try to solve our colorful opening screen. The first two red boxes said that, we need to fix two security salts inside App/Config/Core.php. Open this file and replace the existing salt with some other secret text.

/**
 * A random string used in security hashing methods.
 */
	Configure::write('Security.salt', 'ShahjalalHossain');

/**
 * A random numeric string (digits only) used to encrypt/decrypt strings.
 */
	Configure::write('Security.cipherSeed', 'ShahjalalHossain');

Greens are good. So, now go to the yellow boxes. It says, we need to configure our database from App/Config/database.php. Here you may not find this database.php file. Rather, you will find database.php.default. Rename this file to database.php. And, set the database info-

class DATABASE_CONFIG {

	public $default = array(
		'datasource' => 'Database/Mysql',
		'persistent' => false,
		'host' => 'localhost',
		'login' => 'root',
		'password' => 'root',
		'database' => 'cakedb',
		'prefix' => '',
		//'encoding' => 'utf8',
	);

	public $test = array(
		'datasource' => 'Database/Mysql',
		'persistent' => false,
		'host' => 'localhost',
		'login' => 'user',
		'password' => 'password',
		'database' => 'test_database_name',
		'prefix' => '',
		//'encoding' => 'utf8',
	);
}

Here, I have configured only default database. You have to create a database named cakedb. You can do it by phpMyAdmin. For this tutorial we will not need any table. Only database is ok. Now, go to your CakePHP welcome screen. What you see? All red and yellow has gone. Only green boxes are there. It is good, really good. Wait, except one yellow box. At this moment this yellow box is not our headache.

Cara menggunakan what is cakephp w3schools?

Model for MVC
Now our first task is creating our model class. Usually model class is responsible for containing business logic or database connection with controller. But in CakePHP, it works differently. For this tutorial only an empty model class is enough. So create a file inside Model folder named HelloWorld.php.

class HelloWorld extends AppModel { 

}

Controller for MVC
In CakePHP, controller class contains all the business logics and others necessary methods. So, CakePHP is different then other MVC frameworks. One other important expect is CakePHP believes on plural controller name with Controller word. Little tricky, right? Ok, let me clear it. For our Hello World application the controller name will be HelloWorldsController. I hope you are clear by now. So create a file inside controller folder named as HelloWorldsController.php.

class HelloWorldsController extends AppController{
	
	
	public function index(){
		
	}
}

Yes, a blank index function. We are almost set.

View for MVC
At this time we will use default theme. So create a folder inside the View folder called HelloWorlds. Again, the plural concept of CakePHP. Now, create a file inside View/HelloWorlds/index.ctp. ctp stands for cake template. CakePHP works with templates, a lot. We will see more in near future.

<h2>Hello World!!!</h2>

Simple or what!!! Yes this is CakePHP. Now go to –

localhost/cakephp24/HelloWords

Cara menggunakan what is cakephp w3schools?

Conclusion
Piece a cake. Yes, this is CakePHP. Everything is as simple as it is. Next tutorial, I will cover some more advance feature of CakePHP, like CRUD.

Happy Coding… 🙂

Introduction to CakePHP

Shahjalal

Hej, I’m from Bangladesh. Learning programming is one of the freaking decisions I have taken in my life. Because, it makes me and my life crazy. I have great weakness on open source technologies. Perhaps, that’s why I do not know any closed source language. I fall in love with programming, when I started my undergraduate in East West University. Till now, I can not live without it.