machuga / php-activerecord-spark Goto Github PK
View Code? Open in Web Editor NEWCodeIgniter 2.0+ Spark to integrate PHPActiveRecord into CodeIgniter
CodeIgniter 2.0+ Spark to integrate PHPActiveRecord into CodeIgniter
I've installed php-activerecord-spark into my CI install and works perfectly on my local windows box. As soon as I upload it to a test linux server I get a blank page on any thing I try to load. Tracked down my apache error log and found this
PHP Parse error: syntax error, unexpected T_STRING in /var/www/_/_/sparks/php-activerecord/0.0.2/libraries/PHPActiveRecord.php on line 48
Any idea what is wrong or I'm missing?
Running the latest version of CI 2.1 and using eith PHP AR 0.0.1 or 0.0.2 results in a fatal error.
PHP Fatal error: Class 'ActiveRecord\Model' not found in /application/models/user.php on line 3
Here is the class
class User extends ActiveRecord\Model {}
Hi,
I've installed the spark with regular CI 2.1.2 and it works perfectly.
But on a fresh install using the hmvc install instructions on the sparks install page and then installing phpar spark I get Fatal: undefined function Test::all();
Here's my setup
Application
--------------modules
--------------------------test
-------------------------------controllers
-----------------------------------------test.php
-------------------------------models
----------------------------------------Test.php
If I try without phpar the module works echoing out a "hello from test module"
So when I run phpar spark or hmvc on their own they both work as they should but when I put them together in the same app this undefined message is all I get. Here's the stacktrace from xdebug
1 0.0003 338504 {main}( ) ..\index.php:0
2 0.0008 339416 require_once( 'E:\sandbox\ciblog2\system\core\CodeIgniter.php' ) ..\index.php:202
3 0.0103 748936 call_user_func_array( ) ..\CodeIgniter.php:359
4 0.0103 748984 Test->index( ) ..\CodeIgniter.php:359
Hi,
First of all, thanks for this spark. Everything works great BUT I get this really annoying fatal error for some reason:
Fatal error: Exception thrown without a stack frame in Unknown on line 0
I can't figure out what's causing it and I wasn't able to find any solution for it. I also don't know if this is due to something in your code or the php-activerecord itself. I bet it has something to do with my server setup (dev machine).
I also want to point out that that the library works (for example, I can get all entries from a particular table). I'm writing here hoping that the author is familiar with this problem.
Thanks,
Edmund
Hi.
I have one code from tutorial http://heybigname.com/2011/09/27/codeigniter-2-sparks-php-activerecord-part-6-form-input-and-model-validation
Its using Codeigniter 2.0.3 , php-activerecord 0.0.1
I updated them both, to CI 2.1.0 and php-activerecord 0.0.2 (and My_Loader.php for the sparks to the latest)
But now there is a problem with the normal finder:
Model::find($id)
If there is no such ID the how script dies, without giving any kind of error..
At the same time Model::find_by_id($id) works even if there isn't such entry..
Controller:
public function register()
{
if($_POST)
{
$register = User::is_valid(array(
'username' => $_POST['username'],
'password' => $_POST['password']
));
if($register)
{
redirect('users/login');
}
else
{
print_r ($register->errors->full_messages());
}
}
}
Model:
class User extends ActiveRecord\Model
{
var $password = FALSE;
static $validates_size_of = array(
array('username', 'within' => array(3,15)),
array('password', 'minimum' => 6)
);
function before_save()
{
if($this->password)
{
$this->hashed_password = $this->hash_password($this->password);
}
}
private function hash_password($password)
{
$salt = bin2hex(mcrypt_create_iv(32, MCRYPT_DEV_URANDOM));
$hash = hash('sha256', $salt . $password);
return $salt . $hash;
}
error message:
Fatal error: Call to undefined method Users::_validate() in /home/test/domains/test/public_html/sparks/php-activerecord/0.0.2/vendor/php-activerecord/lib/Model.php on line 1077
hi there
i came across your spark as i was going through a tutorial on the 'Perfect Model'
what is the status of this spark ?
are there any plans for releasing a new version that contains the latest github version of php-activerecord https://github.com/jpfuentes2/php-activerecord ?
i would like to fork this repo and try to build it fresh
Feature Request
Is it possible to have table prefixes in the model name? Accomplishing this with the current release is done by putting individual names in the model file.
My Stack
The use case
There are different domains of an enterprise application which share the same database.
For example, A company sells products handled by A company's website using the a_company database table. B company also sells products using their own website but shares database (say because of hosting restrictions) with A company. Assuming both follow the convention of naming their database models after the models—a_products
and b_products
, respectively—they need to differentiate their database models somehow.
This use case can be easily solved by the solution provided by the spark but assuming such similarity is not limited to one table, assuming this similarity approaches countable infinity, in such case, manually redefining names of tables in model files will not only be tedious but inefficient.
My proposal remains as above: a means to use prefixes in table names. CodeIgniter already provides a $config[database][dbprefix] = 'pfx'
—the "pfx" is an assumption—option which can be used like so
`$this->db->prefix("table_name"); // should result in pfx_table_name
However, the PHPActiveRecord spark does not respect this, since…
class Test extends ActiveRecord\Model
{
static $table_name;
function __construct()
{
parent::__construct();
$table_name = $this->db->prefix('tests');
// OR…
// $CI =& get_instance();
// $CI->load->database();
// $table_name = $CI->db->prefix('tests');
}
}
… still assumes the table name is tests
by virtue of…
[04-Sep-2013 22:15:29 Europe/Berlin] PHP Fatal error: Uncaught exception 'ActiveRecord\DatabaseException' with message '42S02, 1146, Table 'database.tests' doesn't exist' in /Applications/MAMP/htdocs/app_name/sparks/php-activerecord/0.0.2/vendor/php-activerecord/lib/Connection.php:313
Stack trace:
#0 /Applications/MAMP/htdocs/app_name/sparks/php-activerecord/0.0.2/vendor/php-activerecord/lib/adapters/MysqlAdapter.php(25): ActiveRecord\Connection->query('SHOW COLUMNS FR...')
#1 /Applications/MAMP/htdocs/app_name/sparks/php-activerecord/0.0.2/vendor/php-activerecord/lib/Connection.php(254): ActiveRecord\MysqlAdapter->query_column_info('`tests`')
#2 /Applications/MAMP/htdocs/app_name/sparks/php-activerecord/0.0.2/vendor/php-activerecord/lib/Table.php(370): ActiveRecord\Connection->columns('`tests`')
#3 /Applications/MAMP/htdocs/app_name/sparks/php-activerecord/0.0.2/vendor/php-activerecord/lib/Cache.php(67): ActiveRecord\Table->ActiveRecord\{closure}()
#4 /Applications/MAMP/htdocs/trc_ci/sparks/php-activerecord/0.0.2/vendor/php-activerecord/lib/Table.php(370): Act in /Applications/MAMP/htdocs/trc_ci/sparks/php-activerecord/0.0.2/vendor/php-activerecord/lib/Connection.php on line 313
…but in my MySQL database, there is a "pfx_tests".
Hi, I'm the newbie in php-activerecord, I've setup from spark manually.
My issue is when I've set dbprefix in CI's config/database.php, then made table names for models are changed to [prefix]_[model_name]s. It cause fatal error like:
Fatal error: Uncaught exception 'ActiveRecord\\DatabaseException' with message '42S02, 1146, Table 'test.mymodels' doesn't exist' in /home/mypc/www/codeigniter/sparks/php-activerecord/0.0.2/vendor/php-activerecord/lib/Connection.php:313
Stack trace:
#0 /home/mypc/www/codeigniter/sparks/php-activerecord/0.0.2/vendor/php-activerecord/lib/adapters/MysqlAdapter.php(25): ActiveRecord\\Connection->query('SHOW COLUMNS FR...')
#1 /home/aimakun/www/codeigniter/sparks/php-activerecord/0.0.2/vendor/php-activerecord/lib/Connection.php(254): ActiveRecord\\MysqlAdapter->query_column_info('`mymodels`')
#2 /home/mypc/www/codeigniter/sparks/php-activerecord/0.0.2/vendor/php-activerecord/lib/Table.php(370): ActiveRecord\\Connection->columns('`mymodels`')
#3 /home/mypc/www/codeigniter/sparks/php-activerecord/0.0.2/vendor/php-activerecord/lib/Cache.php(67): ActiveRecord\\{closure}()
#4 /home/mypc/www/codeigniter/sparks/php-activerecord/0.0.2/vendor/php-activerecord/lib/Table.php(370): ActiveRecord\\Cache::get('get_meta_data-`...' in /home/mypc/www/codeigniter/sparks/php-activerecord/0.0.2/vendor/php-activerecord/lib/Connection.php on line 313
My table name is now 'myprefix_mymodels'.
Where can I find PostgreAdapter ?
My MAMP is running Php 5.4.4.
I successfully managed to install Bonfire(latest) with Sparks to use PhpAR.
I've pre loaded the php-activerecord library in the config and works really well.
When I run a simple query like User::all(), this error appears even though my default driver in my config is 'mysql' (not mysqli).
I'm trying to make an adjustment to the $DATE_FORMAT variable for the Serialization class. The phpAR website says to call
ActiveRecord\Serialization::$DATETIME_FORMAT = 'Y-m-d';
However, it doesn't seem that I can access the class variable like that within codeigniter. I haven't come across any other sparks that include namespaced classes for php yet. So I'm not exactly sure how to modify these values. Any suggestions?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.