仓酷云

标题: PHP网页设计[转]类与PHP (II) [打印本页]

作者: 小魔女    时间: 2015-2-4 00:25
标题: PHP网页设计[转]类与PHP (II)
看到好的帖子最好up一下,以使得更多的人得到分享。   Classes and PHP

When you create a function within a class with the same name as the class that function will execute whenever you create an object of that class. This is called a 'constructor.' It allows me to have default values for each attribute automatically whenever I create an object:

<?php $Basic = new Style; ?>

You define an instance of a class by giving it a name ($Basic) and assigning it "=new ClassName;".

You could also send different values for the variables as arguments when declaring the new Style, but if you declare a value you have to declare all of them that occur to the right of the one you declare (class functions work just like regular functions in this respect). Meaning if you set 'text' to something different than the default given in Style, then you have to declare all the variables. There is an easier way. We can create a function that changes a single variable within the class:

<?php

Function Set($varname,$value) {

        $this->$varname=$value;

}

?>

So to change the value of particular variable of an instance we can:

<?php $Basic->Set('size','2'); ?>

You use the "->" operator to refer to a variable or a function of an instance. So the above tells the interpreter "Run function 'Set()' of instance '$Basic'." It knows that "$Basic" is an instance of class "Styles" because we declared it so. Similarly we can refer to variables of an instance in the same manner (e.g. $Basic->text).

Let's create a Style for table headers that has some slightly different attributes.

<?php

$Theader= new Style;
$Theader->Set('text','#0000FF');
$Theader->Set('bgcol','#000000');

?>

There, that's good enough. Now my table header has blue text on a black background. I want my table body to be a slightly lighter gray than my main page, black is good for text, but maybe I'll make the text smaller:

<?php

$Tbody=new Style;
$Tbody->Set('bgcol','#AAAAAA');
$Tbody->Set('size',2);

?>

  我假设你目前已经可以完成一个静态页面了,当然,做的好看难看是另外一说,皮皮我的第一个网页也没好看到哪去,但是“孩子”再丑,咱们做“爹妈”的也不能嫌弃不是?这毕竟是咱的成果。
作者: 蒙在股里    时间: 2015-2-4 13:06
说php的话,首先得提一下数组,开始的时候我是最烦数组的,总是被弄的晕头转向,不过后来呢,我觉得数组里php里最强大的存储方法,所以建议新手们要学好数组。
作者: 小女巫    时间: 2015-2-9 22:57
曾经犯过一个很低级的错误,我在文件命名的时候用了一个横线\\\\\\\'-\\\\\\\' 号,结果找了好几个小时的错误,事实是命名的时候 是不能用横线 \\\\\\\'-\\\\\\\' 的,应该用的是下划线  \\\\\\\'_\\\\\\\' ;
作者: 再见西城    时间: 2015-2-9 23:29
兴趣是最好的老师,百度是最好的词典。
作者: 飘灵儿    时间: 2015-2-10 13:25
至于模板嘛,各位高人一直以来就是争论不休,我一只小菜鸟就不加入战团啦,咱们新手还是多学点东西的好。
作者: 老尸    时间: 2015-3-1 23:56
至于模板嘛,各位高人一直以来就是争论不休,我一只小菜鸟就不加入战团啦,咱们新手还是多学点东西的好。
作者: 柔情似水    时间: 2015-3-7 20:51
先学习php和mysql,还有css(html语言很简单)我认为现在的效果比以前的方法好。
作者: 金色的骷髅    时间: 2015-3-10 05:11
你很难利用原理去编写自己的代码。对于php来说,系统的学习我认为还是很重要的,当你有一定理解后,你可你针对某种效果研究,我想那时你不会只是复制代码的水平了。
作者: admin    时间: 2015-3-11 13:14
php是动态网站开发的优秀语言,在学习的时候万万不能冒进。在系统的学习前,我认为不应该只是追求实现某种效果,因为即使你复制他人的代码调试成功,实现了你所期望的效果,你也不了解其中的原理。
作者: 飘飘悠悠    时间: 2015-3-18 12:31
开发工具也会慢慢的更专业,每个公司的可能不一样,但是zend studio是个大伙都会用的。
作者: 仓酷云    时间: 2015-3-25 19:49
说点我烦的低级错误吧,曾经有次插入mysql的时间 弄了300年结果老报错,其实mysql的时间是有限制的,大概是到203X年  具体的记不清啦,囧。
作者: 因胸联盟    时间: 2015-3-28 21:58
当然这种网站的会员费就几十块钱。
作者: 谁可相欹    时间: 2015-4-1 18:08
个人呢觉得,配wamp 最容易漏的一步就是忘了把$PHP$目录下的libmysql.dll拷贝到windows系统目录的system32目录下,还有重启apache。
作者: 深爱那片海    时间: 2015-4-12 04:33
建数据库表的时候,int型要输入长度的,其实是个摆设的输入几位都没影响的,只要大于4就行,囧。
作者: 变相怪杰    时间: 2015-4-19 03:41
作为一个合格的coder 编码的规范是必须,命名方面我推崇“驼峰法”,另外就是自己写的代码最好要带注释,不然时间长了,就算是自己的代码估计看起来都费事,更不用说别人拉。
作者: 海妖    时间: 2015-4-20 11:30
小鸟是第一次发帖(我习惯潜水的(*^__^*) 嘻嘻……),有错误之处还请大家批评指正,另外,前些日子听人说有高手能用php写驱动程序,真是学无止境,人外有人,天外有天。
作者: 分手快乐    时间: 2015-4-25 04:03
我学习了一段时间后,我发现效果并不好(估计是我自身的问题)。因为一个人的精力总是有限的,同时学习这么多,会导致每个的学习时间都得不到保证。
作者: 简单生活    时间: 2015-4-25 22:40
当然这种网站的会员费就几十块钱。
作者: 山那边是海    时间: 2015-4-27 14:44
本人接触php时间不长,算是phper中的小菜鸟一只吧。由于刚开始学的时候没有名师指,碰过不少疙瘩,呗很多小问题卡过很久,白白浪费不少宝贵的时间,在次分享一些子的学习的心得。




欢迎光临 仓酷云 (http://www.ckuyun.com/) Powered by Discuz! X3.2