Welcome Guest, Not a member yet? Register   Sign In
php-activerecord and code igniter with PHP 5.4.3 don´t work
#1

[eluser]Sangar[/eluser]
I use CodeIgniter 2.1 and my production server was updated to PHP 5.4.3-1, and the pages that uses phpactiverecord don´t show nothing and don't show any error.

In my test servers with 5.3.6 works fine.

I use the nightly build version of May 2012. I try with the older versions and stable version.

Php-activerecord don´t work fine with php 5.4.3?

EDIT: I found that my new server doesn´t have displays_errors = ON. After activate it, I see the error:

Code:
Fatal error: Class 'Category' not found in /srv/www/framework/application/controllers/categories.php on line 26

at line 26:

Code:
$data["categories"] = Category::findby($parent_id);

categories.php exists in /srv/www/framework/application/controllers/ and this works fine on PHP 5.3.6.

I need to call something more or call at a different way?

p.d. More info at
StackOverflow
#2

[eluser]WanWizard[/eluser]
Category here is a model, and not a controller.

Looking at the phpactiverecord autoloader, it expects a model file called category_name.php in the model directory you have defined. Does that file exist, and does it contain a class called "Category".
#3

[eluser]Sangar[/eluser]
Yes the file exist and it´s called category.php. The controller is located at controller´s folder and her name is categories.php. At my local environment works perfectly, it´s fails at production server with a different PHP version.


My model at models/category.php:

Code:
<?php
class Category extends ActiveRecord\Model {

...

}

My controller at controllers/categories.php

Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Categories extends MY_Controller {

function __construct()
{
  parent::__construct();

  //$this->output->cache(10000);
}


public function index($parent_id = NULL)
{

  //set the title of the page
  $layout['title'] = lang('web_category_list');

  //find all the categories with paginate and save it in array to past to the view
  $data["categories"]  =  Category::findby($parent_id);
  $data["category_id"]  =  $parent_id;
  $data['category']  =  Category::find($parent_id);

  //Guardamos en la variable $layout['body'] la vista renderizada users/list. Le pasamos tb la lista de todos los usuarios
  $layout['body'] = $this->load->view('categories/list', $data, TRUE);

  //Cargamos el layout y le pasamos el contenido que esta en la variable $layout
  $this->load->view('layouts/backend', $layout);
}


}
#4

[eluser]WanWizard[/eluser]
I would say start debugging the phpactiverecord autoloader...
#5

[eluser]Sangar[/eluser]
I found the solution. Thanks WanWizard for show me the right way

This solution is for php-activerecord through the latest SPARKS version.

Debugging the autoload_function, I´ve seen that the model file was loaded with the first letter capitalized, only in PHP 5.4.3, not in 5.3.x, and the file wash´t loaded.

Find the ActiveRecord.php at

Quote:yourfolder/sparks/php-activerecord/0.0.0.2/vendor/php-activerecord

Search the function:

Quote:activerecord_autoload($class_name)

Line 49 change:

Quote:$file = $root.DS.$file_name;

for

Quote:$file = $root.DS.strtolower($file_name);


And now it works!

p.d. I found another strange case with php 5.4.3 before solve this. The function parse_url() returns false if your passwords has a '/' on the string. Because of this, php-activerecord could not connect to the database in the file yourfolder/sparks/php-activerecord/0.0.0.2/vendor/php-activerecord/lib/connection.php at function: file parse_connection_url().

On PHP 5.3 returns the correct array.




Theme © iAndrew 2016 - Forum software by © MyBB