小编Ale*_*eri的帖子

php stdClass到数组

我有一个问题,将对象stdClass转换为数组.我试过这样的方式:

return (array) $booking;
Run Code Online (Sandbox Code Playgroud)

要么

return (array) json_decode($booking,true);
Run Code Online (Sandbox Code Playgroud)

要么

return (array) json_decode($booking);
Run Code Online (Sandbox Code Playgroud)

在我尝试将其转换为空之后,演员阵容之前的数组已满了一条记录.如何在不删除行的情况下转换/转换它?

演员阵容前:

array(1) {   [0]=>   object(stdClass)#23 (36) {     ["id"]=>     string(1) "2"     ["name"]=>     string(0) ""     ["code"]=>     string(5) "56/13"   } } 
Run Code Online (Sandbox Code Playgroud)

如果我尝试制作一个,则在施放后为空NULL var_dump($booking);

我也试过这个函数但总是空的:

public function objectToArray($d) {
        if (is_object($d)) {
            // Gets the properties of the given object
            // with get_object_vars function
            $d = get_object_vars($d);
        }

        if (is_array($d)) {
            /*
            * Return array converted to object
            * Using __FUNCTION__ (Magic constant)
            * for recursive call
            */
            return array_map(__FUNCTION__, $d); …
Run Code Online (Sandbox Code Playgroud)

php arrays

185
推荐指数
6
解决办法
23万
查看次数

如何将绝对定位元素水平居中在100%宽度的div中?

在下面的例子中,#logo绝对定位,我需要它水平居中#header.通常情况下,我会margin:0 auto为相对定位的元素做一个但我被困在这里.有人能给我指路吗?

JS小提琴:http://jsfiddle.net/DeTJH/

HTML

<div id="header">
    <div id="logo"></div>
</div>
Run Code Online (Sandbox Code Playgroud)

CSS

#header {
    background:black;
    height:50px;
    width:100%;
}

#logo {
    background:red;
    height:50px;
    position:absolute;
    width:50px
}
Run Code Online (Sandbox Code Playgroud)

html css

148
推荐指数
4
解决办法
18万
查看次数

SWIG和C++内存泄漏与指针向量

我使用SWIG来连接C++和Python.我创建了一个函数,它创建了一个std :: vector对象指针.在这种情况下,指向的对象并不重要.

我遇到的问题是,当object(someObject)超出Python端的范围时,它无法释放向量中对象/指针所指向的内存,从而导致内存泄漏.

当我在Python中运行它时,我收到此错误:

swig/python detected a memory leak of type 'std::vector< someObject *,std::allocator<  someObject * > > *', no destructor found.
Run Code Online (Sandbox Code Playgroud)

这个错误是因为当Python删除向量时,它只能删除向量中的指针而不是它们指向的实际指针.

如果我可以为std :: vector创建一个析构函数,这就是答案,但这是不可能的.

在任何人建议将其作为解决方案之前,我确实需要使用与对象向量相对的指针向量,特别是因为对象很大且复杂,速度是个问题.

我在Windows上使用gcc4.4,swigwin 2.0.4和Python 2.7.

c++ swig python-2.7

22
推荐指数
1
解决办法
6573
查看次数

Codeigniter未设置会话

嗨,我在CodeIgniter中开发了一个站点.

在我的一个页面中,我在搜索表单后使用了CodeIgniter的分页.

在这种情况下,我将传递的搜索值存储到我的会话中,$_POST因为如果我有更多结果,则单击下一页搜索keppe搜索值.

但是,当我更改页面时,我想返回索引,并在返回到我的搜索表单页面后,会话已经创建,并使用会话的值进行查询.当我更改页面时,如何销毁或取消设置会话的价值?这可能吗?

在我的模型函数中,我检查会话值是否与0不同并且存在,如果为true,则使用会话值进行查询.

这是我的控制器(国家是存储到会话中的值)

public function region_list(){
        $this->load->model('backend/Nation_model');
        $this->load->library("pagination");

        if($_POST)
        {
            if (isset($_POST['ricerca'])){

                $nation = $this->input->post('nation');
                if(strlen($nation) > 0){
                   $this->session->set_userdata('nation',$nation);
                }

                $config = array();
                $config["base_url"] = base_url() . "index.php/backend/region/region_list";
                $config["total_rows"] = $this->Region_model->countRegionSearch();
                $config["per_page"] = 10;
                $config["uri_segment"] = 4;

                $this->pagination->initialize($config);

                $page = ($this->uri->segment(4)) ? $this->uri->segment(4) : 0;
                $data["regionlist"] = $this->Region_model->regionSearch($config["per_page"], $page);
                $data["links"] = $this->pagination->create_links();
                $data["nationlist"] = $this->Nation_model->nationList();

                $this->load->view('backend/region_list_view',$data);
            }
        }
        else
        {
            $config = array();
            $config["base_url"] = base_url() . "index.php/backend/region/region_list";
            $config["total_rows"] = $this->Region_model->countRegion();
            $config["per_page"] = 10;
            $config["uri_segment"] …
Run Code Online (Sandbox Code Playgroud)

php session codeigniter

22
推荐指数
2
解决办法
11万
查看次数

在组件中使用模型

如何在CakePHP中的组件中使用模型?

在控制器中,您可以使用

public $uses = array(...);
Run Code Online (Sandbox Code Playgroud)

但这在组件中不起作用.

什么

php cakephp

21
推荐指数
2
解决办法
2万
查看次数

codeigniter包括视图中的公共文件

大家好我有一个在codeigniter开发的网站,我想存储到一个名为common.php的文件中,我在很多页面中使用了一些javascript/PHP函数.我试过这种模式:

require(base_url().'application/libraries/common.php'); //I have tried also include
Run Code Online (Sandbox Code Playgroud)

这回复了我这个错误:

A PHP Error was encountered

Severity: Warning

Message: require() [function.require]: http:// wrapper is disabled in the server configuration by allow_url_include=0
Run Code Online (Sandbox Code Playgroud)

我要去我的php.ini然后打开allow_url_include,重新启动apache,当我尝试加载页面时返回我现在这个错误:

A PHP Error was encountered

Severity: Warning

Message: require() [function.require]: http:// wrapper is disabled in the server configuration by allow_url_include=0

Filename: backend/hotel_view.php

Line Number: 6

A PHP Error was encountered

Severity: Warning

Message: require(http://demo.webanddesign.it/public/klikkahotel.com/application/libraries/common.php) [function.require]: failed to open stream: no suitable wrapper could be found

Filename: backend/hotel_view.php

Line Number: 6


Fatal …
Run Code Online (Sandbox Code Playgroud)

php codeigniter

17
推荐指数
1
解决办法
7万
查看次数

动态更改CKEditor工具栏

如何动态更改CKEditor工具栏(不使用预定义的工具栏)?

CKEditor 开发人员指南仅告诉您如何在初始化期间设置工具栏.

我正在使用CKEditor 3.6.4.

ckeditor

15
推荐指数
2
解决办法
3万
查看次数

"无法加载文件或程序集或其中一个依赖项.尝试加载格式不正确的程序."

在VS中进行调试时,在VS中启动调试时会引发错误.

错误如下:

Could not load file or assembly 'p4dn, Version=1.0.1.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. An attempt was made to load a program with an incorrect format. 
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.BadImageFormatException: Could not load file or assembly 'p4dn, Version=1.0.1.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. An attempt …
Run Code Online (Sandbox Code Playgroud)

asp.net

15
推荐指数
3
解决办法
3万
查看次数

在XAMPP上安装Php-intl

我需要在我的mac上使用扩展intl和XAMPP.

所以我按照这个链接:

在XAMPP for Mac Lion 10.8上安装Php-intl

http://lvarayut.blogspot.it/2013/09/installing-intl-extension-in-xampp.html

我重新启动我的apache服务器,但没有安装扩展.因为如果我发布:

php -m | grep intl #should return 'intl'
Run Code Online (Sandbox Code Playgroud)

回来空了

没有它我无法启动的命令是对于composer和cakephp这样:

composer create-project --prefer-dist -s dev cakephp/app cakephp3
Run Code Online (Sandbox Code Playgroud)

给我这个错误:

Installing dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - Installation request for cakephp/cakephp 3.0.*-dev -> satisfiable by cakephp/cakephp[3.0.x-dev].
    - cakephp/cakephp 3.0.x-dev requires ext-intl * -> the requested PHP extension intl is missing from your system.
  Problem 2
    - cakephp/cakephp 3.0.x-dev requires ext-intl * …
Run Code Online (Sandbox Code Playgroud)

php apache macos cakephp

15
推荐指数
3
解决办法
4万
查看次数

在Codeigniter中使用LIMIT进行SELECT

我在Codeigniter中开发了一个站点,在我的模型中我有一个这样的函数:

function nationList($limit=null, $start=null) {
    if ($this->session->userdata('language')=="it")
    $this->db->select('nation.id, nation.name_it as name');
    if ($this->session->userdata('language')=="en")
    $this->db->select('nation.id, nation.name_en as name');
    $this->db->from('nation');
    $this->db->order_by("name", "asc");
    $this->db->limit($limit, $start);
    $query = $this->db->get();
    $nation = array();
    foreach ($query->result() as $row)
        array_push($nation, $row);

    return $nation;     
}
Run Code Online (Sandbox Code Playgroud)

如果进入我的控制器,我会无限制地调用该函数,并且start不会返回如下结果:

$data["nationlist"] = $this->Nation_model->nationList();
Run Code Online (Sandbox Code Playgroud)

相反,如果我设置限制并开始工作!如果limit和start为null,为什么不返回结果?如果limit和start为null,我不想创建第二个函数或控件.如果在没有控件或第二个函数的情况下限制和启动为null以使代码变得有用并且效率更高,我该如何解决这个问题呢?

php sql codeigniter

14
推荐指数
2
解决办法
12万
查看次数

标签 统计

php ×6

codeigniter ×3

cakephp ×2

apache ×1

arrays ×1

asp.net ×1

c++ ×1

ckeditor ×1

css ×1

html ×1

macos ×1

python-2.7 ×1

session ×1

sql ×1

swig ×1