程序设计
Yii之CHtml表单
yii可是使用CHtml helper类创建表单,通过CHtml创建的表单有一点好处是可以配合内置的model类实现表单提交前的验证,而不需写额外的代码,并且还能实现js验证.不需要写额外的代码.
创建form标签:
原生方式:
1 <form name=”myform” action=”yii/index.php/test/edit” method=”post”>
2 //some code
3 </form>
yii方式:
1 <?php echo CHtml::beginForm(‘edit’,‘post’,array(‘name’=>‘myform’)) ?>
2 //some code
3 <?php echo Chtml::endForm(); ?>
创建input type=”text”:
原生方式:
1 <input type=”text” id=”original” value=”” name=”user”/>
yii方式:
1 <?php echo CHtml::textField(‘user’); ?>
创建提交按钮 input type=”submit”:
原生方式:
1 <input type=”submit” name=”sub” value=”登录”/>
yii方式:
1 <?php echo CHtml::submitButton(’submit’,array(‘name’=>’sub’,‘value’=>‘登录’)); ?>
更多表单元素创建方法参见CHtml类即可,方法类似…
http://www.yiiframework.com/doc/api/1.1/CHtml
PHP Get 方法加号处理
用 get 方法 , 参数里有 “+” 时,要做处理,否则到后台会变成空格
解决方案:
1 、改用 post 方法 ,ok
2 、在 js 里用 url = encodeURI(encodeURI(XXX))
3 、将参数里的加号进行转换 data = data.replace(/\+/g, “%2B”);
(2,3步可以合为一步 encodeURIComponent(encodeURIComponent(xxxx)) )
4、 PHP接受使用 rawurldecode后台再解码一次, ok
Using OpenGraph with PHP (cUrl requests for actions)
When I press the “get code” link near the action, that’s what I get:
curl -F ‘access_token=***’ \
-F ‘article=http://example.com’ \
‘https://graph.facebook.com/me/yellowheart:read’
(There’s an actual access token of course).
sing the PHP SDK you would use the api method.
$facebook = new Facebook($config);
…
$facebook->api(‘https://graph.facebook.com/me/yellowheart:read?
article=http://example.com”,’POST‘);
You could also do a raw request
$myurl = [...]
