例如,在Windows文件夹中,如果我们创建一些文件并将其命名为1.html,2.txt,3.txt,photo.jpg,zen.png,则顺序将保持不变.但是如果我们创建另一个名为_file.doc的文件,它将被放在顶部.(考虑到我们按名称降序排序)
同样,将被视为第一个的角色是什么,这样如果我使用该角色,它会将文件放在层次结构的顶部?
windows algorithm programming-languages char special-characters
请参阅以下示例(PHP)
class Parent
{
protected $_property;
protected $_anotherP;
public function __construct($var)
{
$this->_property = $var;
$this->someMethod(); #Sets $_anotherP
}
protected function someMethod()
...
}
class Child extends Parent
{
protected $parent;
public function __construct($parent)
{
$this->parent = $parent;
}
private function myMethod()
{
return $this->parent->_anotherP; #Note this line
}
}
Run Code Online (Sandbox Code Playgroud)
我是OOP的新手并且有点无知.
这里访问parent属性我正在使用该类的一个实例,这似乎是错误的:S(不需要我是孩子).有没有一种简单的方法,以便我可以将父属性与子属性同步,并且可以直接访问$ this-> anotherP而无需使用$ this-> parent-> anotherP?
关联数组的关键是动态生成的.我如何获得这样一个数组的"密钥"?
$arr = array ('dynamic_key' => 'Value');
Run Code Online (Sandbox Code Playgroud)
我知道可以通过这样的foreach循环访问它:
foreach ($arr as $key => $val) echo "Key value is $key";
Run Code Online (Sandbox Code Playgroud)
但是,我知道这个数组只有一个键,并且想避免使用foreach循环.是否可以以任何其他方式访问此元素的值?或者获得关键名称?
似乎很少甚至没有关于Facebook登录与cakephp Auth组件在线集成的最新资源.我找到了以下资源:
除此之外,我没有找到明确的资源.我希望集成尽可能灵活(不使用魔术插件).经过大量研究后,我终于提出了一个体面的解决方案,我今天在这里分享.因为我对蛋糕很新,请提供帮助.
integration cakephp facebook-graph-api cakephp-2.0 facebook-php-sdk
海.我正在制作这个简单的字符串类,并想知道是否有更自然的方法.
class Str{
function __construct($str){
$this->value = $str;
$this->length = strlen($str);
..
}
function __toString(){
return $this->value;
}
..
}
Run Code Online (Sandbox Code Playgroud)
所以现在我必须像这样使用它:
$str = new Str('hello kitty');
echo $str;
Run Code Online (Sandbox Code Playgroud)
但是用圆括号看起来并不那么"自然".所以我想知道这样或类似的东西是否可能.
$str = new Str 'hello kitty'; # I dont believe this is possible although this is preferred.
$str = new Str; # get rid of the construct param.
$str = 'value here'; #instead of resetting, set 'value here' to Str::$value??
Run Code Online (Sandbox Code Playgroud)
在第二种方法中,有没有办法可以再次捕获变量bing set而不是重置它,将其设置为Str :: $ value?我已经考虑过了,我最接近的是__destruct方法.但没有办法知道它是如何被摧毁的.这可能还是我在浪费时间?
是否在PHP中随机命名了函数及其参数?我发现很难记住哪个功能是如何,并且总是发现自己参考手册.你怎么做才能记住它们而不必每次都参考手册?
几个例子:
array_map(callback, array)但是array_filter(array, callback).当处理字符串时strstr(),strpos()并substr()没有下划线,但是str_replace(),str_pad()并str_split()不会.在大多数情况下,字符串被接受为第一个参数,但在explode()字符串中是第二个参数.
Cakephp 2.x中是否有Auth Component的助手?
目前我只是将$ Auth对象传递给AppController中的视图,如下所示:
$this->set('Auth', $this->Auth);
Run Code Online (Sandbox Code Playgroud)
我四处搜索,但默认情况下似乎没有帮手.我需要像Auth :: loggedIn()这样的视图中的Auth组件的一些功能.
救命?
我希望能够做到这样的事情:
$table_object->getRows()->where($wer)->or($or)->orderBy('field', 'DESC');
Run Code Online (Sandbox Code Playgroud)
如果我确定每次都会按顺序调用所有方法,那么它就很简单了,我可以在每次方法调用时返回一个对象本身的实例,以便查询得到构建并最终在orderBy方法中执行.但是我希望类能够执行如下查询:
$table_object->getRows()->where($wer);
Run Code Online (Sandbox Code Playgroud)
以下代码适用于第一个代码示例(即调用所有方法时),但不适用于第二个代码,其中只有方法在getRows之后调用.它只返回自身的一个实例.
class DatabaseTable extends Database
{
protected $table_name;
protected $query;
public function getRows()
{
return ($this instanceof self)? $this : false;
}
public function where(array $where)
{
foreach ($where as $field => $value){
$w[] = $field . ' = "' . $this->escapeString($value) . '"';
}
$this->query = "SELECT * FROM {$this->table_name} WHERE " . join($w, ' AND '));
return $this;
}
public function or(array $Clause)
{
foreach ($clause as $field => $value){
$o[] = $field …Run Code Online (Sandbox Code Playgroud) php ×6
oop ×3
cakephp ×2
cakephp-2.0 ×2
algorithm ×1
char ×1
integration ×1
string ×1
windows ×1