fuel / core Goto Github PK
View Code? Open in Web Editor NEWFuel PHP Framework - The core of the Fuel v1 framework
Home Page: http://fuelphp.com
Fuel PHP Framework - The core of the Fuel v1 framework
Home Page: http://fuelphp.com
Looks like DB caching is not supported.
I'm trying to get a CSV output with a REST controller. However I'm getting the following error: Missing argument 2 for Fuel\Core\Response::set_header(). Looks like there's a function in the base rest controller calling:
$this->response->set_header('Content-Type: '.$this->_supported_formats[$this->request->format]);
With 1 argument but the function itself expects 2 arguments:
public function set_header($name, $value)
I noticed when doing some work with the super useful \Fuel\Core\Cli class that the methods new_line
and clear_screen
are both declared in the oldy php 4 style and with the latest php version it throws an error about calling an instance method statically, just a simple fix really :-)
Would appreciate it being fixed soon, thanks!
Sorry if this is the wrong place to post this, but the http://fuel.frenky.net/latest_fuel.zip download is incorrectly putting the oil package in place of the orm package.
It's always possible that I'm being an idiot and I'll be happy to admit it if needs be, but where in the hell is add_fields() functionality? DBUtil seems to be missing this, and scarily still has an awful lot of SQL strings in it.
My final question on DBUtil, is that it seems to totally disrespect tables prefixes, meaning that migrations (more specifically DBUtil::create_table('foo')) will break whenever a prefix is used.
It might be something for v1.1 but I feel this issues should probably be cleared up before final as... well it's really not final.
Entered by Juan Treminio on 4/13/11
fuel/core/classes/uri.php:
/**
* Gets the current URL, including the BASE_URL
*
* @param string the url
*/
public static function main()
{
return static::create(\Request::main()->uri->uri);
}
/**
* Gets the current URL, including the BASE_URL
*
* @param string the url
*/
public static function current()
{
return static::create();
}
Uri::main() should return ONLY main URL.
Example, if my website is on http://fuel.com/, Uri::main() should return only "http://fuel.com/", but it's returning the same thing as Uri::current(), which is the base URL plus controller.
Uri::main in welcome/index is currently returning:
http://fuel.com/welcome/index/
For now I've simply extend Uri:
static function base()
{
return \Config::get('base_url');
}
Stuart Hutchinson responded
According to the docs, URI:current() does the following:
The current method allows you to fetch the current URL, including the base URL inside HMVC pattern.
whereas URI::main() does the following:
The main method allows you to fetch the current URL, including the base URL.
I think this should probably be a feature if adding a function such as URI::base() to the class is desired.
I noticed that Form::button
is just an alias to Form::input
with a type attribute of button. I was just curious why that was done instead of actually creating a button element. As this page outlines, there are some pretty significant differences with the button element. You've already got the Form::submit
for a submit button if someone wants, so I was just curious what the reasoning behind the button decision was. Thanks!
public function error($field = null)
{
return $this->validation()->error($field);
}
should be
public function errors($field = null)
{
return $this->validation()->errors($field);
}
(Validation::error() doesn't exist)
validation, and error messaging of fileds like below doesn't work properly.
<input name="item[]" /> <input name="item[]" /> <input name="item[]" /> <input name="item[]" /> <input name="item[]" />
ErrorException [ Notice ]: Array to string conversion
return $open.str_replace($find, $replace, $msg).$close;
Thanks
Hi
EXAMPLE:
$aStatus = array ( '' => '',
-1 => 'status -1',
0 => 'status 0',
1 => 'status 1',
2 => 'status 2'
);
Form::select('status', $iStatus=0, $aStatus, array() );
If option $iStatus=0, the option in dropdown is newer SELECTED.
May be it is checked on empty(), should be checked on != " "
Jozef
Form::input from scaffold edit form displays Central European characters ล and ลก as ล and ลก regardless of db encoding
<?php echo Form::input('keywords', Input::post('keywords', isset($site) ? $site->keywords : '')); ?>
however this is ok:
input type="text" name="keywords" value="<? echo Input::post('keywords', isset($site) ? $site->keywords : '') ?>"
as is the display from var_dump() and all other CE specific signs.
public function action_page1() { Session::set('foo', 'FOO'); echo Debug::dump(Session::get('foo')); echo Html::anchor('welcome/page2', 'Next Page'); } // output: 'FOO' public function action_page2() { echo Debug::dump(Session::get('foo')); } // output: NULL
I've run in to some issues with sessions. Maybe I'm doing something wrong, but I can't keep session variables across page requests. I thought maybe it was how I was doing something, but even the vanilla code above doesn't work for me. Am I missing something? I just pulled the latest code from the develop branch about 30 minutes ago.
If there is a 404 error when using the template controller, the Controller_Template after() method is overloading the body response.
This may be solved by adding a second condition to core/classes/controller/template.php line 53:
FROM: if ($this->auto_render === true)
to:
TO: if ($this->auto_render === true && $this->response->status != 404)
Making sure $this->response->body is not overloaded by the after() method.
/core/classes/fieldset.php on line 126:
if (isset($config['form_instance']) && $config['form_instance'] instanceof Form)
{
$this->validation = $config['form_instance'];
}
this maybe should be:
if (isset($config['form_instance']) && $config['form_instance'] instanceof Form)
{
$this->form = $config['form_instance'];
}
The problem is that when putting anything in the subject line only the first few characters are read correctly by the mails clients (GMail, Mac OS Mail, Thunderbird) and after that the subject line gets garbled like this "=d0=b7=d0=b0_=d0=bd=d0=be=d0=b2=d0=b0_". This doesn't happen with latin characters.
I've encountered the same issue with Codeigniter and it was in the _prep_q_encoding method. I know it may not be very correct to do it but I've fixed the issue by not using the method on the subject and instead just doing this:
$subject = '=?'. $this->charset .'?B?'. base64_encode($subject) .'?=';
$this->_set_header('Subject', $subject);
in a MY_Email.php extension.
I'm not sure this is the best possible way (actually I'm sure it's bad:) ), but it'll be great if this bug doesn't continue it's life in Fuel.
I'm currently working with dates but I had an issue were the dates I was getting were offseted by 5 hours or so.
I checked my php.ini file to verify that my date.timezone
value was correctly set, and it was set to America/Mexico_City which is correct, but I was getting dates from another timezone. I then looked into date_default_timezone_get()
and realized that the timezone was set to UTC (at this moment I didn't know why this was happening as I had America/Mexico_City set as the default timezone). After some time looking around for this I stumbled across the date config file inside Fuel core but there was nothing there that was messing this up... I then looked into the APPATH folder inside the config.php file and found this on line 59:
* default_timezone optional, if you want to change the server's default timezone
so I set the new key in the array after the 'server_gmt_offset = 0,
:
'default_timezone' => 'America/Mexico_City',
I refreshed the site and nothing happened. I still was getting the wrong dates. Well, after more digging I found that in the app's bootstrap.php file are this lines of code:
/**
* Set the timezone to what you need it to be.
*/
date_default_timezone_set('UTC');
I think those lines should not exist at all there. I mean, it always overrides the configuration set in php.ini regardless if I want it to or not. What would be more helpful is this:
If the default_timezone configuration is specified I think the timezone change should be called inside the Fuel::init()
function. The way it currently works is a little bit misleading and does not achieve the flexibility you are aiming at...
I'm extending the Route object and found 2 things:
I could edit both now, but as I'm tired I'm afraid I might be missing something...
A error occurred using Rest controller.
"Missing argument 2 for Fuel\Core\Response::set_header(), called in /fuel/core/classes/controller/rest.php on line 103 and defined".
Hi,
in my development process I usually have local, dev, stage, test and prod environments, which are partly mapped by the environment constants found in Fuel class.
I was wondering if it is possible to either add them or find a more flexible solution to solve this problem whatever the number and the name of the environments somebody wants to use.
I'm not sure if this is a bug or the intended behavior, but when I add a path to Fuel for inclusion in the file system (through Fuel::add_path()
), I can't use controllers in the added path location. I tossed a controller in to the added path's classes/controller
directory and went there in my browser only to be met by a Fuel exception (Fuel\Core\Fuel_Exception [ Error ]: It appears your 404 route is incorrect. Multiple Recursion has happened.).
At this point, my controller is dead simple as I'm just trying to get it to print something out:
<?php
class Controller_Welcome extends Controller {
public function before()
{
parent::before();
}
public function action_index()
{
echo 'Foo!';
}
}
Is this a bug or expected behavior? If it's the latter, I'm just curious why controllers aren't allowed in those added paths. Thanks!
After WanWizard commit ( e14bc5a - Today ) Asset class couldn't find elements
Before the commit all works fine.
If you do, you'll get
Orm\Exception [ Error ]: Primary key cannot be changed.
If I use special characters like "Fuel's company", everything is displayed well in the view, however when trying to edit this data it will show as: Fuel's company
That problem only occurs with input text fields and works fine with textarea fields.
I just find a bug in FUEL::find_file function on line 259:
https://github.com/fuel/core/blob/develop/classes/fuel.php#L259
The class caches the found path so that it has it on it's records. But now we have modules, so the directory structure can 'repeat' itself.
If I have two modules: mod1 and mod2 having this structure (I wont put all folders as they are not need to show the point):
- mod1
|- config
|- config.php
-mod2
|- config
|- config.php
and I run:
$mod1_config = \Config::load('mod1\\config', true);
$mod2_config = \Config::load('mod2\\config', true);
then both vars will have the same contents, because of caching not using the namespace. Let me clarify this (fuel.php L259):
$path = $directory.DS.strtolower($file).$ext;
var_dump($path);
will output in both cases:
string(17) "config\config.php"
if then, on line 261 we check for the cached path:
if (static::$path_cache !== null and array_key_exists($cache_id.$path, static::$path_cache)){
return static::$path_cache[$cache_id.$path];
}
the array key we are checking ($cache_id.$path) would be in both cases something like this:
string(49) "d41d8cd98f00b204e9800998ecf8427econfig\config.php"
which is wrong because they are two different paths!!! I think the namespace should be somewhere involved in assigning a key for the cached path.
There's a bug with JSON output in a REST controller. Here's some code:
class Controller_API extends Controller_Rest {
public function get_list()
{
$users = Model_User::find('all');
//print_r($users)
$this->response($users);
}
}
This will output:
{ 1: { } 2: { } }
I have two users in my test environment, so having 2 json values would be correct, but they're empty.
By uncommenting the print_r I get my 2 results so the $users variable is correct.
Also, if I change config/rest.php back to xml, it outputs everything correctly.
More details here: http://fuelphp.com/forums/topics/view/974
I had a module which routes were doing fine, until some update from the git repo. Unfortunately I haven't notice which one was it :)
The problem is find_controller method in Router always returns false on module controllers.
In my case I'm expecting this line
if (class_exists(ucfirst($match->module).'\\Controller_'.ucfirst($match->controller)))
to return true, but it seems the autoloader hasn't loaded the proper controller filename (judging by what the profile shows as included files).
In the Route class, ":segment" is replaced by "([^/]+([^/]*))", which contains a double set of parentheses, giving you $1 and $2.
See http://fuelphp.com/forums/topics/view/1005 for more details.
I'm experimenting with the Upload class and purposefully set the upload path to something nonexistent and set 'create_path' to false to see what happens when a file upload fails.
It looks like the code tries to throw an Exception in classes/upload.php line 446:
'Can't move the uploaded file. Destination path specified does not exist.'
However the error reported is actually:
ErrorException [ Error ]: Class 'Fuel\Core\Exception' not found
I'm not sure, but it looks like it's expecting to find an "Exception" class?
Quick caveat emptor: my first report of that kind, so I am not even sure this is the right place......
unless I am completely wrong, there is an error in the Router::find_controller method
My setup:
modules
---test
------controller
---------test.php
test.php:
<?php
namespace Test;
class Controller_Test extends \Controller {
public function action_index()
{
$this->response->body = 'abc';
}
public function action_login()
{
$this->response->body = 'def';
}
}
/* End of file test.php */
** what fixed it **
/core/classes/router.php (around line 135):
was:
$match->controller = count($segments) ? array_shift($segments) : $match->module;
``
fix:
```php
$match->controller = count($segments)>1 ? array_shift($segments) : $match->module;
In relation to the fuel/core issue #84 already fixed in the develop branch, the save method of the \Config class has the same problem:
In the documentation it says: "The save method saves a config file into the system. It searches through the config directories for the requested file. If no existing file is found, the config file is created in the APPPATH config directory." and the function works as described, but having modules should change this a little bit.
Let's say I have a global config file named 'ldap.php' which has the configuration details for an LDAP connection. I then add a module 'mod1' and (humor me) I create at runtime a special configuration for an LDAP connection to be used only in that module which differs from the previous one described in the global config folder.
Currently, in 'mod1' there's no 'ldap.php' file in the module's config folder, as I want to create it at runtime.
So Let's see some code of what I'm doing here:
\Config::set('mod1cfg.ldap.server', 'testserver.fuelphp.com');
\Config::set('mod1cfg.ldap.user', 'myldapuser');
\Config::set('mod1cfg.ldap.pwd', 'myldappwd');
If were to save this configuration for future use I would do so like this:
\Config::save('mod1\\ldap', 'mod1cfg');
What will happen is that the save process will see if there's an 'ldap.php' file inside the module's mod1 config folder but there won't be so it sets the save path automatically to the 'APPPATH config directory' which will effectively overwrite the configuration I don't want to overwrite.
I think the way it should work is:
Going from RC1 to RC2 I noticed my Rest controllers stopped working, further investigation lead me to the following typo/bug:
Line 103 in core/classes/controller/rest.php is incorrect:
$this->response->set_header('Content-Type: '.$this->_supported_formats[$this->request->format]);
it should be something like this (from RC1):
$this->response->set_header('Content-Type', $this->_supported_formats[$this->request->format]);
-js
The migrate class should probably utilise a config - for the table name used (sometimes I want to put the session and migrate classes under fuel_sessions and fuel_migrations just to keep them together).
Do you think this is a good idea?
Line 103 of fuel/core/classes/controller/rest.php
The set_header method requires two parameters so the "." should be a ","
Instead of adding the given class to the validation callables like this :
public function add_model($class, $instance = null, $method = 'set_form_fields')
{
if ((is_string($class) && is_callable($callback = array('\\'.$class, $method)))
|| is_callable($callback = array($class, $method)))
{
$instance ? call_user_func($callback, $this, $instance) : call_user_func($callback, $this);
}
// Add model to validation callables for validation rules
$this->validation()->add_callable($class);
return $this;
}
the Fieldset class should add the model first to allow the 'set_form_fields' method to add validation rules from the same class.
Like this :
public function add_model($class, $instance = null, $method = 'set_form_fields')
{
// Add model to validation callables for validation rules
$this->validation()->add_callable($class);
if ((is_string($class) && is_callable($callback = array('\\'.$class, $method)))
|| is_callable($callback = array($class, $method)))
{
$instance ? call_user_func($callback, $this, $instance) : call_user_func($callback, $this);
}
return $this;
}
I have a model set up with the ORM with multiple many to many relations. However, when I try to delete a record using $model->delete() I'm getting the following error:
ErrorException [ Error ]: Call to undefined method Fuel\Core\Database_Query_Builder_Delete::delete()
PKGPATH/orm/classes/manymany.php @ line 297
Seems this is being called: $query->delete(); Which is a Database_Query_Builder_Delete object.
This class has some commented out code, doesn't have docblocks for methods and credits the Kohana team while I thought Phil wrote this from scratch?
I think it's one of the most overused feature when working with strings, the ability to return a plural / singular string automatically.
A simple code suggestion with comments: gist code
Sadly, i have no good method name to propose.
I noticed that the MySQL and MySQLI drivers query() method return affected_rows() after execution, which means
The PDO driver only returns rowCount(), so no indication if the query executed correctly or not.
Then, the ORM Model update() method uses this return value, and determines that the update was correct if the rowcount returned is greater than zero. Which in turn means that if no rows were affected, Model::save() returns false.
I don't think this is correct.
With new installation, after adding some code lines that retrieve info from the Db it gives this error:
ErrorException [ Error ]: Undefined class constant 'STAGE'[/code]
APPPATH/config/db.php @ line 61
My (new) application only consists on a simple Model function with this code:
return DB::select()->from('books')->as_object()->execute();
And this Controller:
$data = array();
$data['result'] = Model_Books::all_books();
$this->response->body = View::factory('books/index', $data);
After adding codeline "const STAGE = 'stage';" to fuel/core/classes/fuel.php it works perfectly.
Is it correct?
Currently the set_template() method simply returns the _template property. This should instead be called get_template().
I ran into this when I created a set_template() method as a setter for the _template property, which of course caused issues.
I can make the necessary changes, just give me the go ahead.
See screenshot at http://d.pr/wBef
i described this problem on fuel forum : http://fuelphp.com/forums/topics/view/1727
The log class should take into account the 'server_gmt_offset' config.
Current setting the server_gmt_offset or the default_timezone in config.php has not effect on the Timestamps ('log_date_format') written out to the log files.
I understand this is to help with misconfigured servers, but if its an option then it should work =)
Edit: The core/classes/log.php currently gets the date using php's date() using the format described as 'log_date_format' in config.php. So if you're php time is off, you need to edit php.ini and set the 'date.timezone' setting. For me it was
date.timezone = US/Pacific
Currently, it appears that the WHERE clause must contain 3 parameters. It would be nice to allow the user to enter their own complex where clause such as:
$query->where("((t.timestamp =
(SELECT MAX(timestamp) FROM client_history WHERE client_id = t.client_id))
OR
(t.timestamp IS NULL)
)"
I suggest that if parameters 2 and 3 to the function and_where() in where.php are null, then the function _comple_conditions() in builder.php ignores parameters 2 and 3 ($op and $value in _comple_conditions() and also does not apply any quotes or escaping.
It would be useful if Form::checkbox()
allowed for a toggle checkbox to be created, by omitting the value
attribute if the parameter passed is null
.
/*
Array (
[enable_foo] =>
[enable_bar] => on
);
*/
<?php echo Form::open(); ?>
<?php print_r($_POST); ?>
<?php echo Form::checkbox('enable_foo', null, array('checked' => 'checked')); ?>
<input type="checkbox" name="enable_bar" checked="checked" />
<?php echo Form::submit('Submit'); ?>
<?php echo Form::close(); ?>
Please check count_records() inside /classes/database/connection.php, table is quoted using this:
$table = $this->quote_identifier($table);
should be:
$table = $this->quote_table($table);
class Fuel {
/**
fuel/app/config/db.php
Jozef
It seems that if you pass an object to a view using output encoding it any related objects are converted to arrays. This causes a problem in a situation like:
$this->template->mustache_templates['m_checkout_payments'] = View::factory('mustache/checkout/payments')
->set('job', $job);
$this->template->mustache_templates['m_checkout_charges'] = View::factory('mustache/checkout/charges')
->set('job', $job);
You can see the dump between the 2 job variables in the scrp below.
The $job variables should not be different between the 2 times they are used. If I set output-encoding to false it works fine.
Background on my installation: As I did this in a haste, I installed memcached through apt-get / Didn't compile by source. Then I just ran "memcached -d -m 512 -p 11211"
I wrote this example code:
//....some code before, getting the $view object, etc...
if ( isset($_GET['set']) )
\Cache::set('memcached_test', 'testing!', 3600 * 3);
try {
$view->cache_test_data = \Cache::get('memcached_test');
$view->cache_test = true;
} catch (\Cache_Exception $e) {
$view->cache_test = false;
$view->cache_test_data = '(null)';
}
//the rest of the code, aka outputting.
Now, first I accessed the default controller with /?set. It worked, and I got the data I set. However, when I don't set it before I get the data, it marks the test as failed. I have also tried without Fuel, and it worked perfectly.
In the process of using the Validation class, I ran in to problems with validation errors. Fuel contains a method to pull back all the fields that were validated in a key => value
array, but the same can't be said of errors. Instead, it returns a massive array that contains everything under the sun. While that may be useful in some cases, in most, developers would just want to know the field that failed and the message(s) associated with that field.
I do realize the error()
method exists, but I really shouldn't have to manually go through every field in the form and check it that way just to get a key => value
array of the field and the validation messages. Any chance this could be patched up or am I the only one that's having this issue?
Thanks!
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.