Category Archives: Programming

Laravel Error – SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 767 bytes

Im currenlty running my way though Laravel the PHP framework and following some tutorials. If your starting this framework you will most likely run into the error below when you run your migrations;

Illuminate\Database\QueryException  : SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 767 bytes (SQL: alter table users add unique users_email_unique(email))

The fix is simple;

Open the AppServiceProvider file and add the following line to the boot function;

via;

https://laracasts.com/discuss/channels/laravel/laravel-54-failing-on-php-artisan-migrate-after-php-artisan-makeauth?page=1

Angular 4/5 quick tips

 

 

 

 

 

 

how to add bootstrap:

add the scripts and styles to your “.angular-cli.json”

add the following the styles and scripts section;

create new project:

start server:

create new component:

create new service:

Getting started with Python and the Django Framework part 1

So over the christmas holidays ive been keeping myself busy by learning more about the Python language.

Having learnt a few basics i started to try the Django framework which ive seen mentioned quite a lot.  Im reffering to windows mainly in this case see below for more detailed instructions;
https://docs.djangoproject.com/en/2.0/howto/windows/

Step 1:
Install python from the site below and install the necessary version for your Operating system.
https://www.python.org/downloads/release/python-364/

Step 2:
Once you get that installed, verify that python is installed by typing “python” from the windows command prompt;

 

 

 

 

 

 

Step 3:
Install Django framework via command prompt;

pip install django

Step 4:
Create your first project its best to refer to the offical document and tutorials at;
https://docs.djangoproject.com/en/2.0/intro/tutorial01/

From the offical site;

Creating a project

If this is your first time using Django, you’ll have to take care of some initial setup. Namely, you’ll need to auto-generate some code that establishes a Django project – a collection of settings for an instance of Django, including database configuration, Django-specific options and application-specific settings.

From the command line, cd into a directory where you’d like to store your code, then run the following command:

This will create a mysite directory in your current directory. If it didn’t work, see Problems running django-admin.

Cakephp 3 – using uuid as primary key

In addition to use an auto-increment key as the primary key, you may also use UUID columns. CakePHP will create a unique 36 character UUID (Cake\Utility\Text::uuid()) whenever you save a new record using the Table::save() method.

From the book;
https://book.cakephp.org/3.0/en/intro/conventions.html#model-and-database-conventions

So if you create your primary key field as char(36) , cakePHP3 will generate unique uuids rather than the stand auto-incremented 1,2,3 4 keys

Credit to stackoverflow again;
http://stackoverflow.com/questions/34519770/cakephp-3-save-function-not-generating-primary-key-for-database

 

CakePHP3 Cache Example – Using Curl to get a Web page contents


Heres a simple example of using the cache feature of cakephp. We want to grab a webpage contents from the web but we only want to do this once otherwise its going to be slow and waste resources.

The basic idea is that we check if the url is saved in cache, if it is then we read it in otherwise we must use curl to grab it.

CakePHP3’s Cache settings are in the config/app.php file;

 

 

CakePHP 3 Cache:
https://book.cakephp.org/3.0/en/core-libraries/caching.html

Cakephp 3 Plugin – Changelogs

Ive finally gotten around to releasing this little app i was working on for Cakephp3.  I decided a while ago to abandon Cakephp 2 and go with the new version 3.

Its been a steep learning curve so i wanted to learn as much as i could.  So thats where this app/plugin came in.

The Aim:
The goal of the plugin was to allow a way to simply log tasks, changes or articles about the cakephp project your working on.

If your working on a website/project on your own you need a way to record your changes and tasks so i thought this would be an ideal way to learn and release something. Sure you could do the same with Github and better but i think its better to have something like this integrated into your application.

Screenshot: Version 1
2016-05-25

 

 

 

 

 

Version 2 Screenshot:
changelogseditv2

 

 

 

 


Github & Source:

https://github.com/gerrymcdonnell/cakephp-changelog

Cakephp3: Installing Cakephp3

23666Cakephp 3 depends a lot on using composer, so youll need to get that first.; http://getcomposer.org/

Once youve set up composer you can create a brand new cakephp3 app by;

  1. Going to your web servers “htdocs” folder. I.e if your using xammp it should be; C:xampphtdocs
  2. Open a command windows here and type;
  3. Cakephp will create a folder in your htdocs folder called ” my_app_name”
  4. Open http://localhost/my_app_name

Cakephp 3 installation:
http://book.cakephp.org/3.0/en/installation.html

Cakephp Tips – Sort Data With the Pagnator Component

If you wanted to sort a Model by a certain field in this case take the field “created” which is a date. We can simply tell cakePHP to pagnate entries by the order they were created by the following example.

More Examples can be found here;
https://www.codeofaninja.com/2013/07/pagination-in-cakephp.html