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... 

Thursday, October 11, 2018

Installing CakePHP and Connecting to PostgreeSQL on Windows 10

Just run this command on windows command prompt :

After it finished, just go to your cakePHP directory and type "bin\cake server"
Result :

That picture above means that we have successfully installed and run cakePHP 3.6.12 but still not yet connected to any database.
So our next task is connecting to a database. In this post I will be using postgreesql. So go just run your pgAdmin and create a newdatabase as you like. For me it's like this :
After creating our database, then go to config folder and open App.php like this :
Change it's config to something as shown below :
Last... let's refresh our localhost:8765 and we got something like ....


If you want to change the host address and port. Then we can run it using this command :


Yeeeei..... That's all for now... If you have something unclear please leave a comment...
Thank you... :-)
English Video

Indonesian Video :


Next post is about migrations...

Postgres cannot be used in CakepPHP due to missing extension

I changed my app.php database configuration to use Postgreesql like this :
And then when I run bin\cake server, I got this error :
Solution :

Monday, October 8, 2018

Proses Instalasi PostgreeSQL di Windows 10

Pertama-tama download dl postgreesqlnya disini... Terus isiin versi postgreesql dan operating sistemnya kek gini :

Terus stlh download tinggal next next... :v













Klik servers(1) buat login....


Siiipss... sekiaan... semoga bermanfaat.. :-)