CodeIgniter 在Linux(Ubuntu等)服务器上的大小写问题,开启rewrite(.htaccess)

貌似会碰到大小写问题,目前用的CodeIgniter 3.0版,载入的时候发现Controller不显示

首先需要开启mode_rewrite,就是对.htaccess的支持(如果不是root账户记得sudo)

然后再配置文件中对站点启用rewrite

可以更改sites-available目录下各个虚拟主机的配置文件,默认的应是default那个,差不多有这么一段

里面那个AllowOverride 原来是None的,改成All

然后保存文件

另外也有说可以在apache2的默认配置文件下改的,对应到ubuntu下是/etc/apache2/apache.conf。不过这个没试过

然后这一步是开启了mode_rewrite

接下来是要启动那个大小写自动修正的模块,叫mode_speling

然后重启apache应用配置

接着找到要应用的网站目录,我是直接放在根目录下的,新建一个叫.htaccess的文件,里头是这些

然后就搞定了。

另外,需要删掉CodeIgniter那个烦人的index.php前缀的话,可以参考文档:http://www.codeigniter.com/user_guide/general/urls.html?highlight=url

Ref: https://www.a2hosting.com/kb/developer-corner/apache-web-server/using-the-mod-speling-apache-module

PHP Style Guide | PHP代码风格

来自http://www.codeigniter.com/user_guide/general/styleguide.html,感觉还挺有用的。


The following page describes the coding styles adhered to when contributing to the development of CodeIgniter. There is no requirement to use these styles in your own CodeIgniter application, though they are recommended.

File Format

Files should be saved with Unicode (UTF-8) encoding. The BOM should not be used. Unlike UTF-16 and UTF-32, there’s no byte order to indicate in a UTF-8 encoded file, and the BOM can have a negative side effect in PHP of sending output, preventing the application from being able to set its own headers. Unix line endings should be used (LF).

Here is how to apply these settings in some of the more common text editors. Instructions for your text editor may vary; check your text editor’s documentation.

TextMate

  1. Open the Application Preferences
  2. Click Advanced, and then the “Saving” tab
  3. In “File Encoding”, select “UTF-8 (recommended)”
  4. In “Line Endings”, select “LF (recommended)”
  5. Optional: Check “Use for existing files as well” if you wish to modify the line endings of files you open to your new preference.

BBEdit

  1. Open the Application Preferences
  2. Select “Text Encodings” on the left.
  3. In “Default text encoding for new documents”, select “Unicode (UTF-8, no BOM)”
  4. Optional: In “If file’s encoding can’t be guessed, use”, select “Unicode (UTF-8, no BOM)”
  5. Select “Text Files” on the left.
  6. In “Default line breaks”, select “Mac OS X and Unix (LF)”

PHP Closing Tag

The PHP closing tag on a PHP document ?> is optional to the PHP parser. However, if used, any whitespace following the closing tag, whether introduced by the developer, user, or an FTP application, can cause unwanted output, PHP errors, or if the latter are suppressed, blank pages. For this reason, all PHP files MUST OMIT the PHP closing tag and end with a single empty line instead.

File Naming

Class files must be named in a Ucfirst-like manner, while any other file name (configurations, views, generic scripts, etc.) should be in all lowercase.

INCORRECT:

CORRECT:

Furthermore, class file names should match the name of the class itself. For example, if you have a class named Myclass, then its filename must be Myclass.php.

Class and Method Naming

Class names should always start with an uppercase letter. Multiple words should be separated with an underscore, and not CamelCased.

INCORRECT:

CORRECT:

Class methods should be entirely lowercased and named to clearly indicate their function, preferably including a verb. Try to avoid overly long and verbose names. Multiple words should be separated with an underscore.

INCORRECT:

CORRECT:

Variable Names

The guidelines for variable naming are very similar to those used for class methods. Variables should contain only lowercase letters, use underscore separators, and be reasonably named to indicate their purpose and contents. Very short, non-word variables should only be used as iterators in for() loops.

INCORRECT:

CORRECT:

Commenting

In general, code should be commented prolifically. It not only helps describe the flow and intent of the code for less experienced programmers, but can prove invaluable when returning to your own code months down the line. There is not a required format for comments, but the following are recommended.

DocBlock style comments preceding class, method, and property declarations so they can be picked up by IDEs:

Use single line comments within code, leaving a blank line between large comment blocks and code.

Constants

Constants follow the same guidelines as do variables, except constants should always be fully uppercase. Always use CodeIgniter constants when appropriate, i.e. SLASH, LD, RD, PATH_CACHE, etc.

INCORRECT:

CORRECT:

TRUE, FALSE, and NULL

TRUE, FALSE, and NULL keywords should always be fully uppercase.

INCORRECT:

CORRECT:

Logical Operators

Use of the || “or” comparison operator is discouraged, as its clarity on some output devices is low (looking like the number 11, for instance). && is preferred over AND but either are acceptable, and a space should always precede and follow !.

INCORRECT:

CORRECT:

Comparing Return Values and Typecasting

Some PHP functions return FALSE on failure, but may also have a valid return value of “” or 0, which would evaluate to FALSE in loose comparisons. Be explicit by comparing the variable type when using these return values in conditionals to ensure the return value is indeed what you expect, and not a value that has an equivalent loose-type evaluation.

Use the same stringency in returning and checking your own variables. Use === and !== as necessary.

INCORRECT:

CORRECT:

INCORRECT:

CORRECT:

See also information regarding typecasting, which can be quite useful. Typecasting has a slightly different effect which may be desirable. When casting a variable as a string, for instance, NULL and boolean FALSE variables become empty strings, 0 (and other numbers) become strings of digits, and boolean TRUE becomes “1”:

Debugging Code

Do not leave debugging code in your submissions, even when commented out. Things such as var_dump(), print_r(), die()/exit() should not be included in your code unless it serves a specific purpose other than debugging.

Whitespace in Files

No whitespace can precede the opening PHP tag or follow the closing PHP tag. Output is buffered, so whitespace in your files can cause output to begin before CodeIgniter outputs its content, leading to errors and an inability for CodeIgniter to send proper headers.

Compatibility

CodeIgniter recommends PHP 5.4 or newer to be used, but it should be compatible with PHP 5.2.4. Your code must either be compatible with this requirement, provide a suitable fallback, or be an optional feature that dies quietly without affecting a user’s application.

Additionally, do not use PHP functions that require non-default libraries to be installed unless your code contains an alternative method when the function is not available.

One File per Class

Use separate files for each class, unless the classes are closely related. An example of a CodeIgniter file that contains multiple classes is the Xmlrpc library file.

Whitespace

Use tabs for whitespace in your code, not spaces. This may seem like a small thing, but using tabs instead of whitespace allows the developer looking at your code to have indentation at levels that they prefer and customize in whatever application they use. And as a side benefit, it results in (slightly) more compact files, storing one tab character versus, say, four space characters.

Line Breaks

Files must be saved with Unix line breaks. This is more of an issue for developers who work in Windows, but in any case ensure that your text editor is setup to save files with Unix line breaks.

Code Indenting

Use Allman style indenting. With the exception of Class declarations, braces are always placed on a line by themselves, and indented at the same level as the control statement that “owns” them.

INCORRECT:

CORRECT:

Bracket and Parenthetic Spacing

In general, parenthesis and brackets should not use any additional spaces. The exception is that a space should always follow PHP control structures that accept arguments with parenthesis (declare, do-while, elseif, for, foreach, if, switch, while), to help distinguish them from functions and increase readability.

INCORRECT:

CORRECT:

INCORRECT:

CORRECT:

INCORRECT:

CORRECT:

Localized Text

CodeIgniter libraries should take advantage of corresponding language files whenever possible.

INCORRECT:

CORRECT:

Private Methods and Variables

Methods and variables that are only accessed internally, such as utility and helper functions that your public methods use for code abstraction, should be prefixed with an underscore.

PHP Errors

Code must run error free and not rely on warnings and notices to be hidden to meet this requirement. For instance, never access a variable that you did not set yourself (such as $_POST array keys) without first checking to see that it isset().

Make sure that your dev environment has error reporting enabled for ALL users, and that display_errors is enabled in the PHP environment. You can check this setting with:

On some servers where display_errors is disabled, and you do not have the ability to change this in the php.ini, you can often enable it with:

Note

Setting the display_errors setting with ini_set() at runtime is not identical to having it enabled in the PHP environment. Namely, it will not have any effect if the script has fatal errors.

Short Open Tags

Always use full PHP opening tags, in case a server does not have short_open_tag enabled.

INCORRECT:

CORRECT:

Note

PHP 5.4 will always have the <?= tag available.

One Statement Per Line

Never combine statements on one line.

INCORRECT:

CORRECT:

Strings

Always use single quoted strings unless you need variables parsed, and in cases where you do need variables parsed, use braces to prevent greedy token parsing. You may also use double-quoted strings if the string contains single quotes, so you do not have to use escape characters.

INCORRECT:

CORRECT:

SQL Queries

SQL keywords are always capitalized: SELECT, INSERT, UPDATE, WHERE, AS, JOIN, ON, IN, etc.

Break up long queries into multiple lines for legibility, preferably breaking for each clause.

INCORRECT:

CORRECT:

Default Function Arguments

Whenever appropriate, provide function argument defaults, which helps prevent PHP errors with mistaken calls and provides common fallback values which can save a few lines of code. Example:

PHP/ANDROID JSON传二进制数据 BASE64编码

来自以下两篇文章:

http://www.cnblogs.com/sqzzy/p/3291791.html

http://hi.baidu.com/xxfaxy/item/4c44f6fd4539dd5cc8f33705

 

今天在做手机项目中的表情模块。   后台:表情包的上传自动解压缩->各种封面的替换->表情的详细资料,提供表情包和单张表情的下载->统计表情下载的人数和人次  前台:开放下载 api接口。  难点:后台表情的图片二进制流和ios/安卓的交互。二进制流传递的问题  获取图片二进制流方法:$str  = file_get_contents(‘http://www.baidu.com/logo.gif’); //可以直接获取图片的二进制流,而且还是字符串类型  我们采用的是json传递的方式:如果json_encode($str); //会显示一个null  这时候的解决方案是:采用可逆的编码base64对二进制字节流进行编码转换  $base64 = base64_encode($str);  然后把这个组合成想要的格式进行json_encode();  和前台交互。所以在进行二进制流传递的时候,最好进行编码转换一下。首选 base64编码转换

 

============

首先导入包

import android.util.Base64;

String 变量=android.util.Base64.encodeToString(字符串.getBytes(),Base64.DEFAULT);

也可简写为

String 变量=Base64.encodeToString(字符串.getBytes(),Base64.DEFAULT);

至于解码

byte b[]=android.util.Base64.decode(字符串,Base64.DEFAULT);

String 变量=new String(b);

byte b[]=android.util.Base64.decode(字符串,Base64.DEFAULT);

BAE中使用BCS是不需要包含文件的!!!

真尼玛愚蠢啊,这个破问题倒腾了我半个小时,血都快喷了出来~

主要自己智商有限,在BAE上(php)使用BCS的文件存储…看示例代码,然后传上去,总是解析不了

一看日志都是500错误,什么找不到那个bcs.class.php

尼玛我明明传上去了啊!!!

结果把那行去掉,那个文件也不传上去,就TMD好了~原来BAE中自带那个东西的…