Showing posts with label CakePHP. Show all posts
Showing posts with label CakePHP. Show all posts

Tuesday, August 4, 2020

Connecting CakePHP 4.1.1 to Postgresql

So I assume you already installed your own fresh CakePHP 4.1.1. Here's mine:

Next, create Db in postgres like this:

Here's my postgres server connection properties:

To connect our db to cakephp 4.1.1 we need to set 2 items:
1. Driver
2. Default datasources properties.

Here's the screen shoot:
1. Driver:

2. Datasource


And if we run the server:

and then opening theeee http://localhost:9999/



Yep yep yep... :D

Friday, September 13, 2019

Contoh CakeLog

<?php
App::uses('CakeTime', 'Utility');
App::uses('CakeNumber', 'Utility');
App::uses('CakeLog', 'Log');



     CakeLog::write('debug',__DIR__.__FILE__);
CakeLog::write('debug', 'jenis lang : '.$language);




Thursday, May 16, 2019

CakePHP Function Call Order

beforeFilter

Controller's Action

beforeRender

Render View

afterFilter

Friday, May 3, 2019

fontawesome-webfont.ttf:1 not found in cakephp 2.10.12

This question already asked here :
https://stackoverflow.com/questions/55962332/fontawesome-webfont-ttf1-not-found-in-cakephp-2-10-12 (I acctually answered it by myself :v)
So the point is font-awesome cannot find the webfont-ttf1 and webfont-ttf2. And the solution is just create a new directory inside of webroot called 'fonts' and put 'fontawesome-webfont.ttf` there :

So next.... How do we find that fontawesome-webfont.ttf ? weell... from searching... ahaa... and I downloaded it from here http://www.tegalsari-ubud.com/assets/tegalsarinew/font-awesome-4.7.0/fonts/
So thanks for tegalsari-ubud website ;-)
and the result isss shown below..

yuupss... That's oll, tenkyew

Thursday, January 17, 2019

Checking CakePHP version of CakePHP 2.10.13


ooowh iyaah... tanda yen diatas tuh sama dengan back slash (\). Itu cuma settingan region ajjah... :-)

Konfigurasi Database cakePHP 2.10.13 menggunakan postgresql

1. buat file baru bernama database.php didalam directory config. Kemudian copy isi dari database.php.default kedalam database.php seperti terlihat pada contoh dibawah :

Jika kita buka localhost maka akan ditampilkan "Your database configuration is present" cuman connectionnya masih missing seperti terlihat dibawah :

2. Berikutnya kita bikin database baru di Pgadmin postgresql. Langkah2nya seperti terlihat dibawah:


3. Silahkan input database dari step 2 ke database.php seperti terlihat dibawah:

Hasilnya :


Seeepssss.... selese daaah....







Nge-Run cakePHP 2.10.13


Thursday, November 1, 2018

Generate Model, Controller, and Template in CakePHP 3.6

For generating model in cakePhp, we use bake command. The command format is "cake bake model yourModelName". Example :
So basically, when baking a model, we'll get 4 files namely model for table, model for entity, test fixture, and testCase table for article.


For baking controller :

And last is for template :

There is another simple way for baking all those tree items. We can use "cake bake all yourTableName", example is shown below :

Wednesday, October 31, 2018

Seeding Tutorial for Beginner in CakePHP - Windows 10

In the previous post. We've learnt a little bit about migrations in cakephp. Rightnow we'll continue our study to seeder. Simply put, seeder is used to add, modify, or delete a data from our database using a simple program. In cakePhp, if we want to create a seeder, then we just simply type "bin\cake bake seed ourTableName". Example is shown below :

Next, we just have fill the $data variabel above like this :
Next for that seeder we can use this command "cake migrations seed --seed UserSeed" as shown below :
Then the result isss.....
Okiee... That's all... :D

Example of Using Logger in CakePhp

For using simple logger in cakePhp, we simply need to import the log class and call debug as shown below :

Result can be seen inside of 'log' directory as show below:

The above example is from cli or command prompt in windows. But if we put our log in the controller. The result can be seen from the webpage and debug.log as shown below :



Yeeepsss... That's it... :-)

Sunday, October 14, 2018

Migrations Tutorial For Beginner in CakePHP - Windows 10

In the previous post we have installed and configured cakePhp with postgreesql. So in this post we'll gonna learn about migrations in CakePhp. Simply put , migrations is all about creating, dropping, changing and removing database or table in cakePhp. So if we wanto create a table, it's really suggested to create it from migrations file because it will track every table that we created and it will be easier for another developer to create their own local environment with this migrations file only by using "bin\cake migrations migrate". 
In cakePhp, we can see all of available commands in migrations by using "bin\cake migrations". It will show 
Also we can see the migrations history in phinxlog table like this :
Ok... Let's create our first migration by running this command "bin\cake migrations create MyFirstMigration" 
So we named our first migration as MyFirstMigration and then we can see it in config/migrations/xxxxxxxxx_MyFirstMigration.php as shown in the picture below :

Next let's put something onto function change ()
So... From that function we will create a table named maryadi_table. It will contain a column name as string, description as text, level as integer, created and modified as datetime. The ID column will be added automatically and it will be primary autoincrement. 
Before we run migrate, we can check the migration status first like this :
We can see MyFirstMigration there... Next let's do the migration
We can see the result in our database :
Ok....Neext...
Let's try another way of creating migration file. We can use "bake" command as follows
So we created new migration file named MySecondMigration which has some column namely name as string, description as text and so on. The result is :
There is one thing to note here. If we want to create new table using bake, we need to use "Createxxxxx" at the front of our migration name. Also we can see that our table name is "my_second_migration". Okiee...Next we'll gonna add a new column to an existing table. In order to do that, we can use "....... AddxxxxToyyyy....". xxxx is the new table that will be added and yyyy is our current existing table. Example is shown below :

So by running that migration we'll gonna add power column to maryadi_table. 
As you might notice that at the end of each migration code, there is a $table->create and $table->update. That means creating and updating the table yeaaah...and rightnow we already have two migration files which is not yet migrated as shown below :
So let's run our migrations then and see the result as shown below:
Okiee... after learning how to add. Next we'll learn how to remove column. For removing column we can use a convension name like "RemovexxxxxxFromyyyyyyy". Example :

After running that migration, we'll see that power column is now gone.
Well... there are a lot of commands that's available for us to be used. But I won't cover it all in post. But I hope this post gives your a little bit way of thinking how to use migrations command in cakePhp so you can explore another commands by yourself ehehee... :-)
Okie that's all thank you so much...