Technical


This week I started on the user registration. At the moment, new users can register themselves with Crisoft, providing information like username and password and (if available) and email address, url and description. The email will become mandatory soon, because I want to build a email-based activation to prevent spam users to register. At the moment new users are marked as “inactive” in the database and they can not login yet.

I added a simple pagination component, that builds an alphabetical navigation for all the recipes in the database. It’s written by myself, because I had no access to the official pagination helper, but it does its job. ;-) Maybe I replace it with the official version soon.

Finally, I added the model Role that hopefully helps to give users a role and access rights. I don’t have a feeling how to code that yet, but I think having models like Role and Right will help with the setup.

In CakePHP it is really easy to force users to login before executing actions. I inserted this functionality today and I’m very happy that it is so flawless.

The class app_controller.php has a function now that checks the current session. The function is used in important actions to functions to protect the content from unregistered users. This content is the user list or the “add recipe” functionality. I consider actions that change content or reveal too much information as important and try to protect them.

The mechanism used to redirect a user to the login has a nice feature now: it allows the redirect target to be specified when checking the session information. So, after login the user will be redirected to the proper page again and continues it’s journey without being interrupted. I think this is important for the usability and the experience of Crisoft. I try to figure out how to manage those things with PHP and CakePHP, and maybe I find a new way to solve this in a few weeks. Until then, you can go check out the files in the CVS and maybe you have some comments and feedback on it. I’ll be happy to hear about your opinion!

This week I was able to add the first stub functionality for the login. I use a simple User model and a password that’s MD5ed. I need to secure the important Actions now. I hope to finish the login next week.

And I changed some of the relations between the models. I think I did a great mess when I created the model. Slowly, I get into the whole hasMany, belongsTo and hasAndBelongsToMany thing. ;-)

Today I added some more Views to the little set of already finished pages in my long-taking journey to replace all scaffolded pages with my own creations. I added a simple index page for the recipes that is showing a random recipe at the moment. It could need some more tweaking, as I’m getting all recipes from the database and only using 1 to display its contents… this should be moved into a specific query to the SQL database to avoid the creation of many PHP variables.

Another View that is already in the creation process is the index page for categories and a simple view/edit combination. This is very easy because a category entry has only two fields: ID and category. So it isn’t too hard to create a page. :-) I added a basic validation using CakePHPs mechanisms and it is working fine. The result page when saving the edit is just a flash message that you have to click to continue, but I try to add some more AJAX style with a fading message box later.

I think I can work on CR2.0 in the next days, so there will be more change to come! Check the CVS repository for code updates.

I connected Images to Recipes in my CakePHP models now, so if you open the recipe details page you can see all attached images. I want to use phpthumb to generated thumbnail for all images so I added the package to the vendor directory. The workflow for this should enable the user to upload an image while editing recipe details and phpthumbnail should then generate the thumbnail on the fly. This is only possible if the GD library is installed, so the user should disable this feature from the configuration page if neccessary. If it is turned off, the recipe details page could show the full image or just links to the image files.

Today I had an issue with my installation of CakePHP on my local XAMPP development installation. The prototype of the new Crisoft won’t show up! I had no idea of what was going wrong, so I took a deep look in my httpd.conf, the error.log and the .htaccess of CakePHP. And now Crisoft is up and running.

Here is what I my configuration files look like:

httpd.conf

You have to load the Module mod_rewrite (and perhaps the mod_cache) to enable CakePHPs scaffolding magic. After that I created an Alias to make my project directory available to XAMPP. This enables me to load the URL http://localhost/crisoft in my webbrowser and have access to the XAMPP tools in the default DocumentRoot, too. You should do that too if you want to develop with XAMPP.

...
LoadModule cache_module modules/mod_cache.so
LoadModule rewrite_module modules/mod_rewrite.so
...
<IfModule alias_module>
ScriptAlias /cgi-bin/ "C:/Programme/xampp/cgi-bin/"
Alias /crisoft "C:/enter/your/path/to/crisoftricette/"
</IfModule>
...
<Directory "C:/enter/your/path/to/crisoftricette/">
    Options FollowSymLinks Includes
    AllowOverride All
	Order allow,deny
	Allow from all
</Directory>

core.php

Next was the $CAKEPHP/app/config/core.php from CakePHP. The default setting should work, but be sure to check if this line in your file:

...
//    define ('BASE_URL', env('SCRIPT_NAME'));
...

.htaccess

What I didn’t understand was the need of a new line in all .htaccess files. I had to tell Apache to apply the RewriteRules to my Alias directory. This was a bit hard, but the CakePHP Google Group is a good place to search for help.

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /crisoft
RewriteRule    ^$    webroot/    [L]
RewriteRule    (.*) webroot/$1    [L]
</IfModule>

So this was my little fight with XAMPP and CakePHP. I will include this in a small document and upload it to the CVS branch. If you’re interested in the current state, please feel free to checkout the current dev snapshot. But don’t expect it to run. And if you don’t know if it is worth the pain, here are 2 screenshots of the current state:

Current development screenshot

This is the “recipe details” page, automagicall created by CakePHP. I will design a better one later, but having CakePHP generating the page is so comfortable for development, because you don’t have to change the page for every little change in the source code.

Current development screenshot

This is the best at all: Relations! You can tell CakePHP that your model Recipe hasMany Comments and belongsTo Category. And so you click around the pages that are already LINKED TO EACH OTHER! :-)

Today I got some time to work with FPDF and I created a new PDF output page. I still have to think about a way to include a stylesheet in it, so you can style the PDF output to match your website theme. I at least want to support different color schemes. I can’t upload the first layout yet, but I will do later. You can take a look at it and give me some feedback about it.

Using FPDF is very simple after a while. There is a way to do a header/footer for the pages and include pictures in the generated PDF. I’ll use that to include the recipe picture and maybe a link to the recipe page of your installation. One should be able to turn off the linking via the configuration, but for the moment I’m happy with a somewhat static generator.

Ok, there is a solution to the WYSIWYG editor in CVS now. I added a configuration option to turn it completly off. This is the best solution to incompability issues.

Disable WYSIWYG in Crisoft Ricette

I’m very happy to see at least some contributions on the wiki. That really helps me going on with this project. Keep editing, guys! :-)

It’s already late (well, too late to be awake), but I wanted to make some minor fixes and try to get a hack for tinyMCE going. I managed to add a snippet that disables the WYSIWYG editor on the insert recipe page, but only for the first textarea. The others aren’t working yet. But I guess I can fix this too.

Yesterday I inserted first documentation comments based on Doxygen into the Crisoft-Libraryfile. With the future expansion of the developer team in my mind (and a good hint by Aurel Bodenmann - thanks a lot) I decided to add this way of documentation to the project. It will help future developers to get into the code and maybe it will speed up the development as a whole.

I am used to Javadocs, so it’s not much of a problem for me to keep the coding style for doxygen. If you want to contribute to the project with sources, please document it ith doxygen now. :-)

Next Page »