Zend Framework2: Tutorial Part2: Hello World Module Application

The reason I start to write this post, because I read saw a lot video on youtube.com take hours to tell you how do it. And I also follow it but it is waste my time. Didn’t work for me. And I write this as my study record also hope that could help someone to start Zend Framework2.

Actually it is very simple,

First,copy the entire “Application file” and rename it to “Hello” (You could just rename the “Application” to “Hello” or any name you like, but under this file those three name must match )

HelloModuleZendFrameWork

Second, open the “Module.php”, the namespace Hello (this namespace should match your module name).

Continue reading Zend Framework2: Tutorial Part2: Hello World Module Application

Advertisements

Tips for use Drupal

Tip1: After install new module,should go Administration › People › Permissions, set permission, otherwise won’t work.

Tip2: Drupal built a lot of caching mechanism to improve performance, but in a development environment, it is best to turn off all to see the results of the fastest changes.

Into the background

administer -> configuration -> perfromance 

Will

  • Cache pages for anonymous users
  • Cache blocks

Are unchecked.

In addition, to make the theme changes take effect immediately, you need to at the top of the theme template.php join

drupal_theme-rebuild();

Tip4: Avoid modifying Drupal core files

In the file structure of Drupal modules and themes can be installed in drupal / modules , drupal / themes , it is also possible to install in drupal / sites / all / modules , drupal / sites / all / themes under. Recommended to choose the latter, which is the official recommended. Because this way, you can modify the project focused on the sites directory when upgrading Drupal version, you can cover all the core files directly without having to have another worry.

Of course, since the Drupal web root directory is set in the root directory of the code, from a security point of view, then pay attention to the library may be accessed files, so you can control what file permissions in addition to sites outside the directory.

Tip5:error when processing Drupal

Since  Drupal has error handling php, when there was error occurs, the screen will appear

The website encountered an unexpected error. Please try again later.

Generally , you can go Administration › Reports › Recent log messages, view the error message.

But sometimes occurred if the situation worse, such as the installation of some modules may report the above error and you can’t access the back control.

So then you can go check watchdog, variables field holds this error message, you can notepad to  open it to see the error details (which you need Database logging module).

Zend Framework2: Tutorial Part1:Teaching you step by step install Zend Framework under window 8 system

Since Zend Framework is very popular, so I decided to install it in my local server to use it. Install Zend Framework is similarly like your install another PHP Framework.

1) go to here download the sample programmer, below is the link

https://github.com/zendframework/ZendSkeletonApplication

2)Unzip to your local hosting my is C:\ xampp \ htdocs and rename ZendSkeletonApplication

3)go to below link to download the latest version, I just download Zend Framework 2.2.5 Full

http://framework.zend.com/downloads/latest

4)unzip it and put it under the vendor file

the path in my computer is like this:

zfDirection

C:\xampp\htdocs\ZendSkeletonApplication\vendor\ZF2

The direction should look like this:

4) Now we need to binding domain

go to here:C:\Windows\System32\Drivers\etc

use notePad to open the file:hosts

Add two line below it:(you actually could change to another name you like it,since this use Zend Framework version 2 and under local host ,so I just named like this for easy remember it).

127.0.0.1       zf2.local
127.0.0.1       http://www.zf2.local

Now,you could access http://zf2.local testing has become effective.

5)Edit the Apache configuration file,I just go to C:\xampp\apache\conf\extra , use notePad open httpd-vhosts.conf

Add this to it:

<VirtualHost *:80>
ServerName localhost
DocumentRoot “C:\xampp\htdocs”
</VirtualHost>

<VirtualHost *:80>
ServerName zf2.local
ServerAlias http://www.zf2.local
DocumentRoot “C:\xampp\htdocs\ZendSkeletonApplication\public”
</VirtualHost>

restart the Apache service. In the browser to re-visit http://zf2.local can open ZendSkeletonApplication test program.

Now you could start programming now.

Here have some option set,not necessary.

1) Adjust the level of error messages,go to C:\ xampp \ php \ php.ini

a)change this error_reporting=E_ALL & ~E_DEPRECATED & ~E_STRICT to error_reporting=E_ALL & ~E_STRICT

b)PHP by default is use short_open_tag=off, now you could change to short_open_tag = On

c) write 2 lines below the finle

extension= php_intl.dll
extension= php_openssl.dll

How You Can Draw Regular Polygons with the HTML5 Canvas API

How it is look likes goes to here:

http://www.sandywebdesigner.com/canvas/canvas.html

  • a circle is 2 * Pi
  • don’t know how to explain sine and cosine, but if you understand below is help you under stand my JavaScript code.
  • x = r * cosine(a)
    y = r * sine(a)

And here is the JavaScript code for you Polygons

function polygon(ctx, x, y, radius, sides, startAngle, anticlockwise) {
if (sides < 3) return;
var a = (Math.PI * 2)/sides;
a = anticlockwise?-a:a;
ctx.save();
ctx.translate(x,y);
ctx.rotate(startAngle);
ctx.moveTo(radius,0);
for (var i = 1; i < sides; i++) {
ctx.lineTo(radius*Math.cos(a*i),radius*Math.sin(a*i));
}
ctx.closePath();
ctx.restore();
}

When I need a pentagon,here is the code for get it.

function doFirst(){
var x = document.getElementById(“canvas”);

context= x.getContext(‘2d’);

context.beginPath();
polygon(context, 120,120,100,5);
context.stroke();
}
window.addEventListener(“load”,doFirst,false);

And You could use below code generate different shapes.

function doFirst(){
var x = document.getElementById(“canvas”);

context= x.getContext(‘2d’);

context.beginPath();
polygon(context,125,125,100,5,-Math.PI/2);
context.fillStyle=”rgba(227,11,93,0.75)”;
context.fill();
context.stroke();

// Draw a circle to encompass this polygon
context.beginPath();
context.arc(125, 125, 100, 0, Math.PI * 2);
context.stroke();

context.beginPath();
polygon(context,350,125,100,6,-Math.PI/2);
context.fillStyle=”rgba(51,128,255,0.75)”;
context.fill();
context.stroke();

context.beginPath();
polygon(context,125,350,100,7,-Math.PI/2);
context.fillStyle=”rgba(11,227,93,0.75)”;
context.fill();
context.stroke();

context.beginPath();
polygon(context,350,350,100,8,0,false);
polygon(context,350,350,60,8,0,true);
context.fillStyle=”rgba(227,11,93,0.75)”;
context.shadowColor = ‘rgba(0,0,0,0.75)’;
context.shadowOffsetX = 8;
context.shadowOffsetY = 8;
context.shadowBlur = 10;
context.fill();
}
window.addEventListener(“load”,doFirst,false);

Create a video in your HTML5 page, here is the javascript code you needed it

Here i put the java script source code make your video work.

here the final file you needed it.

function doFirst(){
    barSize=600;
    myMovie=document.getElementById(‘myMovie’);
    playButton=document.getElementById(‘playButton’);
    bar=document.getElementById(‘defaultBar’);
    progressBar=document.getElementById(‘progressBar’);
    
    playButton.addEventListener(‘click’,playOrPause,false);
    bar.addEventListener(‘click’,clickedBar,false);
}
function playOrPause(){
   if(!myMovie.paused && !myMovie.ended ) {
       myMovie.pause();
       playButton.innerHTML=’Play’;
       window.clearInterval(updateBar);
   }else{
       myMovie.play();
       playButton.innerHTML=’Pause’;
       updateBar=setInterval(update,500);
   }
}

function update(){
    if(!myMovie.ended){
        var size=parseInt(myMovie.currentTime*barSize/myMovie.duration);
        progressBar.style.width=size+’px’;
    }else{
         progressBar.style.width=’0px’;
          playButton.innerHTML=’Play’;
          window.clearInterval(updateBar);
    }
}

function clickedBar(e){
    if(!myMovie.paused && !myMovie.ended){
        var mouseX=e.pageX-bar.offsetLeft;
        var newtime=mouseX*myMovie.duration/barSize;
        myMovie.currentTime=newtime;
        progressBar.style.width=mouseX+’px’;
        
    }
}
window.addEventListener(‘load’,doFirst,false);

Then here is your css code for add video to your html5 page–continue

Here I put the css style for mark up your video appearance. not very beautiful, but it works, you could change this to what you like.

Css3 style below: (next post is the javascript file, you need add to make the video works.)

body{
text-align:center;
}
header,section,footer,aside,nav,article,hgroup{
display:block;
}
#skin{
width:700px;
margin:10px auto;
padding:5px;
background:red;
border:4px solid black;
border-radius: 10px;
}
nav{
margin:5px 0px;
}
#buttons{
float:left;
width:70px;
height:22px;
}
#defaultBar{
position: relative;
float:left;
width:600px;
height: 16px;
padding:4px;
border:2px solid black;
background-color:yellow;
}
#progressBar{
position: absolute;
width:0px;
height:16px;
background:blue;
}

Create a video in your HTML5 page–continue

Here I am going to continue my post. HTML5 page added video is much easy now.

put below source code in your html body ,next post is the css style.

<section id = “skin”>
<video id=”myMovie” width=”640″ height=”360″>
<source src=”videos/movie.mp4″ type=’video/mp4′ >
</video>

<nav>
<div id=”buttons”>
<button type=”button” id=”playButton”>Play</button>
</div>
<div id=”defaultBar”>
<div id=”progressBar”>
</div>
</div>
<div style=”clear: both;”>

</div>

</nav>

</section>

Cakephp Blog Tutorial 1 – Installation

1. download the latest version cakePHP,

2. copy into localhost root file, and I name it as “Blog”

3. There are 3 things need to fix it out:

First is connect to your databases:

A) Database configuration (make sure have a  database in your localhost)

B) use NetBeans to open your files,under the App file, under config file, you see a database.php.default,rename it and move .default, and open it

C) here you could set your database, there are class you should change it like this

public $default = array(
‘datasource’ => ‘Database/Mysql’,
‘persistent’ => false,
‘host’ => ‘localhost’,
‘port’ => ”,
‘login’ => ‘root’,//I use localhost, so I set it root
‘password’ => ‘*******’,//here put your password
‘database’ => ‘blog’,//choose your databases
‘prefix’ => ”,
‘encoding’ => ‘utf8’,
);

Second,config your salt

under app/config/core.php, open core.php file,find your Security.salt, then go to google type:random strings, click GRC,copy the string to replace it into your file,should look like below:

Configure::write(‘Security.salt’, ‘dVYSYFEl2wYaF5FXSKhFmhGSXBGLmFeyczLUaH4IX8qIKZqo03aasw2jTmcjRP7’);

Third, Debug is optional but I think that it is good have it.

Down load it from cakePHP website name debug_kit-master file put it under your plug file

open bootstrap.php uncommon this statement.

CakePlugin::load(‘DebugKit’); //Loads a single plugin named DebugKit