kulekci.net kulekci.net      About      Speaking      Elasticsearch

Usage of BasicMVC and Slim Framework

BasicMVC is a library to create MVC structure with Slim Framework. It uses Slim framework router to reach the controllers.

In this text, I will try to help bootstraping a project with BasicMVC and Slim Framework. First, let’s talk about the file structure. You can use what you want in your structure. Because, in the BasicMCV, all the directories configurable. For example,

app/
    public/
        controllers/
            ...
        models/
            ...
        views/
            ...
.htaccess
index.php

In this structure, application directory will be app/ directory and represented as APP_DIR. Your controllers will be at app/public/controllers/ and your models will be at app/public/models/ etc. When you create your BasicMVC object with index.php, you can set them like:

$basicmvc = new BasicMVC($app, array(
    "controllers_path"   => APP_DIR . "public/controllers/",
    "models_path"        => APP_DIR . "public/models/",
    "library_path"       => APP_DIR . "public/system/library/",
    "template_constants" => array()
));

You must set your path of controllers, models and views.

template_constants is a variable to send data directly to view. I will use it to send some constant of my project. For example, I define a BASE_URL which is base url of my project. I will send it to view and use it there.

I will use Twig Template Engine to render views. View files are at app/public/views/ folder. First, I will create twig object. See example below.

$twigView = new \Slim\Views\Twig();

$app = new \Slim\Slim(
    array(
        'mode'              => 'development', // development, test, and production
        'debug'             => true,
        'view'              => $twigView,
        'templates.path'    => APP_DIR . "public/views/"
        )
    );

You can also use Smarty Template Engine as template engine. See example below.

$view = new \Slim\Views\Smarty();
$view->parserDirectory = APP_DIR . "public/views/";
$view->parserCompileDirectory = APP_DIR . 'public/cache/';
$view->parserCacheDirectory = APP_DIR . 'public/cache/';

That’s all. You can ready to run your project. One more thing, I will explain your controller, model and view file contents following days.

Install Zend Server 7.0.0 and Mysql 5.6.20 on MacOSx 10.9.4

By default, Zend Server 7.0.0 has MySQL 5.5. But there are lots of feature in MySQL 5.6.20. ANd i decide to upgrade MySQL to 5.5 to 5.6.20. First of all, i get a backup from PhpMyAdmin. This is very important. And shutdown all Zend Server with

sudo /usr/local/zend/bin/zendctl.sh stop

And i open zendctl.sh file with nano and remove all mysql start and stop operation from there.

....

    "start-mysql")
        if $MYSQL_EN; then
                    $ZCE_PREFIX/mysql/bin/mysql.server start
                fi
        ;;

....
        
    "stop-mysql")
        if $MYSQL_EN; then
                    $ZCE_PREFIX/mysql/bin/mysql.server stop
                fi
        ;;
        
....

    "restart-mysql")
        if $MYSQL_EN;then
            $0 stop-mysql
            sleep 2
            $0 start-mysql
        fi
        ;;

I save and close file. After that, start the Zend Server and check Activity Monitor for MySQL. MySQL was not started. I completely delete files from /usr/local/zend/mysql/.

Now, i install MySQL 5.6.20 from http://dev.mysql.com/downloads/mysql/. Select your platform and DMG Archive. After downloading, install it with next. The installation directory of MySQL is /usr/loca/mysql. We are work in this directory. MySQL installer also includes a MySQL Preference Pane. You can start and stop your MySQL Server from MacOSx System Preferences Panel.

Now, we change the my.cnf file for new mysql. I change it like this:

[client]
#password   = your_password
port        = 3306
socket      = /tmp/mysql.sock

[mysqld]

port        = 3306
socket      = /tmp/mysql.sock
skip-external-locking
key_buffer_size = 16K
max_allowed_packet = 1M
table_open_cache = 4
sort_buffer_size = 64K
read_buffer_size = 256K
read_rnd_buffer_size = 256K
net_buffer_length = 2K
thread_stack = 128K

sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

After that, save the file and your can change every settings with the mysqladmin.

sudo mysqladmin status --socket=/tmp/mysql.sock -h 127.0.0.1 -P 3306 -u root -p

Then restart your MySQL Server. Now, we must change our php.ini file to connect from PHP. Your Zend Server php.ini file is /usr/local/zend/etc/php.ini.

You must change the following lines :

...
pdo_mysql.default_socket=/tmp/mysql.sock
...
mysql.default_socket=/tmp/mysql.sock
...
mysqli.default_socket=/tmp/mysql.sock
...

Now, You can restart Zend Server and it is ready.

Example Post

h1. Example Post

p(meta). 23 May 2014 - Istanbul

This post is an example post to sampling the markdown grammer.

h2. An exhibit of Markdown

This note demonstrates some of what “Markdown”:markdown is capable of doing.

Note: Feel free to play with this page. Unlike regular notes, this doesn’t automatically save itself.

h2. Basic formatting

Paragraphs can be written like so. A paragraph is the basic block of Markdown. A paragraph is what text will turn into when there is no reason it should become anything else.

Paragraphs must be separated by a blank line. Basic formatting of italics and bold is supported. This can be nested like so.

h2. Lists

h3. Ordered list

  1. Item 1
  2. A second item
  3. Number 3

Note: the fourth item uses the Unicode character for “Roman numeral four”:format.

h3. Unordered list

  • An item
  • Another item
  • Yet another item
  • And there’s more…

h2. Paragraph modifiers

h3. Code block

Code blocks are very useful for developers and other people who look at code or other things that are written in plain text. As you can see, it uses a fixed-width font.

You can also make inline code to add code into other things.

h3. Quote

quote. Here is a quote. What this is should be self explanatory. Quotes are automatically indented when they are used.

h2. Headings

There are six levels of headings. They correspond with the six levels of HTML headings. You’ve probably noticed them already in the page. Each level down uses one more hash character.

h3. Headings can also contain formatting

h3. They can even contain inline code

Of course, demonstrating what headings look like messes up the structure of the page.

I don’t recommend using more than three or four levels of headings here, because, when you’re smallest heading isn’t too small, and you’re largest heading isn’t too big, and you want each size up to look noticeably larger and more important, there there are only so many sizes that you can use.

h2. URLs

URLs can be made in a handful of ways:

  • A named link to “MarkItDown”:markitdown. The easiest way to do these is to select what you want to make a link and hit Ctrl+L.
  • Another named link to MarkItDown
  • Sometimes you just want a URL like http://www.markitdown.net/.

Horizontal rule

A horizontal rule is a line that goes across the middle of the page.


It’s sometimes handy for breaking things up.

h2. Images

Markdown can also contain images. I’ll need to add something here sometime.

h2. Finally

There’s actually a lot more to Markdown than this. See the official “introduction”:basics and “syntax”:syntax for more information. However, be aware that this is not using the official implementation, and this might work subtly differently in some of the little things.

[markdown]http://daringfireball.net/projects/markdown/ [format]http://www.fileformat.info/info/unicode/char/2163/index.htm [markitdown]http://www.markitdown.net/ [basics]http://daringfireball.net/projects/markdown/basics [syntax]http://daringfireball.net/projects/markdown/syntax