手机浏览 RSS 2.0 订阅 膘叔的简单人生 , 腾讯云RDS购买 | 超便宜的Vultr , 免费部署 N8N 的 Zeabur 注册 | 登陆
浏览模式: 标准 | 列表分类:PHP

[翻译][未完成版本]Developing Desktop Applications in PHP for Beginners.

Introduction:
简价

We have been creating web-applications using PHP since it came into existence, now we can also develop Desktop or Stand alone Applications with PHP-GTK. Desktop Applications are one which does not need either a Web Server like IIS, Apache, PWS etc. or a web browser for their execution. One of the reasons why Java is so popular is because it can be used to build applications, web pages, applets and beans that can run on several platforms including Windows, Linux and Solaris. Java runs a virtual machine called JVM, and code is compiled into an intermediate format known as Java byte code, which is platform independent. When that particular piece of code is executed within the JVM, the JVM optimizes the code for the particular platform on which it is running as it is being compiled.
从PHP产生到现在,我们一直都是使用它创建WEB应用,如今,我们也可以使用PHP-GTK来创建桌面或者其他杰出的应用。桌面程序不再依靠WEB服务器(比如IIS、APACHE、PWS等等)或者通过浏览器运行他们。JAVA为什么这么流行其中之一的原因就是他不仅可以创建程序、WEB应用,小应用程序Applets和Beans,而是他可以运行在windows、linux和solaris平台上。当这些特定的代码在JVM上运行的时候,JVM会在编译的时候针对特定联台而对代码进行优化。

Microsoft's latest technology, .NET follows the same principles. Code is compiled into Microsoft Intermediate Language (MSIL) and is then executed within the .NET framework as an application domain. Microsoft is hoping to standardize C# and MSIL so that .NET code can run cross platform.

微软最近的技术声称,.net一直遵循着同样的工作原因,代码被编译成MSIL并且运行在.net framework上。微软一直希望C#和MSIL能够标准化,这样.net下的代码也就能够相对的跨平台运行了。

So what has all of this got to do with PHP-GTK? Well, both Java and .NET can be used to build windowed applications and web pages. Thanks to PHP-GTK, we can now build cross platform windowed applications with PHP as well.

可是这和使用PHP-GTK又有什么关系呢?OK,java和.net都能够创建“窗口式应用”(桌面应用软件)和网页。感谢PHP-GTK,我们也可以使用PHP创建跨平台的“winform应用”(windowed applications一直不知道怎么翻译比较好,下面如果再提到,我想,我还是用桌面应用软件来代替吧。)。

What is PHP-GTK?
PHP-GTK是什么?

GTK is an acronym for the GIMP Toolkit and GIMP is an acronym for GNU Image Manipulation Program, and is a fully featured graphics editing program that runs on Linux. It has many (if not all) of the features of popular Windows programs such as Photoshop and Paint shop. It's the graphics editor of choice for most Linux users.

GTK是GIMP ToolKit(GIMP工具包)的缩写,同时GIMP又是GNU Image Manipulation Program(开源图像处理软件)的缩写,是一个可以运行在LInux下的一款图像编辑程序。它拥有与windows平台下的photoshop和画笔程序一些相同的功能,但并非全部。它是大多数Linux用户所选择的图形编辑工作。

GTK is actually part of a set of libraries that was written in C called GTK+. GTK+ was built up over time and is now a main part of Gnome, which is a Linux GUI desktop environment. GTK+ is based on an object-oriented nature and also includes two other libraries:
GTK实际上是一套用C语言编码的代码库,一般称为GTK+。GTK+一直以来就是Gnome(Linux图形界面)的重要部件之一。GTK+采用了面向对象的方面,并且引入其他两个重要的库:

  1. GLib: A library of tools that can be used to assist developers when creating applications with GTK+.
  2. GDK: Similar to GDI for Win32, GDK standard for GIMP drawing kit and wraps a set of lower level drawing functions into classes that make developing applications with GTK+ easier. If you're thinking along the lines of MFC for C++ then you're making a fair comparison: MFC wraps several controls and hides the calls to the underlying Windows API's from the developer. GDK does the same thing for GTK+.

Where to get?

We can download binary as well as source code version of PHP-GTK from http://gtk.php.net/download.php . As a beginner, it would be a difficult process to download and install in this manner. Where we need to set up another php.ini file for PHP-GTK. Instead there is another way of installing it. We can get PHP-GTK2 in an executable form as we get WAMP.EXE. (Windows, Apache, Mysql, PHP) All we have to do is just download just download the files from http://www.gnope.org/download.php ,unzip them and double click on the icon GnopeSetup-1.5.1.exe . It will run through a step by step process where it will set up PHP-GTK automatically.

How to test the installation?

Once the installation is done we would eager to know about what is special in it? When we install PHP we would run phpinfo () from root directory .For this let us run a sample script which displays Hello world (as usual) .we can use Dreamweaver for editing the code. Another important point to be kept in mind is to save the file with extension .phpw it can be saved anywhere on your hard disk.

Here is the sample code:

 

<?PHP
if (!class_exists('gtk')) {
die("Please load the php-gtk2 module in your php.ini");
}
$wnd = new GtkWindow();
$wnd->set_title('Hello world');
$wnd->connect_simple('destroy', array('gtk', 'main_quit'));
$lblHello = new GtkLabel("hello world");
$wnd->add($lblHello);
$wnd->show_all();
Gtk::main();
?>

 

I have saved this sample file with the name hello.phpw at c:\test\. We should run this sample code from command line interface. (CLI) There may be a question rising in your mind asking, why we should run through command prompt than by just by double clicking it as it is a stand alone application. It is possible, for that we need to have a PHP compiler which converts our PHP-GTK code to EXE file . For now, let us try running it from the command prompt.
现在我们将上面这段代码保存在c:\test\目录下,取名为:hello.phpw。我们可以在命令行下运行它。或许你会有疑问,为什么我们不是编译成一个正常的程序,可以通过双击来运行?当然,这不是问题,那样的话,我们需要通过我们的PHP-GTK程序把PHP代码转换成EXE文件。现在,让我们尝试运行一下这个命令行先。

Steps for Executing a sample code:
执行部骤

  1. Start -> Run -> cmd (for xp sp2 and later version) or command (for windows 98).
    点击开始菜单->运行,输入cmd,如果是windows2000以前的版本,请输入command。
  2. Now you could see a black window which is Command Prompt. Key in the following commands as shown below.

 

z:>c:
c:> cd test
c:\test>php hello.phpw

Once we finish this line and hit the Enter key, we should see the desired output.

This shows the successful installation of PHP-GTK2 and shouls us PHP output without a web-browser.

Some interesting Websites on PHP-GTK:

  1. http://www.kksou.com/php-gtk2/
  2. http://phpgtk.activeventure.com/gtk/gtk.gtkbox.html (describes about all base classes).
  3. http://gtk.php.net/download.php
  4. http://www.gnope.org/download.php

Tags: gtk, php, application, develop, desktop

恭喜一下,phpmyadmin出了3.0测试版

看新闻的时候,突然看到phpmyadmin出了3.0beta版本,只是好象新版本是基于5.2开发的。源码地址为:http://internap.dl.sourceforge.net/sourceforge/phpmyadmin/phpMyAdmin-3.0.0-beta-all-languages.zip,大家可以去下载,如果不能下载,可以先到:http://sourceforge.net/projects/phpmyadmin/,找到3.0beta版进行下载。

对于使用PHP进行开发的人员来说,phpmyadmin可以说是最常用的工具之一。其重要性不亚于一个好的IDE所带来的功效。

SF上面如此提示:

Welcome to the beta release of phpMyAdmin 3.0.0. This version supports various features of MySQL 5.1, the Maria and PBXT storage engines and  
SweKey hardware authentication. The 3.0 series requires PHP 5.2+ and MySQL 5.0+.

看到cnbeta上有人评价说:phpmyadmin不是利器,而是神器。心中亦有此感啊。

下载源码,学习一下。oh yeah

Tags: phpmyadmin, php, mysql, database, management

smarty中的注释

写代码的时候不可避免的会使用到注释。大多数的情况下,我们都是使用<!-- 这里是注释 -->,因为这是HTML自带的注释功能,在这里的代码都不会被显示到浏览器。

然而,使用了smarty之类,我们确实不是很建议这样使用,因为,在<!---->标记里的smarty代码其实还是被解析了,如果是这样的话,那么,我们其实是多做了很多事情,却没有被显示出来,那就是说,我们其实多做了很多无用功。

因此,我们在使用smarty模版的时候,应该根据smarty的规范来。让我们看看手册怎么说:


 所有例子中,我们假定你使用缺省的分隔符。Smarty中,所有在分隔符之外的内容被显示为静态内容,或者说不会被改变。一旦Smarty遇见分隔符,它将尝试解释它们,然后在其位置处显示合适的内容。

注释

    模板注释由星号包围,继而由分隔符包围,型如:{* 这是一个注释 *}。Smarty注释不会在最终模板的输出中显示,这点和<!-- HTML comments -->不同。前者对于在模板中插入内部注释有用,因为没有人能看到。;-)

 

模版中的注释
  1. {* 这是Smarty注释,不出现在编译后的输出中 *}  
  2. <html>  
  3. <head>  
  4. <title>{$title}</title>  
  5. </head>  
  6. <body>  
  7.   
  8. {* 另一个单行Smarty注释 *}  
  9. <!-- HTML注释将发送到浏览器 -->  
  10.   
  11. {* 这是一个多行  
  12.    Smarty注释  
  13.    并不发送到浏览器  
  14. *}  
  15.   
  16. {*********************************************************  
  17. 多行注释块,包含了版权信息  
  18.   @ author:         bg@example.com  
  19.   @ maintainer:     support@example.com  
  20.   @ para:           var that sets block style  
  21.   @ css:            the style output  
  22. **********************************************************}  
  23.   
  24. {* 包含了主LOGO和其他东西的头文件 *}  
  25. {include file='header.tpl'}  
  26.   
  27.   
  28. {* 开发注解:$includeFile变量在foo.php脚本中赋值 *}  
  29. <!-- 显示主内容块 -->  
  30. {include file=$includeFile}  
  31.   
  32. {* 该<select>块是多余的 *}  
  33. {*  
  34. <select name="company">  
  35.   {html_options options=$vals selected=$selected_id}  
  36. </select>  
  37. *}  
  38.   
  39. {* 模板的cvs标记。下面的36应该是美元符号。  
  40. 但是在CVS中被转换了。 *}  
  41. {* &#36;Id: Exp &#36; *}  
  42. {* $Id: *}  
  43. </body>  
  44. </html>  

 

Tags: smarty, 注释

smarty中的变量使用

smarty中的变量和平时使用有点区别,比如$aa.bb其实代表的是$aa['bb'],具体如何个使用法,其实在手册里已经有详细说明了

    Smarty可以识别嵌入在双引号中赋值变量,只要变量名只包含数字,字母,下划线和方括号[](参见命名)。如果有其它字符(如句点,对象引用等),变量必须由反引号对`backticks`包含。你不可以嵌入修饰符,它们必须永远在引号之外使用。

实际使用中应该是这样的:

语法例子:
{func var="test $foo test"} <-- 使用$foo
{func var="test $foo_bar test"} <-- 使用$foo_bar
{func var="test $foo[0] test"} <-- 使用$foo[0]
{func var="test $foo[bar] test"} <-- 使用$foo[bar]
{func var="test $foo.bar test"} <-- 使用$foo(不是$foo.bar)
{func var="test `$foo.bar` test"} <-- 使用$foo.bar

{func var="test `$foo.bar` test"|escape} <-- 修饰符在引号外!

实际例子:
{include file="subdir/$tpl_name.tpl"} <-- 将以实际值替换$tpl_name
{cycle values="one,two,`$smarty.config.myval`"} <-- 必须有反引号!

看清楚哦。平时在使用的时候应该是感觉不出问题的,只有用在函数、循环里面,这才会成为使用中的问题。

Tags: smarty, 变量

好不要脸的说明

国内很多软件开发在叫嚣着开源,但,有几个是真正做到的?最初的discuz,直到现在还是有一些目录是加密的,主要是一些API,现在又看到不少自称是开源的。请你们扪心自问,你们做到了吗?
虽然国内开发人员的素质参差不齐,但靠欺骗的手段来达到听引人的目录,你们对得起自己的良心吗??
什么是开源???看看吧。。。
开放源代码并不仅仅意味着对源代码的访问权。开放源代码软件的发布条款必须满足以下条件:

1. 自由地再发布

如果被发布的软件是由不同来源的程序组成的,许可证不得限制任何当事人或组织(party)销售或赠送作为被发布软件成分之一的开放源码软件。

许可证不得从此项销售中索取使用费或其它任何费用。(理由)

2. 源代码

程序必须包括源代码,必须允许以源代码方式发布、还必须允许以编译后的形式发布。如果产品的某个部分没有与源代码一同发布,那么必须提供通行的、不需要支 付合理范围之外的任何费用的手段以获得源代码---从网络上免费下载是一种可取的方式。源代码必须是程序员对其进行修改的最佳形式。故意地使源代码变得含 混晦涩是不允许的。也不允许给出预处理器或翻译器处理的中间结果。(理由)

3. 派生作品

许可证必须允许修改软件和派生软件,并且必须允许它们按照原软件的许可证的条款进行发布。(理由)

4. 作者的源代码的完整性

只有在许可证允许与源代码一同发布"补丁文件"(该"补丁文件"以在创建时对程序进行修改为目的)时,许可证才能限制对修改形式的源代码的发布。许可证必 须明确地允许发布由修改后的源代码生成的程序。许可证可以要求派生的作品采用不同的名称或不同的版本号以区别于原来的软件。(理由)

5. 不得歧视任何个人或团体

许可证不得歧视任何个人或者由多人组成的团体。(理由)

6. 不得歧视任何应用领域(fields of endeavor)

许可证不得限制任何人把程序应用于任何领域。例如,不得规定程序不能应用于商业领域或基因研究领域。(理由)

7. 许可证的发布

与程序有关的权利必须适用于该程序的任何使用者,并且程序的使用者也不需要为了使用该程序而获得其它许可证的许可。(理由)

8. 许可证不能针对于一个产品

与程序有关的权利不能由该程序是否作为某个软件产品的一部分来决定。如果程序从那个发布中被抽出来,并且按照程序的许可证的条款进行使用和发布,那么得到该程序的当事人或组织将获得与得到原程序的使用者相同的权利。(理由)

9. 许可证不能影响其它软件

许可证不得向与采用它的软件一同发布的其它软件提出任何限制。例如,许可证不能坚持要求在同一媒体上发布的其它程序都是开放源代码软件。(理由)

» 阅读全文

Tags: php, shopnc, 开源